Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): allow the apibody decorator to add examples and add $ref f… #1268

Merged
merged 1 commit into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/decorators/api-body.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Type } from '@nestjs/common';
import { omit } from 'lodash';
import {
ExamplesObject,
ReferenceObject,
RequestBodyObject,
SchemaObject
} from '../interfaces/open-api-spec.interface';
Expand All @@ -22,7 +24,8 @@ interface ApiBodyMetadata extends RequestBodyOptions {
}

interface ApiBodySchemaHost extends RequestBodyOptions {
schema: SchemaObject;
schema: SchemaObject | ReferenceObject;
examples?: ExamplesObject;
}

export type ApiBodyOptions = ApiBodyMetadata | ApiBodySchemaHost;
Expand Down
7 changes: 5 additions & 2 deletions lib/swagger-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,13 @@ export class SwaggerExplorer {
let consumes = mergeAndUniq(classConsumes, methodConsumes);
consumes = isEmpty(consumes) ? ['application/json'] : consumes;

const keysToRemove = ['schema', 'in', 'name'];
const keysToRemove = ['schema', 'in', 'name', 'examples'];
document.root.requestBody = {
...omit(requestBody, keysToRemove),
...this.mimetypeContentWrapper.wrap(consumes, pick(requestBody, 'schema'))
...this.mimetypeContentWrapper.wrap(
consumes,
pick(requestBody, ['schema', 'examples'])
)
};
return document;
}
Expand Down