Skip to content
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

servers support for multiple base path #604

Closed
subhransus2 opened this issue Jan 9, 2020 · 15 comments
Closed

servers support for multiple base path #604

subhransus2 opened this issue Jan 9, 2020 · 15 comments

Comments

@subhransus2
Copy link

Hi
I just want to add multiple base path in swagger doc.
For ex :
My base path is /api/v1
I have defined two tags(let say A and B)

  1. Endpoints under tag A will have url like

localhost:8080/api/v1/getList

  1. Endpoints under tag B will have url like

localhost:8080/api/v1/sub/getList

I can do this by adding @router /sub/getList [post], but it is not a best practice for adding /sub in all endpoints. So I am searching for solutions like define basepath for particular tags or override the global base path.

Or is there any way of adding servers like following:

"servers": [
    {
      "url": "https://localhost:8080/api/v1/"
    },
    {
      "url": "https://localhost:8080/api/v1/sub/"
    }
  ],
@sdghchj
Copy link
Member

sdghchj commented Jan 13, 2020

I am afraid this is no way

@subhransus2
Copy link
Author

Is there any other feasible solution to resolve this?

@sdghchj
Copy link
Member

sdghchj commented Jan 13, 2020

I think your had better first to find out whether swagger2.0 supports multiple base paths. If not, all here make no sense.

@subhransus2
Copy link
Author

I don't think swagger 2.0 supports multiple base paths. But if we can add servers like following then I guess it will be better as per my requirement.
This way we need to select the required path from the dropdown.

servers:
  - url: https://api.example.com/v1
    description: Production server (uses live data)
  - url: https://sandbox-api.example.com:8443/v1
    description: Sandbox server (uses test data)

@sdghchj
Copy link
Member

sdghchj commented Jan 13, 2020

Sorry, I haven't got your idea.
Does swagger UI supoort it ?

@subhransus2
Copy link
Author

subhransus2 commented Jan 13, 2020

@sdghchj
Copy link
Member

sdghchj commented Jan 13, 2020

I see.
However I found tag 'servers' is suported in openapi 3.0.0 but swag for swagger 2.0

@subhransus2
Copy link
Author

Yes.
Is there any plan to release and update to support Open API spec 3.0?

@sdghchj
Copy link
Member

sdghchj commented Jan 13, 2020

@easonlin404

@ubogdan
Copy link
Contributor

ubogdan commented Jan 15, 2020

@subhransus2 so far for this use case, we have support for controlling hostname/schema at runtime, please check this example.
Open API 2.0 doesn't have support for multiple endpoints definition.

servers:
  - url: https://api.example.com/v1
    description: Production server (uses live data)
  - url: https://sandbox-api.example.com:8443/v1
    description: Sandbox server (uses test data)

https://swagger.io/docs/specification/2-0/api-host-and-base-path/

@Nerzal
Copy link
Contributor

Nerzal commented Jan 31, 2020

We should definetly take a look at Open API 3.0 in the near future.
There are several great features to solve problems like this easily :)

@smithyj
Copy link

smithyj commented Jul 8, 2020

强烈支持大佬执行 3.0 升级计划

@ubogdan
Copy link
Contributor

ubogdan commented Sep 28, 2021

Closing: The generated swag documentation allows configurable Host and Basepath.

@ubogdan ubogdan closed this as completed Sep 28, 2021
@Nerzal
Copy link
Contributor

Nerzal commented Sep 29, 2021

Host and Basepath was not the answer to the issue :)

Use the @x-servers extension annotation for that feature.

@matanmarciano
Copy link

Host and Basepath was not the answer to the issue :)

Use the @x-servers extension annotation for that feature.

Can you give an example how to do that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants