class-validator#MetadataStorage TypeScript Examples

The following examples show how to use class-validator#MetadataStorage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Swagger.ts    From jaebook-server with MIT License 6 votes vote down vote up
/**
 * Swagger를 사용하도록 한다.
 * @param app Express Application
 */
export function useSwagger(app: express.Application) {
  // 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, routingControllerOptions, {
    components: {
      schemas,
      securitySchemes: {
        bearerAuth: {
          type: "http",
          scheme: "bearer",
          bearerFormat: "JWT",
        },
      },
    },
    info: {
      title: "JaeBook Server",
      description: "JaeBook API",
      version: "1.0.0",
    },
  });

  app.use(env.swagger.route, swaggerUi.serve, swaggerUi.setup(spec));
}