sourcemeta/alterschema

definitions not updated to $defs

Opened this issue · 4 comments

Using https://alterschema.sourcemeta.com/ to translate the open api v3 spec from Draft-04 to 2019-09 re: OAI/OpenAPI-Specification#2996

Mostly worked except the definitions references weren't updated to defs. The schema appears valid after making this replacement (according to https://www.jsonschemavalidator.net )

-              "$ref": "#/definitions/Schema"
+              "$ref": "#/$defs/Schema"

I wonder if this is more of an issue around the schemas being embedded in an OpenAPI doc rather than being independent schemas. I'm not sure if the tool takes that into account.

This is a good point, and it is not related to being OpenAPI. Alterschema is doing a bunch of JSON-replacements to the given schema, but it is not amending JSON pointers touching those paths at all.

I'll send a PR to fix this for $defs in a bit, but I think this is a larger can of worms that we need to think about: if any keyword is modified as part of any Alterschema rule, then ANY JSON pointer going through that path has to be changed as well...

@chris-smith-zocdoc @gregsdennis The fix for the $defs case has been merged. I released v1.0.4 to NPM and the website is reflecting the changes.

However, let's keep this issue open until we figure out a more general way to deal with transformations within pointers.

I'm thinking about something along these lines: Alterschema has the concept of iterating through every subschema of any JSON Schema definition across specification versions.

Though that mechanism, Alterschema can accurately collect JSON Pointers to every subschema of a given schema. In turn, that information would allow us to break up a JSON Pointer, accurately know which fragments correspond to sub schemas, and try to re-apply some variant of the transformation rules we have WITHIN the pointers themselves.

I'll aim to book some time to hack on this tonight!