【问题标题】:OpenApi Codegen "Failed to get the schema name:"OpenApi Codegen“获取架构名称失败:”
【发布时间】:2020-08-22 17:12:58
【问题描述】:

我使用 OpenAPI Generator 根据我的 swagger.yaml 生成客户端 我有这部分代码:

...
    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':
      $ref: "#/errors/400"

使用以下内容,在这种情况下没有警告:

responses:
     '400':
        description: invalid request
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ErrResp"

【问题讨论】:

    标签: swagger openapi swagger-codegen openapi-generator codegen


    【解决方案1】:

    查看spec 我认为errors 在顶层是不允许的。

    它允许扩展,所以x-errors 可能会起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多