使用swagger 4.x包生成swagger 2.0 yaml
Generate swagger 2.0 yaml using swagger 4.x package
我要将我的 API 服务器集成到 Google Cloud Endpoints。
并且 Google Cloud Endpoints 目前支持 swagger 2.0。
但是我的dependencies/libraries现在是升级版了。所以我想生成 swagger 2.0 yaml 文件而不降级 swagger 库版本(api 端点已经用 swagger 4.x - openapi 3.0 spec 描述过)。
Nestjs 和 swagger 依赖项(package.json):
...
"@nestjs/common": "^7.0.0",
"@nestjs/config": "^0.4.0",
"@nestjs/core": "^7.0.0",
"@nestjs/platform-express": "^7.0.0",
"js-yaml": "^3.14.0",
...
"@nestjs/swagger": "^4.5.4",
"swagger-ui-express": "^4.1.4",
...
和 swagger 生成器脚本:
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as fs from 'fs'
import * as yaml from 'js-yaml'
const generateSwaggerYaml = async () => {
const app = await NestFactory.create(AppModule);
const options = new DocumentBuilder()
.setTitle('API Title')
.setDescription('API Description')
.build()
const document = SwaggerModule.createDocument(app, options)
fs.writeFileSync("./openapi-run.yaml", yaml.safeDump(document))
}
generateSwaggerYaml()
并且脚本的输出是开放的api 3.0 规范:(
openapi: 3.0.0
info:
title: API Title
description: API Description.
version: 1.0.0
contact: {}
tags: []
servers: []
...
有没有option/way从openapi 3.0文档生成swagger2.0 yaml?
如何将 openapi 3.0 规范降级为 swagger 2.0 规范?
我将 github 中的这个项目用于此目的:https://github.com/LucyBot-Inc/api-spec-converter
openapi 3 yaml转swagger 2 yaml,就这么简单$ api-spec-converter --from openapi_3 --syntax yaml --to swagger_2 ${f} > ${SWAGGER_V2_FILE}
我要将我的 API 服务器集成到 Google Cloud Endpoints。
并且 Google Cloud Endpoints 目前支持 swagger 2.0。
但是我的dependencies/libraries现在是升级版了。所以我想生成 swagger 2.0 yaml 文件而不降级 swagger 库版本(api 端点已经用 swagger 4.x - openapi 3.0 spec 描述过)。
Nestjs 和 swagger 依赖项(package.json):
...
"@nestjs/common": "^7.0.0",
"@nestjs/config": "^0.4.0",
"@nestjs/core": "^7.0.0",
"@nestjs/platform-express": "^7.0.0",
"js-yaml": "^3.14.0",
...
"@nestjs/swagger": "^4.5.4",
"swagger-ui-express": "^4.1.4",
...
和 swagger 生成器脚本:
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as fs from 'fs'
import * as yaml from 'js-yaml'
const generateSwaggerYaml = async () => {
const app = await NestFactory.create(AppModule);
const options = new DocumentBuilder()
.setTitle('API Title')
.setDescription('API Description')
.build()
const document = SwaggerModule.createDocument(app, options)
fs.writeFileSync("./openapi-run.yaml", yaml.safeDump(document))
}
generateSwaggerYaml()
并且脚本的输出是开放的api 3.0 规范:(
openapi: 3.0.0
info:
title: API Title
description: API Description.
version: 1.0.0
contact: {}
tags: []
servers: []
...
有没有option/way从openapi 3.0文档生成swagger2.0 yaml?
如何将 openapi 3.0 规范降级为 swagger 2.0 规范?
我将 github 中的这个项目用于此目的:https://github.com/LucyBot-Inc/api-spec-converter
openapi 3 yaml转swagger 2 yaml,就这么简单$ api-spec-converter --from openapi_3 --syntax yaml --to swagger_2 ${f} > ${SWAGGER_V2_FILE}