Skip to content

Commit ff88d93

Browse files
authored
fix: clean up parent-metadata and parent-additional-properties from query params (#372)
1 parent 7309a4d commit ff88d93

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

packages/nestjs-zod/src/__e2e_tests__/openapi.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,42 @@ describe('basic query params', () => {
148148
});
149149
});
150150

151+
describe('issue#397', () => {
152+
test('cleans up description marker', async () => {
153+
class QueryParamsDto extends createZodDto(
154+
z
155+
.object({
156+
filter: z.string(),
157+
})
158+
.describe('My query params'),
159+
) {}
160+
161+
@Controller()
162+
class BookController {
163+
constructor() {}
164+
165+
@Get()
166+
getBooks(@Query() _query: QueryParamsDto) {
167+
return [];
168+
}
169+
}
170+
171+
const doc = await getSwaggerDoc(BookController, { cleanUp: true });
172+
173+
expect(get(doc, 'paths./.get.parameters')).toEqual([
174+
{
175+
in: 'query',
176+
name: 'filter',
177+
required: true,
178+
schema: {
179+
type: 'string',
180+
},
181+
},
182+
]);
183+
expect(JSON.stringify(doc)).not.toContain(PREFIX);
184+
});
185+
});
186+
151187
describe('unions', () => {
152188
test('v4', async () => {
153189
class BookDto extends createZodDto(

packages/nestjs-zod/src/cleanupOpenApiDoc.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,14 @@ function fixParameter(
541541
delete parameter[PARENT_ID_KEY];
542542
}
543543

544+
if (PARENT_METADATA_KEY in parameter) {
545+
delete parameter[PARENT_METADATA_KEY];
546+
}
547+
548+
if (PARENT_ADDITIONAL_PROPERTIES_KEY in parameter) {
549+
delete parameter[PARENT_ADDITIONAL_PROPERTIES_KEY];
550+
}
551+
544552
if (PARENT_HAS_REFS_KEY in parameter) {
545553
delete parameter[PARENT_HAS_REFS_KEY];
546554

0 commit comments

Comments
 (0)