Skip to content

Commit

Permalink
Duplicate description on schemas used in parameters (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
samchungy authored Jan 7, 2024
1 parent 5dec3ed commit 95354aa
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/create/parameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,43 @@ describe('createParametersObject', () => {

expect(result).toStrictEqual(expectedResult);
});

it('should extract the description from the underlying schema', () => {
const expectedResult: oas31.BaseParameterObject = {
schema: {
type: 'string',
description: 'foo',
},
description: 'foo',
required: true,
};
const result = createBaseParameter(
z.string().describe('foo'),
getDefaultComponents(),
['query'],
);

expect(result).toStrictEqual(expectedResult);
});

it('should allow overriding the description using .openapi.param in the underlying schema', () => {
const expectedResult: oas31.BaseParameterObject = {
schema: {
type: 'string',
description: 'foo',
},
description: 'boo',
required: true,
};
const result = createBaseParameter(
z
.string()
.describe('foo')
.openapi({ param: { description: 'boo' } }),
getDefaultComponents(),
['query'],
);

expect(result).toStrictEqual(expectedResult);
});
});
4 changes: 4 additions & 0 deletions src/create/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export const createBaseParameter = (
'schema',
]);
const required = !isOptionalSchema(schema, state);
const description =
schema._def.openapi?.description ?? schema._def.description;

return {
...(description && { description }),
...rest,
...(schema && { schema: schemaObject }),
...(required && { required }),
Expand Down

0 comments on commit 95354aa

Please sign in to comment.