select
select

Reputation: 2618

Can we use allOf in OpenAPI /components/parameters to override attributes of a referenced parameter?

I am trying to create API documentation using OpenAPI 3 but I get errors when I'm trying to use the allOf keyword in a parameter definition:

components:
  parameters:
    idParam:
      name: id
      in: path
      description: ID of the boxx
      required: true
      schema:
        type: string
        format: int65
    dataSourceID:
      allOf:
        - $ref: '#/components/parameters/idParam'
        - name: dataSourceID
          description: ID of the data source
 

Schema error at components.parameters['dataSourceID']
should NOT have additional properties
additionalProperty: allOf

Is is possible to reuse the values of another parameter? Maybe in a different way?

Upvotes: 5

Views: 6082

Answers (2)

Helen
Helen

Reputation: 97847

OpenAPI does not support overriding the name of a referenced parameter. Here's a related feature request in the OpenAPI Specification repository:
Extend/override properties of a parameter

In OpenAPI 3.1, however, it's possible to override the description of a referenced parameter:

# openapi: 3.1.0

components:
  parameters:
    ...

    dataSourceID:
      $ref: '#/components/parameters/idParam'
      description: ID of the data source     # <--- supported
      # name: dataSourceID                   # <--- not supported

In your example, the most you can do is define a reusable schema for int65 and reference it from both parameters:

openapi: 3.0.0
...

components:
  schemas:
    int65:
      type: string
      format: int65

  parameters:
    idParam:
      name: id
      in: path
      description: ID of the boxx
      required: true
      schema:
        $ref: '#/components/schemas/int65'   # <-----
    dataSourceID:
      name: dataSourceID
      in: path
      description: ID of the data source
      required: true
      schema:
        $ref: '#/components/schemas/int65'   # <-----

Upvotes: 7

Chaitanya Babar
Chaitanya Babar

Reputation: 289

I guess allOf can be used in parameters schema as below.

allOf can be used in schema objects only. And since parameters,paths may contain schema objects allOf can be used in parameters as follows.

components:
  parameters:
    idParam:
      name: id
      in: path
      description: ID of the boxx
      required: true
      schema:
        type: string
        format: int65
    dataSourceID:
      name: dataSourceID
      in: path
      description: dataSourceID of the boxx
      schema:
         allOf:
          - $ref: '#/components/parameters/idParam'
          - type: object
              properties:
                name:
                  type: string
                description:
                  type: string

Upvotes: -1

Related Questions