Recursively discover flattened fields in maps - #1582
Open
nipunn1313 wants to merge 2 commits into
Open
Conversation
This allows the discovered fields to appear in component.schemas without having to explicitly list it as a workaround. Fixes juhaku#1330
| #[cfg_attr(feature = "debug", derive(Debug))] | ||
| pub struct FlattenedMapSchema { | ||
| tokens: TokenStream, | ||
| pub schema_references: Vec<SchemaReference>, |
Contributor
There was a problem hiding this comment.
why not:
Suggested change
| pub schema_references: Vec<SchemaReference>, | |
| schema_references: Vec<SchemaReference>, |
Contributor
There was a problem hiding this comment.
likey because utoipa-gen/src/component/schema.rs, or?
Author
There was a problem hiding this comment.
was mistake. I assumed it was necessary because of schema.rs - but it's not because it's a submodule. Made it private.
Comment on lines
+132
to
+159
| // `Bar` referenced through the flattened `HashMap` must be discovered recursively. | ||
| assert!( | ||
| schemas.contains_key("Bar"), | ||
| "expected `Bar` to be collected recursively, got: {:?}", | ||
| schemas.keys().collect::<Vec<_>>() | ||
| ); | ||
| assert_json_snapshot!(schemas, @r###" | ||
| { | ||
| "Bar": { | ||
| "properties": { | ||
| "value": { | ||
| "format": "int64", | ||
| "type": "integer" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "value" | ||
| ], | ||
| "type": "object" | ||
| }, | ||
| "Foo": { | ||
| "additionalProperties": { | ||
| "$ref": "#/components/schemas/Bar" | ||
| }, | ||
| "type": "object" | ||
| } | ||
| } | ||
| "###); |
Contributor
There was a problem hiding this comment.
I think the "established" way of doing this testing is to use assert_value and non-inline snapshots.
Could you change it to that?
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.
This allows the discovered fields to appear in component.schemas without having to explicitly list it as a workaround.
Ran into this issue in our codebase, and confirmed that patching in this fixes.
Fixes #1330