diff --git a/src/create/parameters.test.ts b/src/create/parameters.test.ts index 970375f..ae9e5a1 100644 --- a/src/create/parameters.test.ts +++ b/src/create/parameters.test.ts @@ -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); + }); }); diff --git a/src/create/parameters.ts b/src/create/parameters.ts index 18f674c..022506a 100644 --- a/src/create/parameters.ts +++ b/src/create/parameters.ts @@ -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 }),