Skip to content

Recursively discover flattened fields in maps - #1582

Open
nipunn1313 wants to merge 2 commits into
juhaku:masterfrom
nipunn1313:nipunn/fix-utoipa-issue-1330
Open

Recursively discover flattened fields in maps#1582
nipunn1313 wants to merge 2 commits into
juhaku:masterfrom
nipunn1313:nipunn/fix-utoipa-issue-1330

Conversation

@nipunn1313

Copy link
Copy Markdown

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

This allows the discovered fields to appear in component.schemas without
having to explicitly list it as a workaround.

Fixes juhaku#1330
Comment thread utoipa-gen/src/component.rs Outdated
#[cfg_attr(feature = "debug", derive(Debug))]
pub struct FlattenedMapSchema {
tokens: TokenStream,
pub schema_references: Vec<SchemaReference>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not:

Suggested change
pub schema_references: Vec<SchemaReference>,
schema_references: Vec<SchemaReference>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

likey because utoipa-gen/src/component/schema.rs, or?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

was mistake. I assumed it was necessary because of schema.rs - but it's not because it's a submodule. Made it private.

Comment thread utoipa-gen/tests/schema_derive_test.rs Outdated
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"
}
}
"###);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the "established" way of doing this testing is to use assert_value and non-inline snapshots.

Could you change it to that?

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.

#[serde(flatten)] Fields in HashMap Not Recursively Discovered

2 participants