Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (!spec.paths[path]) {
spec.paths[path] = {};
}
if (spec.paths[path][verb]) {
// Operations from subclasses override those from the base
debug(` Overriding ${endpointName} - endpoint was already defined`);
}
debug(` adding ${endpointName}`, operationSpec);
spec.paths[path][verb] = operationSpec;
debug(` inferring schema object for method %s`, op);
const opMetadata = MetadataInspector.getDesignTypeForMethod(
constructor.prototype,
op,
);
const paramTypes = opMetadata.parameterTypes;
const isComplexType = (ctor: Function) =>
!includes([String, Number, Boolean, Array, Object], ctor);
for (const p of paramTypes) {
if (isComplexType(p)) {
generateOpenAPISchema(spec, p);
}
}
}
return spec;
}
return function(target: object, member: string, index: number) {
paramSpec = paramSpec || {};
// Get the design time method parameter metadata
const methodSig = MetadataInspector.getDesignTypeForMethod(target, member);
const paramTypes = methodSig?.parameterTypes || [];
// Map design-time parameter type to the OpenAPI param type
const paramType = paramTypes[index];
if (paramType) {
if (
// generate schema if `paramSpec` doesn't have it
!paramSpec.schema ||
// generate schema if `paramSpec` has `schema` but without `type`
(isSchemaObject(paramSpec.schema) && !paramSpec.schema.type)
) {
// please note `resolveSchema` only adds `type` and `format` for `schema`
paramSpec.schema = resolveSchema(paramType, paramSpec.schema);
}
return function(target: object, member: string, index: number) {
debug('@requestBody() on %s.%s', target.constructor.name, member);
debug(' parameter index: %s', index);
/* istanbul ignore if */
if (debug.enabled)
debug(' options: %s', inspect(requestBodySpec, {depth: null}));
// Use 'application/json' as default content if `requestBody` is undefined
requestBodySpec = requestBodySpec ?? {content: {}};
if (_.isEmpty(requestBodySpec.content))
requestBodySpec.content = {'application/json': {}};
// Get the design time method parameter metadata
const methodSig = MetadataInspector.getDesignTypeForMethod(target, member);
const paramTypes = methodSig?.parameterTypes || [];
const paramType = paramTypes[index];
const schema = resolveSchema(paramType);
/* istanbul ignore if */
if (debug.enabled)
debug(' inferred schema: %s', inspect(schema, {depth: null}));
requestBodySpec.content = _.mapValues(requestBodySpec.content, c => {
if (!c.schema) {
c.schema = schema;
}
return c;
});
// The default position for request body argument is 0
// if not, add extension 'x-parameter-index' to specify the position