How to use openapi3-ts - 4 common examples

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 eropple / nestjs-openapi3 / src / utils / schema.ts View on Github external
export function parseSchemaLike(c: SchemaLike, modelsToParse: Array): O3TS.SchemaObject | O3TS.ReferenceObject {
  // It's important to note that this method DOES have a side effect: it
  // adds any found models to `modelsToParse`.

  if (typeof(c) === 'function') {
    return inferSchema(c, modelsToParse);
  } else if (Array.isArray(c)) {
    return { type: 'array', items: parseSchemaLike(c[0], modelsToParse) };
  } else if (isReferenceObject(c)) {
    return c;
  } else { // O3TS.SchemaObjects, but potentially with deeper schemaLikes.
    const ret: O3TS.SchemaObject = {
      ...c,
    };

    if (c.allOf) {
      ret.allOf = c.allOf.map(sub => parseSchemaLike(sub, modelsToParse));
    }

    if (c.anyOf) {
      ret.anyOf = c.anyOf.map(sub => parseSchemaLike(sub, modelsToParse));
    }

    if (c.oneOf) {
      ret.oneOf = c.oneOf.map(sub => parseSchemaLike(sub, modelsToParse));
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 };
github plumier / plumier / packages / swagger / src / index.ts View on Github external
function transform(routes: RouteInfo[]) {
    const group = groupRoutes(routes)
    const paths = transformPaths(group)
    return OpenApiBuilder.create({
        openapi: "3.0.0",
        info: { title: "title", version: "1.0.0" },
        paths
    }).getSpec()
}
github djfdyuruiry / ts-lambda-api / src / api / open-api / OpenApiGenerator.ts View on Github external
private generateApiOpenApiSpecBuilder(appConfig: AppConfig, middlewareRegistry: MiddlewareRegistry) {
        let openApiBuilder = OpenApiBuilder.create()
        let paths: IDictionary = {}
        let tags: IDictionary = {}

        this.logger.debug("Generating OpenAPI spec")

        if (appConfig.name) {
            this.logger.trace("title: %s", appConfig.name)

            openApiBuilder.addTitle(appConfig.name)
        }

        if (appConfig.version) {
            this.logger.trace("version: %s", appConfig.version)

            openApiBuilder.addVersion(appConfig.version)
        }

openapi3-ts

TS Model & utils for OpenAPI 3.x specification.

MIT
Latest version published 3 months ago

Package Health Score

83 / 100
Full package analysis