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

OpenAPI YAML路径错误:/photos不应有额外属性/{PhotoId}求助

问题分析与修复方案

核心错误:路径结构不符合OpenAPI规范

你收到的错误提示「不应有额外属性 /{PhotoId}」,根源是OpenAPI不允许在/photos路径下嵌套/{PhotoId}子路径。正确的写法是将两部分合并为**/photos/{PhotoId}**,作为一个独立的路径条目。

次要问题:参数定义重复且格式错误

你在get方法里重复定义了PhotoId参数,同时schema字段用了数组形式(- $ref),这两处都不符合规范:

  • 路径级的parameters已经通过$ref引用了PhotoId,方法级无需重复定义;
  • schema应直接引用参数,不需要加数组符号-。

修正后的代码示例

paths:
  /photos/{PhotoId}:  # 合并路径,不再嵌套
    parameters:
      - $ref: "#/components/parameters/XAppBuild"
      - $ref: "#/components/parameters/XAppVersion"
      - $ref: "#/components/parameters/XAppLanguage"
      - $ref: "#/components/parameters/XAppPlatform"
      - $ref: "#/components/parameters/PhotoId"
    get:
      # 移除重复的PhotoId参数定义
      responses:
        200:
          description: 成功获取照片详情

另外,确保components/parameters/PhotoId的定义格式正确,示例如下:

components:
  parameters:
    PhotoId:
      name: PhotoId
      in: path
      required: true
      schema:
        type: string  # 可根据需求改为integer等类型

内容的提问来源于stack exchange,提问作者Fernando Alonzi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 05:02:37