Search code examples
swaggeropenapi

In OpenApi, can I use the info.version as a default parameter elsewhere in the document?


I am writing an API spec in Open API.
I would like the paths to include their version as a parameter; this way, if there is a version change in the future, the implementing code could identify which version it was called with.
So far, so good.

What I would like is for the version of the API doc to be the default version in the path's version parameter.
Something like:

openapi: 3.0.3
info:
  title: JXG API
  version: 1.2.3

servers:
  - url: https://jxg.info/api

paths:
  /jxg:
    get:
      parameters:
        - in: header
          name: X-Version
          schema:
            type: string
            default: <info.version>
      responses:
        "200":
          description: OK.

Is there a way to get info.version into the default of the parameter schema?
I've looked at the documentation, and couldn't find anything in either direction.


Solution

  • Using the $ref keyword to reference the definition should work fine:

    schema:
      type: string
      default: 
        $ref: '#/info/version'