Socket
Book a DemoInstallSign in
Socket

@openapi-codegen/cli

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@openapi-codegen/cli

OpenAPI Codegen cli

Source
npmnpm
Version
2.0.4
Version published
Weekly downloads
26K
-19.81%
Maintainers
1
Weekly downloads
 
Created
Source

OpenAPI Codegen

Getting started

  • 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,
      });
    },
  },
});
  • Expose openapi-codegen in your package.json
--- a/package.json
+++ b/package.json
   "scripts": {
+    "gen": "openapi-codegen",
   }
  • Run the generator (example is the config key defined in the step 1)
$ yarn gen example
  • Start playing! 🥳

Keywords

openapi

FAQs

Package last updated on 17 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts