Code Monkey home page Code Monkey logo

fabernovel-custom-openapi-generator's Introduction

openapi-generator

From an OpenAPI file, generate apigateway files or code.

Getting started

Configuration

Parameters

By default, openapi-generator will rely on your project package.json to get the following information:

  • name
  • version

It is possible to bypass or override these values by providing arguments when calling the program.

Example:

yarn openapi-generator --name Hello --version 2.3.4

An extra parameter is available: mode. It allows you to customise the configuration based on a given string. This will only work if the configuration exports a function.

Example:

yarn openapi-generator --mode production

Configuration

Create an openapi-generator.config.js file in your project. It can be located in any subfolder. However, the cli must be executed in the same folder or below to be detected.

It can follow one of the following naming conventions:

  • openapi-generator.config.js, openapi-generator.config.cjs (recommended)
  • openapi-generator in package.json
  • .openapi-generatorrc (yaml or json)
  • .openapi-generator.json, .openapi-generator.yaml, .openapi-generator.yml, .openapi-generator.js, .openapi-generator.cjs

All files must export an object with the schema defined below.

For .js config files, you can export a function which returns the aforementioned object:

module.exports = function({ mode }) {
  return {
    input: "path/to/openapi.yaml",
    ...
  }
}
API
Config
parameter type required description
input string required input path to openapi file (json or yaml)
normalizeInput (input: OpenAPIV3.Document, config: Config): OpenAPIV3.Document optional Normalize the openapi before being used by the operations
operations Operations required
operations.openapi OpenAPIOperation optional
operations.codegen CodegenOperation optional
OpenAPIOperation
parameter type required/optional description
output string required ouput path with filename
dryRun boolean optional (false) Generate the openapi file but do not save it on disk
validateSchema boolean optional (true) Validate the openapi schema when loading and saving the file
preTransform (input: OpenAPIV3.Document, config: Config) => OpenAPIV3.Document optional Transform the openapi file before transformations
postTransform (input: OpenAPIV3.Document, config: Config) => OpenAPIV3.Document optional Transform the openapi file after transformations
transformation object optional
transformation.cors (path: string, cors: object) => object optional Add and customise cors per route
transformation.securitySchemes object optional
transformation.securitySchemes.scheme Record<string, object> required OpenApi security scheme object
transformation.securitySchemes.filterSecurity (path: string, method: Method, security: Array<Record<string, string[]>>) => Array<Record<string, string[]>> | false optional Customise the security and the scopes on a per route basis. Routes are secured with no scopes by default
transformation.apiGatewayIntegration object optional
transformation.apiGatewayIntegration.proxyBaseUrl string required The base url for proxied requests
transformation.apiGatewayIntegration.routeIntegration (route: { path: string, method: Method }, extension: object) => object required Customise the provided route extensions on a per route basis. Routes are secured with no scopes by default
transformation.apiGatewayIntegration.securitySchemesExtensions Record<string, object> optional Add extensions to the provided operations.openapi.transformation.securitySchemes.scheme securities
transformation.apiGatewayIntegration.binaryMediaTypes string[] optional A list of binary MIME types
CodegenOperation
parameter type required description
output string required ouput path with filename
type "typings" | "contracts" | "fastify" | ["fastify", { iotsRouter?: boolean (false), noSchemas?: boolean (false) }] required Generate files based on provided type and options
Example configuration
module.exports = function ({ mode }) {
  return {
    input: "./openapi.yml",
    operations: {
      openapi: {
        output: "generated/apigateway.yaml.tpl",
        transformation: {
          cors: (path, cors) => cors,
          securitySchemes: {
            scheme: {
              openapi: {
                type: "http",
                scheme: "bearer",
                bearerFormat: "JWT"
              },
            },
            filterSecurity: (path, method, security) => security,
          },
          apiGatewayIntegration: {
            proxyBaseUrl: "${URL}",
            routeIntegration: (route, extension) => extension,
            securitySchemesExtensions: {
              openapi: {
                "x-amazon-apigateway-authtype": "cognito_user_pools",
                "x-amazon-apigateway-authorizer": {
                  type: "cognito_user_pools",
                  providerARNs: ["${ARN_COGNITO_HTAG}"],
                },
              },
            },
            binaryMediaTypes: ["image/*"],
          },
        },
      },
      codegen: {
        output: "example/generated",
        type: "fastify",
      },
    },
  };
};

fabernovel-custom-openapi-generator's People

Contributors

egovelox avatar

Stargazers

Lars Fronius avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.