Skip to content

danielpox/swagger-client-codegen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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