@openapi-codegen/cli
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

OpenAPI Codegen

Getting started

  1. Add a openapi-codegen.config.ts at the root of your project
// openapi-codegen.config.ts
import { defineConfig } from "@openapi-codegen/cli";
import {
  generateSchemaTypes,
  generateReactQueryComponents,
} from "@openapi-codegen/typescript";

export default defineConfig({
  example: {
    from: {
      source: "github",
      owner: "fabien0102",
      repository: "openapi-codegen",
      ref: "main",
      specPath: "examples/spec.yaml",
    },

    // can be overridden from cli
    outputDir: "src/queries",

    to: async (context) => {
      const filenamePrefix = "example";

      // Generate all the schemas types (components & responses)
      const { schemasFiles } = await generateSchemaTypes(context, {
        filenamePrefix,
      });

      // Generate all react-query components
      await generateReactQueryComponents(context, {
        filenamePrefix,
        schemasFiles,
      });
    },
  },
});
  1. Expose openapi-codegen in your package.json
--- a/package.json
+++ b/package.json
   "scripts": {
+    "gen": "openapi-codegen",
   }
  1. Run the generator (example is the config key defined in the step 1)
$ yarn gen example
  1. Start playing! 🥳

Package Sidebar

Install

npm i @openapi-codegen/cli

Weekly Downloads

13,559

Version

2.0.1

License

MIT

Unpacked Size

3.72 MB

Total Files

30

Last publish

Collaborators

  • fabien0102