alterschema icon indicating copy to clipboard operation
alterschema copied to clipboard

definitions not updated to $defs

Open chris-smith-zocdoc opened this issue 3 years ago • 4 comments

Using https://alterschema.sourcemeta.com/ to translate the open api v3 spec from Draft-04 to 2019-09 re: https://github.com/OAI/OpenAPI-Specification/issues/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"

chris-smith-zocdoc avatar Aug 09 '22 19:08 chris-smith-zocdoc

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.

gregsdennis avatar Aug 10 '22 08:08 gregsdennis

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...

jviotti avatar Aug 10 '22 12:08 jviotti

@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.

jviotti avatar Aug 10 '22 12:08 jviotti

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!

jviotti avatar Aug 10 '22 12:08 jviotti