Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
endpoint.pathsMethods.forEach(pathMethod => {
/* istanbul ignore else */
if (!!pathMethod.method) {
const builder = new OpenApiEndpointBuilder(endpoint, endpointUrl, pathMethod, getOperationId).build();
deepExtends(paths, builder.paths);
deepExtends(definitions, builder.definitions);
}
});
});
const doc = conf.doc;
const tags: Tag[] = [];
const getOperationId = this.createOperationIdFormatter(conf);
this.controllerService.routes.forEach(({provider, route}) => {
const hidden = provider.store.get("hidden");
const docs = provider.store.get("docs") || [];
if ((!doc && !hidden) || (doc && docs.indexOf(doc) > -1)) {
this.buildRoutes(paths, definitions, provider, route, getOperationId);
tags.push(this.buildTags(provider));
}
});
return deepExtends(
defaultSpec,
{
tags,
paths,
definitions
},
getReducers()
);
}
private createResponses(builderResponses: OpenApiResponses): OpenApiResponses {
const responses = this.endpoint.get("responses") || {};
deepExtends(responses, builderResponses);
responses[this.endpoint.get("statusCode") || "200"] = {description: "Success"};
Object.keys(responses).forEach(code => {
responses[code] = this.createResponse(code, responses[code]);
});
return responses;
}
protected createSchemaFromBodyParam(param: ParamMetadata): Schema {
let builder;
const {currentProperty, schema} = this.createSchemaFromExpression(param);
if (param.isClass) {
builder = new OpenApiModelSchemaBuilder(param.type);
builder.build();
deepExtends(this._definitions, builder.definitions);
deepExtends(this._responses, builder.responses);
}
Object.assign(currentProperty, super.createSchema(param));
return schema;
}
export function schemaOptions(target: any, options?: MongooseModelOptions) {
const store = Store.from(target);
if (options) {
options = deepExtends(store.get(MONGOOSE_SCHEMA_OPTIONS) || {}, options);
store.set(MONGOOSE_SCHEMA_OPTIONS, options);
}
return store.get(MONGOOSE_SCHEMA_OPTIONS);
}
private createResponses(builderResponses: OpenApiResponses): OpenApiResponses {
const responses = this.endpoint.get("responses") || {};
deepExtends(responses, builderResponses);
responses[this.endpoint.get("statusCode") || "200"] = {description: "Success"};
Object.keys(responses).forEach(code => {
responses[code] = this.createResponse(code, responses[code]);
});
return responses;
}
private createOperation(builder: OpenApiParamsBuilder): Operation {
const operationId = this.getOperationId(this.endpoint.targetName, this.endpoint.methodClassName);
const security = this.endpoint.get("security");
const produces = this.endpoint.get("produces");
const consumes = this.endpoint.get("consumes");
return deepExtends(
{
operationId,
tags: [this.getTagName()],
parameters: builder.parameters.length ? builder.parameters : undefined,
consumes,
responses: this.createResponses(builder.responses),
security,
produces
},
this.endpoint.get("operation") || {}
);
}
this._definitions[model] = params.reduce((acc: any, param) => {
deepExtends(acc, this.createSchemaFromBodyParam(param));
if (param.required) {
this.addResponse400();
required = true;
}
return acc;
}, {});
if (+code === +expectedStatus) {
const response = this.store.get("response");
if (response) {
headers = response.headers || headers;
examples = response.examples || examples;
description = response.description || description;
this.type = response.type || this.type;
this.collectionType = response.collectionType || this.collectionType;
}
}
if (headers) {
headers = deepExtends({}, headers);
Object.keys(headers).forEach(key => {
delete headers[key].value;
});
}
return {
headers,
examples,
description
};
}