elevista / nuxtswagger Goto Github PK
View Code? Open in Web Editor NEWNuxt-TS-Swagger
Nuxt-TS-Swagger
Hi there, thanks for this handy library. I just found a issue when generating types:
When 200 responses only have description
I get the following error
node_modules/nuxtswagger/dist/schema/v3/Template.js:15
const schema = (_a = content['application/json']) === null || _a === void 0 ? void 0 : _a.schema;
^
TypeError: Cannot read property 'application/json' of undefined
Can you add support for responses with no return value?
{
"description": "object created"
}
The following code does not seem to set the baseurl. Anybody else has this issue?
publicRuntimeConfig: {
nuxtswagger: [
{
pluginName: 'api1',
axiosConfig: { baseURL: process.env.api1},
},
{
pluginName: 'api2',
axiosConfig: { baseURL: process.env.api2},
},
}
Following the README doesn't work.
npm i -D nuxtswagger
nuxtswagger https://api.server.foo/swagger.json
zsh: command not found: swagger
Later in the README I see we have to add the command to our package.json manually in the script section:
"scripts": {
"dev": "nuxt dev",
"build": "nuxt build",
"start": "nuxt start",
"swagger": "nuxtswagger"
},
But now the instruction are still wrong, we need to do
yarn run swagger https://api.server.foo/swagger.json
and not nuxtswagger https://api.server.foo/swagger.json
Hi,
How could I define requestInterceptor
and responseInterceptor
for the plugin ?
I currently use a custom plugin for Swagger and I did like so but it fetch the schema at runtime instead of build time which increase page load time.
import SwaggerClient from 'swagger-client';
export default async ({ app, $config, $auth }, inject) => {
const swagger = await SwaggerClient({
url: $config.apiURL,
async requestInterceptor(request) {
let jwt = $auth.strategy.token.get();
if (jwt) {
if ($auth.strategy.token.status().expired()) {
if ($auth.strategy.refreshToken.status().valid()) {
// Forcer le reload des tokens
await $auth.refreshTokens();
jwt = $auth.strategy.token.get();
} else {
$auth.logout();
return;
}
}
request.headers.Authorization = jwt;
}
request.headers['Accept-Language'] = app.i18n.locale;
request.headers.Accept = 'application/json';
return request;
},
responseInterceptor(response) {
if (response.status === 401) {
$auth.logout();
}
return response;
},
});
inject('swagger', swagger);
};
Currently this plugin only seem to support Swagger schema as JSON, but our project use an OpenAPI YAML schema.
Official swagger-client library also support OpenAPI schema definition in both JSON and YAML format, could it be possible to support this ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.