various improvements to JSON schema processing #1356
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@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 emptyenum
value e.g.{ "enum": [] }
andopenapiv3
does not;schemars
will also emit such a schema when theJsonSchema
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 byopenapiv3
structures:{ "not": {} }
.And for funsies, we also handle the
false
schema using the same construction.