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
相关产品推荐
相关产品推荐

