-
Notifications
You must be signed in to change notification settings - Fork 278
fix: preserve JSON Schema 2020-12 keyword siblings on $ref schemas for OAS 3.1+ #2896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7bcdecb
ef3a1a6
32fb216
4c228f7
4666f2c
fcf4dbf
af0686a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,17 @@ | ||
| #nullable enable | ||
| Microsoft.OpenApi.JsonSchemaReference.Anchor.get -> string? | ||
| Microsoft.OpenApi.JsonSchemaReference.Anchor.set -> void | ||
| Microsoft.OpenApi.JsonSchemaReference.Comment.get -> string? | ||
| Microsoft.OpenApi.JsonSchemaReference.Comment.set -> void | ||
| Microsoft.OpenApi.JsonSchemaReference.Definitions.get -> System.Collections.Generic.IDictionary<string!, Microsoft.OpenApi.IOpenApiSchema!>? | ||
| Microsoft.OpenApi.JsonSchemaReference.Definitions.set -> void | ||
| Microsoft.OpenApi.JsonSchemaReference.DynamicAnchor.get -> string? | ||
| Microsoft.OpenApi.JsonSchemaReference.DynamicAnchor.set -> void | ||
| Microsoft.OpenApi.JsonSchemaReference.DynamicRef.get -> string? | ||
| Microsoft.OpenApi.JsonSchemaReference.DynamicRef.set -> void | ||
| Microsoft.OpenApi.JsonSchemaReference.Schema.get -> System.Uri? | ||
| Microsoft.OpenApi.JsonSchemaReference.Schema.set -> void | ||
| Microsoft.OpenApi.JsonSchemaReference.SchemaId.get -> string? | ||
| Microsoft.OpenApi.JsonSchemaReference.SchemaId.set -> void | ||
| Microsoft.OpenApi.JsonSchemaReference.Vocabulary.get -> System.Collections.Generic.IDictionary<string!, bool>? | ||
|
Comment on lines
+2
to
+16
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In JSON schema 2020-12 only annotation keywords are allowed next to $ref. Let me know if you have any additional comments or questions.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, after digging some more, it seems that:
I couldn't find any additional evidence for $anchor, $dynamicAnchor or $vocabulary
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually I went ahead and had additional discussions with both @handrews and @darrelmiller (thank you both). My understanding was wrong. In the case where both are present, we have a precedent of returning the reference value for annotation keywords, so being consistent here makes sense. Then the application can check the reference and the target values, and compare them, if the difference is important to the application. Any keyword in JSON schema exposed as a property in the IOpenAPISchema interface as well as in the IOpenApiSchemaMissingProperties should have:
Now, I understand this is significant work, if you want to focus on the properties you've identified first, and punt the other properties to an additional issue, let me know. |
||
| Microsoft.OpenApi.JsonSchemaReference.Vocabulary.set -> void | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -452,6 +452,31 @@ public static IOpenApiSchema LoadSchema(JsonNode node, OpenApiDocument hostDocum | |
| var result = new OpenApiSchemaReference(reference.Item1, hostDocument, reference.Item2); | ||
| result.Reference.SetMetadataFromJsonObject(jsonObject); | ||
| result.Reference.SetJsonPointerPath(pointer, nodeLocation); | ||
|
|
||
| // Parse $defs sibling — requires LoadSchema for nested schema materialization, | ||
| // so it cannot be done inside SetAdditional31MetadataFromMapNode. | ||
| if (jsonObject.TryGetPropertyValue(OpenApiConstants.Defs, out var defsNode) && defsNode is JsonObject defsObj) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could refactor that to accept a callback. Assuming the SetMetadata method is internal |
||
| { | ||
| var defs = new Dictionary<string, IOpenApiSchema>(StringComparer.Ordinal); | ||
| foreach (var kvp in defsObj) | ||
| { | ||
| if (kvp.Value is null) continue; | ||
| context.StartObject(kvp.Key); | ||
| try | ||
| { | ||
| defs[kvp.Key] = LoadSchema(kvp.Value, hostDocument, context); | ||
| } | ||
| finally | ||
| { | ||
| context.EndObject(); | ||
| } | ||
| } | ||
| if (defs.Count > 0) | ||
| { | ||
| result.Reference.Definitions = defs; | ||
| } | ||
| } | ||
|
Comment on lines
+456
to
+478
|
||
|
|
||
| return result; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need to use the version instead of the callback?
this is brittle and we might forget to update things here in future versions