npm.io
0.1.10 • Published 6 years agoCLI

swagger-client-codegen

Licence
MIT
Version
0.1.10
Deps
4
Size
82 kB
Vulns
24
Weekly
0
Stars
5

swagger-client-codegen

Generate a TypeScript API client or GraphQL schema based on a Swagger JSON file

Installation

$ npm install swagger-client-codegen --save-dev
$ yarn add swagger-client-codegen --dev

Usage

CLI (Primary)
$ npx swagger-client-codegen --typescript --pathToSwaggerJSON 'https://some.url/path.json' --outputPath 'some/file/path'
$ yarn swagger-client-codegen --graphql --pathToSwaggerJSON '../some/file/path.json' --outputPath './some/file/path/' --includeJSONOutput

NOTE: Specifying a recursive outputPath (nested non-existing directories) will only work on Node >= v10.12!

You can also use swagger-client-codegen directly from your code, if that suits you, as mentioned in the following JavaScript and TypeScript sections.

JavaScript
const { generateTypeScriptClient, generateGraphQLClient } = require('swagger-client-codegen')

generateTypeScriptClient({
  pathToSwaggerJSON: 'https://some.url/path.json',
  outputPath: 'some/file/path'
})

generateGraphQLClient({
  pathToSwaggerJSON: '../some/file/path.json',
  outputPath: './some/file/path/',
  includeJSONOutput: true
})
TypeScript
import { generateTypeScriptClient, generateGraphQLClient } from 'swagger-client-codegen'

generateTypeScriptClient({
  pathToSwaggerJSON: 'https://some.url/path.json',
  outputPath: 'some/file/path'
})

generateGraphQLClient({
  pathToSwaggerJSON: '../some/file/path.json',
  outputPath: './some/file/path/',
  includeJSONOutput: true
})

Development

Build
$ npm run build # 1. Builds TypeScript to JavaScript
Run
$ npm run start # 2. Runs actual codegen

Keywords