You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swagger Editor编写Swagger YAML报错,求修复以生成OpenAPI客户端代码

修复后的OpenAPI 3.0 YAML代码及错误说明

原代码存在的问题及修复点:

  • 路径参数定义不匹配:原路径/details/未包含路径参数details的占位符,需改为/details/{details}才能正确关联路径参数。
  • 版本结构混用:definitions是Swagger 2.0的字段,OpenAPI 3.0需使用根层级的components/schemas来定义数据模型。
  • 缩进层级混乱:原代码中parameters列表项、responses的缩进错误,需调整至对应父节点的正确层级。
  • 数据类型错误:OpenAPI规范中整数类型应为integer,而非int。
  • 响应Schema冲突:$ref会覆盖同层级的其他属性,原代码中在$ref后添加properties无效,需重新组织响应结构。

修复后的完整代码:

openapi: 3.0.0

info:
  description: |
    Rest Server API.
  version: 1.0.0-oas3
  title: Implementation of GET API in Swagger

paths:
  /details/{details}:
    get:
      parameters:
        - name: details
          in: path
          schema:
            type: string
            enum: ['all', 'message', 'successfulCalls','failedCalls']
            default: all
          required: true
      responses:
        '200':
          description: A list of calls (maybe filtered by details)
          content:
            application/json:
              schema:
                type: object
                properties:
                  details_name_test:
                    type: array
                    items:
                      $ref: '#/components/schemas/Call'
                  message:
                    type: string
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string

components:
  schemas:
    Call:
      type: integer

内容的提问来源于stack exchange,提问作者Lalit Kumar Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 12:43:30