#290 feat: OpenAPI schema overrides carried to generated structs - #291
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #290
A JSONB column typed as
serde_json::Valuedocuments as a free-form object, and there was no way to say otherwise:#[schema(...)]is not a helper attribute of the derive, so writing it on an entity did not compile — and the generated DTOs would not have carried it anyway. The workaround was a hand-written duplicate of the generated struct existing only to hold the attribute.The attribute is now accepted on a field and forwarded verbatim to every generated struct that derives
utoipa::ToSchema: the create and response DTOs and the joined view. Whatever utoipa accepts works here, because nothing is parsed twice.Two deliberate exclusions. With the
apifeature off nothing generated derivesToSchema, so the attribute is dropped rather than emitted onto a struct that cannot interpret it. Update DTOs never carry it: the macro rewrites their field types for PATCH semantics, so a declaredvalue_typewould contradict the type actually generated.Covered by unit tests on the parser, a compile-pass case asserting all three generated structs implement
ToSchemawith an override in place, and documented in the README reference and the attribute page in all five wiki languages.