Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { UsersController } from './UsersController'
const routingControllersOptions = {
controllers: [UsersController],
routePrefix: '/api'
}
const app: Express = createExpressServer(routingControllersOptions)
// Parse class-validator classes into JSON Schema:
const metadatas = (getFromContainer(MetadataStorage) as any).validationMetadatas
const schemas = validationMetadatasToSchemas(metadatas, {
refPointerPrefix: '#/components/schemas/'
})
// Parse routing-controllers classes into OpenAPI spec:
const storage = getMetadataArgsStorage()
const spec = routingControllersToSpec(storage, routingControllersOptions, {
components: {
schemas,
securitySchemes: {
basicAuth: {
scheme: 'basic',
type: 'http'
}
}
},
info: {
description: 'Generated with `routing-controllers-openapi`',
title: 'A sample API',
version: '1.0.0'
}
})
return function(object: Object, method: string, index: number) {
const reflectedType = (Reflect as any).getMetadata("design:paramtypes", object, method)[index];
const isArray = reflectedType && reflectedType.name ? reflectedType.name.toLowerCase() === "array" : false;
const target = options && options.type ? options.type : reflectedType;
if (!target)
throw new Error("Cannot guess type if the parameter");
getMetadataArgsStorage().params.push({
object: object,
method: method,
index: index,
name: paramName,
type: "cookie",
parse: options && options.parse,
required: options && options.required,
transform: (actionProperties, value) => entityTransform(value, target, isArray, options)
});
};
}
return function(object: Object, method: string, index: number) {
const reflectedType = (Reflect as any).getMetadata("design:paramtypes", object, method)[index];
const isArray = reflectedType && reflectedType.name ? reflectedType.name.toLowerCase() === "array" : false;
const target = options && options.type ? options.type : reflectedType;
if (!target)
throw new Error("Cannot guess type if the parameter");
getMetadataArgsStorage().params.push({
object: object,
method: method,
index: index,
name: paramName,
type: "body-param",
parse: options && options.parse,
required: options && options.required,
transform: (actionProperties, value) => {
if (value === undefined || value === null) return undefined;
const connection = getConnectionManager().get(options ? options.connection : undefined);
function buildMap(target: Function, maps: { target: Function, properties: any }[]) {
if (!!maps.find(map => map.target === target))
return maps;
return function(object: Object, methodName: string, index: number) {
const reflectedType = (Reflect as any).getMetadata("design:paramtypes", object, methodName)[index];
const isArray = reflectedType && reflectedType.name ? reflectedType.name.toLowerCase() === "array" : false;
const target = options && options.type ? options.type : reflectedType;
if (!target)
throw new Error("Cannot guess type if the parameter");
getMetadataArgsStorage().params.push({
object: object,
method: methodName,
name: paramName,
index: index,
type: "query",
parse: options && options.parse,
required: options && options.required,
transform: (actionProperties, value) => entityTransform(value, target, isArray, options)
});
};
}
return function(object: Object, method: string, index: number) {
const reflectedType = (Reflect as any).getMetadata("design:paramtypes", object, method)[index];
const isArray = reflectedType && reflectedType.name ? reflectedType.name.toLowerCase() === "array" : false;
const target = options && options.type ? options.type : reflectedType;
if (!target)
throw new Error("Cannot guess type if the parameter");
getMetadataArgsStorage().params.push({
object: object,
method: method,
index: index,
type: "body",
parse: options && options.parse,
required: options && options.required,
transform: (action: Action, value: any) => {
const connection = getConnection(options ? options.connection : undefined);
function buildMap(target: Function, maps: { target: Function, properties: any }[]) {
if (!!maps.find(map => map.target === target))
return maps;
const map: any = { target: target, properties: {} };
maps.push(map);
connection.getMetadata(target).relations.forEach(relation => {
return function(object: Object, methodName: string, index: number) {
const reflectedType = (Reflect as any).getMetadata("design:paramtypes", object, methodName)[index];
const isArray = reflectedType && reflectedType.name ? reflectedType.name.toLowerCase() === "array" : false;
const target = options && options.type ? options.type : reflectedType;
if (!target)
throw new Error("Cannot guess type if the parameter");
getMetadataArgsStorage().params.push({
object: object,
method: methodName,
index: index,
name: paramName,
type: "param",
parse: options && options.parse,
required: options && options.required,
transform: (actionProperties, value) => entityTransform(value, target, isArray, options)
});
};
}