Forum Discussion

Krishnan79's avatar
Krishnan79
New Contributor
7 months ago

Duplicate server variables in OpenAPI

Some one assist on this use case

Facing Duplicate server variables in OpenAPI documentation lead to maintenance issues and violate the DRY principle

 

Example:

 

servers:

  - name: Server 1

    variables:

      foo:

        $ref: '#/variables/foo'

  - name: Server 2

    variables:

      bar:

        $ref: '#/variables/bar'

 

variables:

  foo:

    value: 'foo-value'

  bar:

    value: 'bar-value'

  • Hi Krishnan79 

    Try creating a centralized 'variables' section and used the '$ref' keyword to reference variables in each server, eliminating duplication and it improves maintenance as well. 

  • Humashankar's avatar
    Humashankar
    Champion Level 2

    Hi Krishnan79 

    Try creating a centralized 'variables' section and used the '$ref' keyword to reference variables in each server, eliminating duplication and it improves maintenance as well. 

  • Krishnan79's avatar
    Krishnan79
    New Contributor

    I see your point and am able to clear things - thanks for helping