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

Unclear documentation for working with relative path for swagger.json #4136

Closed
alecStewart1 opened this issue Mar 11, 2022 · 2 comments
Closed

Comments

@alecStewart1
Copy link

Hello,

I'm working on a project where we are using Swagger 1.5. The issue we're running into is on our staging server, Swagger still looks at https://localhost:XXXX/api/swagger.json for the relevant swagger file.

We're using the web.xml configuration with a Spring Servlet and we're making use of Java annotations. Here's an example of what we have:

    <servlet>
        <servlet-name>ApiServlet</servlet-name>
        <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>io.swagger.jaxrs.json;io.swagger.jaxrs.listing;</param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/some-configuration.xml</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>ApiServlet</servlet-name>
        <url-pattern>/api/*</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>Jersey2Config</servlet-name>
        <servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
        <init-param>
            <param-name>api.version</param-name>
            <param-value>0.1</param-value>
        </init-param>
        <init-param>
            <param-name>swagger.api.basepath</param-name>
            <param-value>/api</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>

We also have a swagger.yaml file at the root of our project that's more or less this:

swagger: 2.0
info:
  title: API
  description: > 
    An API
  version: 0.1
consumes:
  - application/json
produces:
  - application/json
basePath: /api

As pointed here here on the websites documentation

A possible way to target multiple hosts is to omit the host and schemes from your specification and serve it from each host. In this case, each copy of the specification will target the corresponding host.

But Swagger always looks at localhost:XXXX.

@alecStewart1
Copy link
Author

This related to certain issues regarding CORS policies?

@alecStewart1
Copy link
Author

Found out it's an issue with the configuration settings for swagger-ui. Didn't know you can do relative urls.

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

1 participant