OpenApi Codegen "无法获取模式名:"

问题描述 投票:0回答:1

我使用OpenAPI生成器来生成基于我的swagger.yamli的客户端上有这部分代码。

...
    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"

并有警告: "Failed get schema name:

[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: #/errors/400

同时,对editor.swagger.io的检查没有错误和警告--文件描述正确。我暂时找到了下面的解决方案,如何避免这个警告,但我想弄清楚为什么会出现这种情况,为了避免冗余,我想保留当前的结构。

解决方案是:代替

responses:
   '400':
      $ref: "#/errors/400"

使用下面的代码,在这种情况下,没有警告。

responses:
     '400':
        description: invalid request
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ErrResp"
swagger openapi swagger-codegen openapi-generator codegen
1个回答
-1
投票

在看 规范 我想 errors 在顶层是不允许的。

它允许扩展,所以 x-errors 也许可以。

© www.soinside.com 2019 - 2024. All rights reserved.