Swagger OpenApi Codegen“;无法获取架构名称:“0”;
我使用OpenAPI生成器根据我的swagger.yaml生成客户端 我有这部分代码:Swagger OpenApi Codegen“;无法获取架构名称:“0”;,swagger,openapi,swagger-codegen,openapi-generator,codegen,Swagger,Openapi,Swagger Codegen,Openapi Generator,Codegen,我使用OpenAPI生成器根据我的swagger.yaml生成客户端 我有这部分代码: ... responses: '400': $ref: "#/errors/400" ... errors: '400': description: invalid request content: application/json: schema: $ref: "#/components/sch
...
responses:
'400':
$ref: "#/errors/400"
...
errors:
'400':
description: invalid request
content:
application/json:
schema:
$ref: "#/components/schemas/ErrResp"
...
components:
schemas:
ErrResp:
type: object
properties:
error_code:
$ref: "#/components/schemas/ErrCode"
error_msg:
type: string
ErrCode:
type: integer
description: |
2 - invalid request
...
使用以下命令执行生成:
openapi-generator generate -i myAPI.yaml -g typescript-fetch -o ./myAPI"
并警告:
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/errors/400
同时,对editor.swagger.io的检查不会出现错误和警告-文件描述正确。我暂时找到了以下关于如何避免此警告的解决方案,但我想知道为什么会出现此警告,我希望保留当前结构以避免冗余
解决办法是:
反而
使用以下选项,在这种情况下没有警告:
responses:
'400':
description: invalid request
content:
application/json:
schema:
$ref: "#/components/schemas/ErrResp"
看看这些错误,我认为在顶层不允许出现错误
它允许扩展,因此x-errors
可能有效
responses:
'400':
description: invalid request
content:
application/json:
schema:
$ref: "#/components/schemas/ErrResp"