Skip to content
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

Obey annotations when flattening ParameterObject fields. Fixes #2787 #2788

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mc1arke
Copy link
Contributor

@mc1arke mc1arke commented Nov 24, 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.

…doc#2787

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. To
ensure that the post-processing steps don't re-apply `required`
properties on parameters that have purposefully had them removed, the
delegate now tracks any annotations what should not be shown as being on
the parameter, and excludes them from the annotation list during
subsequent calls.
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.

1 participant