我正在拆分YAML文件,但是在生成代码时出现以下异常:
java.lang.NullPointerException
at io.swagger.v3.parser.ResolverCache.updateLocalRefs(ResolverCache.java:162)
at io.swagger.v3.parser.ResolverCache.loadRef(ResolverCache.java:152)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalResponse(ExternalRefProcessor.java:205)
at io.swagger.v3.parser.processors.ResponseProcessor.processReferenceResponse(ResponseProcessor.java:76)
at io.swagger.v3.parser.processors.ResponseProcessor.processResponse(ResponseProcessor.java:38)
at io.swagger.v3.parser.processors.OperationProcessor.processOperation(OperationProcessor.java:56)
at io.swagger.v3.parser.processors.PathsProcessor.processPaths(PathsProcessor.java:83)
at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:49)
at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:53)
at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:19)
我正在尝试实现的示例(openapi.yaml
):
openapi: 3.0.0
info:
title: Common Data Types
version: "1.0"
paths:
/{appId}/subscriptions:
get:
summary: read all of the active subscriptions for the app
responses:
'200':
description: OK (Successful)
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/subscription'
'400':
$ref: './common.yam#/components/responses/E400'
'401':
$ref: './common.yam#/components/responses/E401'
components:
schemas:
subscription:
type: string
和common.yaml
:
openapi: 3.0.0
info:
title: Common Data Types
version: "1.0"
paths: {}
components:
responses:
E400:
description: Bad request
E401:
description: Unauthorized
内容:
$ tree
├── common.yaml
└── openapi.yaml
$ openapi-generator version
3.3.0
观察结果:
一种观察结果是,如果从“响应”插入的外部文件中引用“方案”,则代码生成有效。所以!如果从外部yaml文件引用“响应”,会出现什么问题?
以下工作:-从外部引用“方案”而不是“响应”(openapi.yaml
):
openapi: 3.0.0
info:
title: Common Data Types
version: "1.0"
paths:
/{appId}/subscriptions:
get:
summary: read all of the active subscriptions for the app
responses:
'200':
description: OK (Successful)
content:
application/json:
schema:
type: array
items:
$ref: './common.yam#/components/schemas/subscription'
'400':
$ref: '#/components/responses/E400'
'401':
$ref: '#/components/responses/E401'
components:
responses:
E400:
description: Bad request
E401:
description: Unauthorized
和common.yaml
:
openapi: 3.0.0
info:
title: Common Data Types
version: "1.0"
paths: {}
components:
schemas:
subscription:
type: string
上下文:
$ tree
.
├── common.yaml
└── openapi.yaml
$ openapi-generator version
3.3.0
已在中解决此问题openapi-generator-cli-4.0.0-beta3
。
但是,以下3.3.0
版本适用
我观察到的是,导致问题的以下if common.yaml文件被修改为common_modified.yaml,问题得以解决,并且没有Null指针异常。
YAML导致问题 common.yaml
openapi: 3.0.0
info:
title: Common Data Types
version: "1.0"
paths: {}
components:
responses:
E400:
description: Bad request
E401:
description: Unauthorized
修改后的YAML解决了该问题 common_modified.YAML
openapi: 3.0.0
info:
title: Common Data Types
version: "1.0"
paths: {}
components:
responses:
E400:
description: Bad request
content:
applictaion/json:
E401:
description: Unauthorized
content:
applictaion/json:
如果外部引用,则开放API似乎会查找内容。不确定。但是对我有用!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句