MarkdownBody: Register swagger metadata

As explained in https://github.com/nestjs/swagger/issues/32#issuecomment-716169471, it's possible to register swagger metadata in custom decorators by providing an array of `enhancers`.
We now add metadata with the `MarkdownBody` decorator: The request needs a `body` with content-type `text/markdown`.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-01-10 19:21:00 +01:00
parent 8d3406175b
commit 644d7a278a
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3

View file

@ -10,6 +10,7 @@ import {
ExecutionContext, ExecutionContext,
InternalServerErrorException, InternalServerErrorException,
} from '@nestjs/common'; } from '@nestjs/common';
import { ApiBody, ApiConsumes } from '@nestjs/swagger';
import * as getRawBody from 'raw-body'; import * as getRawBody from 'raw-body';
/** /**
@ -37,4 +38,17 @@ export const MarkdownBody = createParamDecorator(
); );
} }
}, },
[
(target, key) => {
ApiConsumes('text/markdown')(
target,
key,
Object.getOwnPropertyDescriptor(target, key),
);
ApiBody({
required: true,
schema: { example: '# Markdown Body' },
})(target, key, Object.getOwnPropertyDescriptor(target, key));
},
],
); );