Skip to content

Commit

Permalink
fix(openapi-v3): check debug.enabled to avoid parameter calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Oct 25, 2018
1 parent dee0c4c commit 928658b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/openapi-v3/src/decorators/request-body.decorator.ts
Expand Up @@ -81,7 +81,8 @@ export function requestBody(requestBodySpec?: Partial<RequestBodyObject>) {
return function(target: Object, member: string, index: number) {
debug('@requestBody() on %s.%s', target.constructor.name, member);
debug(' parameter index: %s', index);
debug(' options: %s', inspect(requestBodySpec, {depth: null}));
if (debug.enabled)
debug(' options: %s', inspect(requestBodySpec, {depth: null}));

// Use 'application/json' as default content if `requestBody` is undefined
requestBodySpec = requestBodySpec || {content: {}};
Expand All @@ -95,7 +96,8 @@ export function requestBody(requestBodySpec?: Partial<RequestBodyObject>) {

const paramType = paramTypes[index];
const schema = resolveSchema(paramType);
debug(' inferred schema: %s', inspect(schema, {depth: null}));
if (debug.enabled)
debug(' inferred schema: %s', inspect(schema, {depth: null}));
requestBodySpec.content = _.mapValues(requestBodySpec.content, c => {
if (!c.schema) {
c.schema = schema;
Expand All @@ -109,7 +111,8 @@ export function requestBody(requestBodySpec?: Partial<RequestBodyObject>) {
requestBodySpec[REQUEST_BODY_INDEX] = index;
}

debug(' final spec: ', inspect(requestBodySpec, {depth: null}));
if (debug.enabled)
debug(' final spec: ', inspect(requestBodySpec, {depth: null}));
ParameterDecoratorFactory.createDecorator<RequestBodyObject>(
OAI3Keys.REQUEST_BODY_KEY,
requestBodySpec as RequestBodyObject,
Expand Down

0 comments on commit 928658b

Please sign in to comment.