How to use the routing-controllers.getMetadataArgsStorage function in routing-controllers

To help you get started, we’ve selected a few routing-controllers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github epiphone / routing-controllers-openapi / sample / 01-basic / app.ts View on Github external
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'
  }
})
github typeorm / typeorm-routing-controllers-extensions / src / decorators / EntityFromCookie.ts View on Github external
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)
        });
    };
}
github typeorm / typeorm-routing-controllers-extensions / src / decorators / EntityFromBodyParam.ts View on Github external
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;
github typeorm / typeorm-routing-controllers-extensions / src / decorators / EntityFromQuery.ts View on Github external
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)
        });
    };
}
github typeorm / typeorm-routing-controllers-extensions / src / decorators / EntityFromBody.ts View on Github external
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 => {
github typeorm / typeorm-routing-controllers-extensions / src / decorators / EntityFromParam.ts View on Github external
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)
        });
    };
}