Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor,
);
if (spec) {
debug(' using class-level spec defined via @api()', spec);
spec = DecoratorFactory.cloneDeep(spec);
} else {
spec = {paths: {}};
}
let endpoints =
MetadataInspector.getAllMethodMetadata(
OAI2Keys.METHODS_KEY,
constructor.prototype,
) || {};
endpoints = DecoratorFactory.cloneDeep(endpoints);
for (const op in endpoints) {
debug(' processing method %s', op);
const endpoint = endpoints[op];
const verb = endpoint.verb!;
const path = endpoint.path!;
let endpointName = '';
/* istanbul ignore if */
if (debug.enabled) {
const className = constructor.name || '';
const fullMethodName = `${className}.${op}`;
endpointName = `${fullMethodName} (${verb} ${path})`;
}
let operationSpec = endpoint.spec;
function resolveControllerSpec(constructor: Function): ControllerSpec {
debug(`Retrieving OpenAPI specification for controller ${constructor.name}`);
let spec = MetadataInspector.getClassMetadata(
OAI2Keys.CLASS_KEY,
constructor,
);
if (spec) {
debug(' using class-level spec defined via @api()', spec);
spec = DecoratorFactory.cloneDeep(spec);
} else {
spec = {paths: {}};
}
let endpoints =
MetadataInspector.getAllMethodMetadata(
OAI2Keys.METHODS_KEY,
constructor.prototype,
) || {};
endpoints = DecoratorFactory.cloneDeep(endpoints);
for (const op in endpoints) {
debug(' processing method %s', op);
const endpoint = endpoints[op];
const verb = endpoint.verb!;
op,
);
if (params == null) {
params = MetadataInspector.getMethodMetadata(
OAI2Keys.METHODS_WITH_PARAMETERS_KEY,
constructor.prototype,
op,
);
}
debug(' parameters for method %s: %j', op, params);
if (params != null) {
const bodyParams = params.filter(p => p && p.in === 'body');
if (bodyParams.length > 1) {
throw new Error('More than one body parameters found: ' + bodyParams);
}
params = DecoratorFactory.cloneDeep(params);
/**
* If a controller method uses dependency injection, the parameters
* might be sparsed. For example,
* ```ts
* class MyController {
* greet(
* @inject('prefix') prefix: string,
* @param.query.string('name) name: string) {
* return `${prefix}`, ${name}`;
* }
* ```
*/
operationSpec.parameters = params.filter(p => p != null);
}
operationSpec['x-operation-name'] = op;