Skip to content

fix(schema): preserve example metadata for non-body params with named types#3782

Open
maruthang wants to merge 1 commit intonestjs:masterfrom
maruthang:fix/example-override-non-body-params-3335
Open

fix(schema): preserve example metadata for non-body params with named types#3782
maruthang wants to merge 1 commit intonestjs:masterfrom
maruthang:fix/example-override-non-body-params-3335

Conversation

@maruthang
Copy link
Copy Markdown

PR Checklist

PR Type

  • Bugfix

What is the current behavior?

When a ParentDto has a property of type ChildDto, and both have @ApiProperty({ example: ... }), the parent's example is lost for non-body parameters (@query, @param, @headers). The child DTO's examples leak through instead.

This happens because getCustomType() places schema-level options (like example) at the top level of the parameter object, while SwaggerTypesMapper.mapParamTypes() later strips all schema-option keys from the top level.

Issue Number: #3335

What is the new behavior?

Schema-level options (example, default, format, etc.) are now moved into the schema object after getCustomType() returns. When there are extra metadata properties alongside a $ref, it uses the allOf: [{ $ref }] pattern, ensuring metadata is properly preserved for all parameter types.

Does this PR introduce a breaking change?

  • No

… types

When a non-body parameter (query/param/header) has a named type and
schema-level options like example, those options were lost because
getCustomType placed them at the top level while SwaggerTypesMapper
stripped them. Move schema options into the schema object using allOf
pattern when a $ref is present.

Closes nestjs#3335
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