首页 > 解决方案 > 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

标签: swaggeropenapi

解决方案


这是不支持的。

从 OpenAPI 3.1 开始,您只能覆盖被description引用参数的 ,但不能覆盖其name或其他属性(requiredstyle等)。

以下是 OpenAPI 规范存储库中现有的功能请求:


推荐阅读