question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow versioning at path:method level

See original GitHub issue

To facilitate the option of media-type versioning, it would be helpful to version at the path:method level. Here is the gist of my proposal: move version from root level to path:method level and represent as an array of versions. In making the change as described, my hope is that none of the existing functionality is sacrificed.

Single version example

/pets/{id}:
  put:
    tags:
    - "pets"
    versions:
    - version: "default"
      summary: "..."
      description: "..."
      ... all other properties formerly defined in the path-item

Multiple version example

/pets/{id}:
  put:
    tags:
    - "pets"
    versions:
    - version: "1"
      summary: "..."
      description: "..."
      operationId: "updatePet_v1"
      consumes:
      - "application/json"
      - "application/vnd.vendor.v1+json"
      deprecated: true
      ... all other properties currently defined in the path-item
    - version: "2"
      summary: "..."
      description: "..."
      operationId: "updatePet_v2"
      consumes:
      - "application/vnd.vendor.v2+json"
      ... all other properties currently defined in the path-item

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:14
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

24reactions
jacobwodcommented, Mar 4, 2021

I understand that this issue/feature request is still unresolved.

Still, I’m wondering: what is the current best practice? Path versioning should be quite common when your API starts to grow, so perhaps I’m misunderstanding some part of the specification, while the solution is obvious to others?

17reactions
damonsutherlandcommented, Feb 20, 2020

@gadton Thanks for pointing out another deficiency in the current 3.x spec with regards to media type versioning. To ensure I completely understand, let me restate.

Consider media-type versioning with the current 3.x spec:

openapi: 3.0.1
...
paths:
  /pets:
    post:
      tags:
      - pets
      summary: Create a new pet
      operationId: createPet
      requestBody:
        description: Pet object that needs to be added to the store
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
          application/vnd.vendor.v1+json:
            schema:
              $ref: '#/components/schemas/Pet'
          application/vnd.vendor.v2+json:
            schema:
              $ref: '#/components/schemas/Pet_v2'
        required: true
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
            application/vnd.vendor.v1+json:
              schema:
                $ref: '#/components/schemas/Pet'
            application/vnd.vendor.v2+json:
              schema:
                $ref: '#/components/schemas/Pet_v2'
      ...

In the above scenario, it is unclear what request content-type/response content-type combinations are legal. The best we could do is add a 406 response code with documentation indicating valid combinations. However, a move to versioning at the path:method level, we get this:

openapi: 4.0.0
...
paths:
  /pets:
    post:
      tags:
      - pets
      versions:
      - version: 1
        summary: Create a new pet
        operationId: createPet
        requestBody:
          description: Pet object that needs to be added to the store
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
            application/vnd.vendor.v1+json:
              schema:
                $ref: '#/components/schemas/Pet'
          required: true
        responses:
          200:
            description: successful operation
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/vnd.vendor.v1+json:
                schema:
                  $ref: '#/components/schemas/Pet'
      - version: 2
        summary: Create a new version 2 pet
        operationId: createPet_v2
        requestBody:
          description: Pet object that needs to be added to the store
          content:
            application/vnd.vendor.v2+json:
              schema:
                $ref: '#/components/schemas/Pet_v2'
          required: true
        responses:
          200:
            description: successful operation
            content:
              application/vnd.vendor.v2+json:
                schema:
                  $ref: '#/components/schemas/Pet_v2'
      ...

The intent is clear.

Read more comments on GitHub >

github_iconTop Results From Across the Web

API versioning methods: A brief reference - Red Hat Developer
This article provides a comprehensive list of the methodologies used for versioning your API.
Read more >
Four REST API Versioning Strategies - xMatters
One way to version a REST API is to include the version number in the URI path. xMatters uses this strategy, and so...
Read more >
How to Version a REST API - freeCodeCamp
URI path versioning implies orchestrated releases of application versions that will require one of two approaches: maintaining one version while ...
Read more >
API Versions - ServiceNow Developers
Versioning is enabled at the API level and is applied to all API Resources. To enable versioning, click the Enable versioning related link...
Read more >
How to manage REST API versioning with spring?
The idea is that the VersionRange annotation can define an open or closed version range. The first method is valid from versions 1.0...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found