Nuxt-TS-Swagger plugin generator CLI
npm i -D nuxtswagger
Nuxt
base project@nuxtjs/axios
module
in Nuxt project directory
npx nuxtswagger https://api.server.foo/swagger.json
in nuxt.config.js
module.exports = {
plugins: [
'~/plugins/api'
]
}
in component
export default {
async asyncData ({ $api }) {
return { foo: await $api.foo.get() }
},
data () { return { bar: undefined } },
async mounted () { this.bar = await this.$api.bar.get() }
}
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 priority : command line > nuxt.config
> package.json
nuxtswagger argument1 --option1 value1 --option2 value2
option | description | default | example |
---|---|---|---|
(first argument) | Swagger schema JSON path | (required) | http://.. or ./foo/swagger.json |
src |
same as first argument | first argument | same as above |
plugins-dir |
Nuxt plugins directory | plugins |
|
plugin-name |
Name for generated plugin | api |
|
inject |
Nuxt plugin inject key | {plugin-name} |
|
type-path |
Path for scheme type file | {plugins-dir}/{plugin-name}/{types.ts} |
./types/swagger.d.ts |
base-path |
base path | /v1 |
/v2 |
skip-header |
Ignore parameter in header | false |
true |
form |
Path param interface mode | (undefined) | underscore |
{
"scripts": {
"swagger": "nuxtswagger"
},
"nuxtswagger": {
"pluginName": "foo",
"src": "https://api.server.foo/swagger.json"
}
}
v1.2+
export default {
// support array
publicRuntimeConfig: {
nuxtswagger: {
pluginName: 'foo',
// AxiosRequestConfig?
axiosConfig: { baseURL: 'https://api-stage.server.foo' }
}
}
}
{
"compilerOptions": {
"types": ["nuxtswagger/types"]
}
}
and npm run swagger
or npx nuxtswagger
ISC License Copyright (c) 2020, Elevista