Skip to content

Feature Request: $ref for servers object #3129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shreelakshmijoshi opened this issue Jan 6, 2023 · 4 comments
Closed

Feature Request: $ref for servers object #3129

shreelakshmijoshi opened this issue Jan 6, 2023 · 4 comments
Labels
re-use: ref-everywhere Requests to support referencing in more / all places

Comments

@shreelakshmijoshi
Copy link

shreelakshmijoshi commented Jan 6, 2023

In many use cases, there would be multiple APIs that would be associated with different servers. It would be great if the server could be referenced from a single server object under components and reused everywhere instead of overriding the servers object for each API.
Currently,

  servers:
    - url: 'https://bookstore/v1'
      description: 'Get books from bookstore'
  paths:
     /book/{id}:
        get:

would result in API: https://bookstore/v1/book/123
But we also have the following apis that have server somewhere else, We'll have to override the global server variable in each of these paths which results in redundancy, maintenance issues when the server variables are changed.

  components:
     servers:
       - url1: 'https://bookstore/v1'
         description: 'Get books from bookstore'
       - url2: 'https://library/v2'
         description: 'Get books from library'
 
  $ref: "#/components/servers/url1"
  paths:
     /book/{id}:
        get:

     /libraryBook/{id}:
      $ref: "#/components/servers/url2"
        get:
        ...
        delete:
        ...

    /listLibraryBooks/
     $ref: "#/components/servers/url2"

Waiting to hear your thoughts!

@karenetheridge
Copy link
Member

Please could you fix the inconsistent indentation so it's valid yaml? it's difficult to understand what you're asking.

@shreelakshmijoshi
Copy link
Author

shreelakshmijoshi commented Jan 8, 2023

I fixed the indentation of both code blocks here:
Before,

components:
  servers:
    - url: 'https://bookstore/v1'
      description: 'Get books from bookstore'


paths:
  /book/{id}:
    get:
#      API -> GET: https://bookstore/v1/book/123

  /libraryBook/{id}:
    servers:
      - url: 'https://library/v2'
        description: 'Get books from library'
    get:
#      ....
#      API -> GET: https://library/v2/libraryBook/123
    delete:
#      ....
#      API -> DELETE: https://library/v2/libraryBook/123


  /listLibraryBooks/:
    servers:
      - url: 'https://library/v2'
        description: 'Get books from library'
    get:
#      API -> GET: https://library/v2/listLibraryBooks

After,

components:
  servers:
    - url1: 'https://bookstore/v1'
      description: 'Get books from bookstore'
    - url2: 'https://library/v2'
      description: 'Get books from library'


paths:
  /book/{id}:
    $ref: '#/components/servers/url1'
    get:
#      API -> GET: https://bookstore/v1/book/123

  /libraryBook/{id}:
    $ref: '#/components/servers/url2'
    get:
#      ....
#      API -> GET: https://library/v2/libraryBook/123
    delete:
#      ....
#      API -> DELETE: https://library/v2/libraryBook/123


  /listLibraryBooks/:
    $ref: '#/components/servers/url2'
    get:
#      API -> GET: https://library/v2/listLibraryBooks

Please let me know if this looks okay

@hkosova
Copy link
Contributor

hkosova commented Jan 9, 2023

Looks like a duplicate of #2338.

@handrews handrews added the $ref label Jan 27, 2024
@handrews
Copy link
Member

Yes, closing this as a duplicate of #2338.

@handrews handrews added re-use: ref-everywhere Requests to support referencing in more / all places and removed $ref labels Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
re-use: ref-everywhere Requests to support referencing in more / all places
Projects
None yet
Development

No branches or pull requests

4 participants