swagger - How can I setup a path to use a parameter reference and override the name property?
问题描述
I have multiple paths that require an id number. There are some paths where multiple ids are required.
I know that I can reference a parameter when building a path.
paths:
/path1/{path1ID}
parameters:
- $ref: '#/components/parameters/path1ID_param'
components:
parameters:
path1ID_param:
name: path1ID
in: path
schema:
type: integer
If I do it this way, I'm going to have a lot of repeated definitions where the only change is the name. This grates.
Is there a way I can override the name in the path definition? I have tried variations of allOf
but haven't hit on anything yet. I've searched the swagger documentation without much luck. I've searched here and found a lot of interesting pointers that helped me refine my API ... but I found nothing related to what I'm trying to do.
Is it possible to do something like this?
paths:
/path1/{path1ID}
parameters:
- $ref: '#/components/parameters/parmID_param/'
- name: path1ID
/path1/{path1ID}/subpath2/{subpath2ID}
- $ref: '#/components/parameters/parmID_param/'
- name: path1ID
- $ref: '#/components/parameters/parmID_param/'
- name: subpath2ID
components:
parameters:
path1ID_param:
name: path1ID
in: path
schema:
type: integer
解决方案
这是不支持的。
从 OpenAPI 3.1 开始,您只能覆盖被description
引用参数的 ,但不能覆盖其name
或其他属性(required
、style
等)。
以下是 OpenAPI 规范存储库中现有的功能请求:
推荐阅读
- sql - 在 Oracle ROWID 上连接表
- python - 有没有办法在函数返回的 Python 对象上调用方法?
- python - vscode 未检测到 ipykernel,已验证它实际上已安装
- c++ - Is calling dlclose() from code loaded by the corresponding dlopen() OK?
- java - Finding the type of variable, knowing it's a primitive datatype
- position - 如何在 gdscript 中获取不同对象的位置?
- node-modules - 你如何打包一个 tree-sitter 语法以供消费?
- c++ - Binding free functions as class member functions
- r - 如何使用 sjPlot 在 R Shiny 中报告 html 表?
- javascript - Dynamically Select An HTML option based previous select option