diff --git a/src/util/commentsToOpenApi.test.ts b/src/util/commentsToOpenApi.test.ts index 1841392..859851e 100644 --- a/src/util/commentsToOpenApi.test.ts +++ b/src/util/commentsToOpenApi.test.ts @@ -65,6 +65,7 @@ describe('commentsToOpenApi', () => { * * @bodyDescription an optional description * @bodyContent {string} application/json + * @bodyExample {ExampleExample} application/json.ExampleExample * @bodyRequired * * @response 200 - sup @@ -164,6 +165,11 @@ describe('commentsToOpenApi', () => { required: true, content: { 'application/json': { + "examples": { + "ExampleExample": { + "$ref": "#/components/examples/ExampleExample" + } + }, schema: { type: 'string', }, diff --git a/src/util/commentsToOpenApi.ts b/src/util/commentsToOpenApi.ts index de462a4..5a19d5f 100644 --- a/src/util/commentsToOpenApi.ts +++ b/src/util/commentsToOpenApi.ts @@ -189,6 +189,23 @@ function tagsToObjects(tags: any[], verbose?: boolean) { }, }; + case 'bodyExample': { + const [contentType, example] = parsedResponse.name.split('.'); + return { + requestBody: { + content: { + [contentType]: { + examples: { + [example]: { + $ref: `#/components/examples/${parsedResponse.rawType}`, + }, + }, + }, + }, + }, + }; + } + case 'bodyDescription': return { requestBody: { description: nameAndDescription } };