How to use the openapi3-ts.OpenApiBuilder function in openapi3-ts

To help you get started, we’ve selected a few openapi3-ts 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 mflorence99 / serverx-ts / src / handlers / open-api.ts View on Github external
static fromRoutes(info: InfoObject, 
                    flattened: Route[]): OpenApiBuilder {
    const openAPI = new OpenApiBuilder().addInfo(info);
    // create each path from a corresponding route
    const paths = flattened.reduce((acc, route) => {
      const item: PathItemObject = acc[route.path] || { };
      // skeleton operation object
      const operation: OperationObject = {
        description: route.description || '',
        responses: { },
        summary: route.summary || '',
        parameters: []
      };
      // handle request body
      if (route.request && route.request.body) {
        const content: ContentObject = Object.entries(route.request.body)
          .map(([contentType, clazz]) => ({ contentType, schema: OpenAPI.makeSchemaObject(clazz) }))
          .reduce((acc, { contentType, schema }) => {
            acc[contentType] = { schema };

openapi3-ts

TS Model & utils for OpenAPI 3.x specification.

MIT
Latest version published 2 months ago

Package Health Score

80 / 100
Full package analysis