Skip to content

Obey annotations when flattening ParameterObject fields. Fixes #2817 #2832

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

Conversation

mc1arke
Copy link
Contributor

@mc1arke mc1arke commented Dec 31, 2024

When creating the flattened parameter definitions for an item annotated with @ParameterObject, the @Schema and @Property annotations on any fields prior to the final child-node of each branch of the parameter tree are not taken into consideration. This results in the field name in the code being used even where annotations may override that, prevents the fields being hidden where one of the parent fields is marked as hidden but the child field isn't hidden, and marks a field as mandatory even where the field would only be mandatory if the parent object had been declared through a sibling of the target field being set. To overcome this, whilst the flattened parameter map is being built, each field is now being inspected for a @parameter annotation or - where the @parameter annotation isn't found - a @Schema annotation. Where a custom name is included in either of those annotations then the overridden field name is used in the flattened definition. If either annotation declares the field as hidden then the field and all child fields are removed from the resulting definition, and a field is no longer set as mandatory unless the parent field was also declared as mandatory, or resolved as non-null and was set in an automatic state, or the child field is specifically set as required in the Schema or Parameter annotation.

…doc#2817

When creating the flattened parameter definitions for an item annotated
with @ParameterObject, the @Schema and @Property annotations on any
fields prior to the final child-node of each branch of the parameter
tree are not taken into consideration. This results in the field name in
the code being used even where annotations may override that, prevents
the fields being hidden where one of the parent fields is marked as
hidden but the child field isn't hidden, and marks a field as mandatory
even where the field would only be mandatory if the parent object had
been declared through a sibling of the target field being set. To
overcome this, whilst the flattened parameter map is being built, each
field is now being inspected for a @parameter annotation or - where the
@parameter annotation isn't found - a @Schema annotation. Where a custom
name is included in either of those annotations then the overridden
field name is used in the flattened definition. If either annotation
declares the field as hidden then the field and all child fields are
removed from the resulting definition, and a field is no longer set as
mandatory unless the parent field was also declared as mandatory, or
resolved as non-null and was set in an automatic state, or the child
field is specifically set as required in the Schema or Parameter
annotation.
@mc1arke mc1arke force-pushed the nested-parameterobject-handling branch from 4df7c63 to 34a468a Compare January 1, 2025 21:06
@bnasslahsen bnasslahsen merged commit 34a468a into springdoc:main Jan 2, 2025
@bnasslahsen
Copy link
Collaborator

@mc1arke,

I have done the merge, with few simplifications, to make the code much readable.
All tests are passing. Do not hesitate to review it or add other test cases.

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