8000 various improvements to JSON schema processing by ahl · Pull Request #1356 · oxidecomputer/dropshot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

various improvements to JSON schema processing #1356

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

Merged
merged 5 commits into from
Jun 21, 2025
Merged

various improvements to JSON schema processing #1356

merged 5 commits into from
Jun 21, 2025

Conversation

ahl
Copy link
Collaborator
@ahl ahl commented Jun 21, 2025

@sunshowers noticed that we aren't including schemas in OpenAPI output that are only referenced by our custom x-rust-type extension. We can address this by massively simplifying how we process schemas. This is some very very old code in dropshot, and I'm not quite sure why it felt like the right approach, but we had been generating them schema, and then scraping out references using a visitor.... but the references were already present in the structures used to generate the schema. It's a bit perplexing why we took this extra step--perhaps there's some other shoe that will drop, but we've certainly developed many more tests since then, and none of them point to any reason why this excursion might have been necessary.

We also noticed that schemars allows for modeling a empty enum value e.g. { "enum": [] } and openapiv3 does not; schemars will also emit such a schema when the JsonSchema derive macro is applied to a never-type enum (e.g. enum Foo {}). To handle this while preserving extensions we emit the following schema which is representable by openapiv3 structures: { "not": {} }.

And for funsies, we also handle the false schema using the same construction.

@ahl ahl requested a review from sunshowers June 21, 2025 01:49
Copy link
Contributor
@sunshowers sunshowers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Comment on lines 337 to +339
openapiv3::ReferenceOr::Item(openapiv3::Schema {
schema_data: openapiv3::SchemaData::default(),
schema_kind: openapiv3::SchemaKind::Any(
openapiv3::AnySchema::default(),
),
schema_data: Default::default(),
schema_kind: openapiv3::SchemaKind::Any(Default::default()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nit: worth extracting the maximally permissive schema into a function? we use it three times

@ahl ahl merged commit f9b9be8 into main Jun 21, 2025
12 checks passed
@ahl ahl deleted the x-rust-type-sad branch June 21, 2025 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0