Fork me on GitHub

Are there any libraries to use with spec for preparing data to be run against a spec? For example, we want to evolve a spec with a required field to keep contracts strong, but knowing this won’t be compatible with old pre-existing stored data in the system. We’re considering declaring (via some library) a default for when that new key is missing, preparing the data w/ those defaults, so it will validate against the spec. I know this is possible via something like spec-tools coercers, but since coupling coercing w/ specs seems like it’s a known anti-pattern I assume using it for defaults in this way would be as well. This is kind of a round-about question about having strong specs for some places (think consumers vs producers), which I feel like is more of a solved thing in spec2 (use the select api to make certain things required in specific places), but without writing custom predicates I see no clear way to this (deeply) with the current version of spec.

Colin P. Hill17:03:08

I think the "right" solution per spec's design philosophy (at least at the time the first version was written – maybe the thinking has moved since then) is that, if the new version of your spec will reject values that were valid under the old version of your spec, then you should simply create a new spec and leave the old one behind for compatibility, possibly with the new key added as an optional value.


@U029J729MUP thanks, having a compatibility spec makes sense as we update the stricter versions.