How to use the class-validator-jsonschema.validationMetadatasToSchemas function in class-validator-jsonschema

To help you get started, we’ve selected a few class-validator-jsonschema 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
createExpressServer,
  getMetadataArgsStorage
} from 'routing-controllers'
import { routingControllersToSpec } from 'routing-controllers-openapi'

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: {
github skmdev / koa-decorator-ts / src / decorators / router.ts View on Github external
const GetSchemaFromType = (Type: new () => any) => {
  const { name } = Type;
  const cached = SCHEMA_CACHE[name];
  if (cached) {
    return cached;
  }
  const metadatas = (getFromContainer(MetadataStorage) as any)
    .validationMetadatas;
  const allSchemas = validationMetadatasToSchemas(metadatas);
  const schema = allSchemas[name];
  if (!schema) {
    console.error(`No schema found for ${name}`);
  } else {
    SCHEMA_CACHE[name] = schema;
  }
  return schema;
};
github ollita7 / kiwi / src / metadata / metadataStorage.ts View on Github external
public static async  generateDoc(options?: IKiwiOptions) {
        var fs = require('fs');
        const swagger: any = {
            schemes: ["https", "http"],
            paths: {},
            openapi: "3.0.0",
            components: {}
        };
        const metadatas = (getFromContainer(MetadataStorage) as any).validationMetadatas;
        const schemas = validationMetadatasToSchemas(metadatas, {
            refPointerPrefix: '#/components/schemas'
        })
        swagger['components']['schemas'] = schemas;

        const routes = KiwiMetadataStorage.routes;
        forEach(Object.keys(routes), (url: string) => {
            swagger.paths[url] = {};
            forEach(Object.keys(routes[url]), (method) => {
                let path = replace(url, options.prefix, '');
                const tags = split(path, '/');
                swagger.paths[url][method] = {
                    consumes: ["application/json"],
                    produces: ["application/json"],
                    parameters: this.getParameters(routes[url][method].params),
                    tags: [tags[1]]
                }

class-validator-jsonschema

Convert class-validator-decorated classes into JSON schema

MIT
Latest version published 6 months ago

Package Health Score

66 / 100
Full package analysis

Popular class-validator-jsonschema functions