Swagger Codegen for OAS3



我正在尝试将Swagger Codegen用于我的OAS3项目。 我已经克隆了 swagger-codegen 分支 3.0.0。当我运行生成命令时,出现以下错误:

[main] ERROR io.swagger.parser.SwaggerCompatConverter - failed to read resource listing
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'openapi': was expecting ('true', 'false' or 'null')
at [Source: (String)"openapi: 3.0.0

Codegen 是否支持 openapi 3.0.1?如果是,我错过了什么?

更新 - Yaml 文件和代码生成命令

宠物商店.yaml 文件 :

openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
'200':
description: A paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
'201':
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string

代码生成命令:

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
java -jar ./swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i "./definitions/petstoreV3.yaml" -l javascript -o "$SCRIPT_DIR/.swagger_gen_temp"

发生此错误的原因是您正在运行 V2 代码生成(来自master分支(而不是 V3 代码生成(来自3.0.0分支(。V2 codegen 不支持 OpenAPI 3.0。

您可以从以下位置下载 V3 代码生成的 JAR:
http://central.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.11/swagger-codegen-cli-3.0.11.jar

但是,V3 codegen 目前没有 JavaScript 客户端生成器。

最新更新