1.0.0 • Published 6 months ago

nextswagger v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

NexTSwagger

Next-TS-Swagger plugin generator CLI

npm package github stars

Installation

npm i -D nextswagger

Requirements

Basic Usage

in Next project directory

npx nextswagger https://api.server.foo/swagger.json

in component

import {api} from './api'
const foo = await api().bar.get()

Path param mode

see form option

/* default (1.1.0+) */
api().foo.bar(1).get(2)
api().foo.bar.get()

/* underscore */
api().foo._bar.get(1, 2)
api().foo.bar.get()

Options

options priority : command line > next.config > package.json

nextswagger argument1 --option1 value1 --option2 value2
optiondescriptiondefaultexample
(first argument)Swagger schema JSON path(required)http://.. or ./foo/swagger.json
srcsame as first argumentfirst argumentsame as above
plugins-dirDirectorylib
plugin-nameName for generated flileapi
export-nameExport name{plugin-name}''(export default)
type-pathPath for scheme type file{plugins-dir}/{plugin-name}/{types.ts}./types/models.ts
base-pathbase path/v1/v2
skip-headerIgnore parameter in headerfalsetrue
formPath param interface mode(undefined)underscore

Set options using next.config

import { NextConfig } from 'nextswagger'
const config: NextConfig = {
  serverRuntimeConfig: {
    nextswagger: [
      { pluginName: 'foo', src: 'https://api.server.foo/swagger.json' },
      { pluginName: 'bar', src: 'https://api.server.bar/swagger.json' }
    ]
  },
  publicRuntimeConfig: {
    nextswagger: {
      pluginName: 'foo',
      // AxiosRequestConfig?
      axiosConfig: { baseURL: 'https://api-stage.server.foo' }
    }
  },
}
export default config

Set options using package.json

{
  "nextswagger": {
    "pluginsDir": "api"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "types": ["nextswagger/types"]
  }
}

and npm run swagger or npx nextswagger

License

ISC License Copyright (c) 2023, Elevista