-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Map all true schemas to empty object schemas in OpenAPI #57067
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
Conversation
mikekistler
left a comment
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.
Looks good! 👍
| // expected in OpenAPI documents. | ||
| if (type == typeof(object)) | ||
| // anything (like the `object` type) or types with user-defined converters. We override | ||
| // this default behavior here to match the style traditionally expected in OpenAPI documents. |
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.
What does "traditionally" mean here? Is there a newer style of OpenAPI documents?
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.
Yes, OpenAPI v3.1 is an upcoming version that has full parity with JSON schema and would permit true schemas being used as catch-all schemas. I'll update this comment to be more explicit.
| if (type == typeof(object)) | ||
| // anything (like the `object` type) or types with user-defined converters. We override | ||
| // this default behavior here to match the style traditionally expected in OpenAPI documents. | ||
| if (schema.GetValueKind() == JsonValueKind.True) |
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.
Idle thought: what happens for dynamic?
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.
Good question! Looks like it gets handled similarily to object foo. I added test coverage for this in fa39cfc.
Closes #57041.
This PR is an extension of the changes that was introduced in 4c8b5fe to replace the use of
trueschemas with empty object schemas in the OpenAPI implementation.JsonSchemaExporteruses thetrueschemas as catch-all schema for types. OpenAPI schema diverges from JSON schema and expects that empty schemas{ }be used to represent catch-all values. The previous logic special cased fixing up these mappings forobjecttypes. This PR updates the implementation to do the mapping if the underlying schema is atrueschema, regardless of the type. This makes the implementation resilient to other cases where atrueschema is returned by STJ, like when a user defined converter is associated with a type.With these changes, we'd expect the following diff in the generated schema.
{ "type": "object", "properties": { "name": { "type": "string" }, - "childType": true, + "childType": { }, } }