我正在尝试在我的OAS3项目中使用Swagger Codegen。我已经克隆了swagger codegen分支3.0.0。当我运行generate命令时,我得到以下错误:
[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文件和codegen命令
Petstore.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
Codegen命令:
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代码编码不支持OpenAPI 3.0。
可以从以下网址下载V3 codegen的JAR:< br > http://central . maven . org/maven 2/io/swagger/codegen/V3/swagger-codegen-CLI/3 . 0 . 11/swagger-codegen-CLI-3 . 0 . 11 . JAR
然而,V3 codecen目前没有JavaScript客户端生成器。