Forum Discussion

flrasmith's avatar
flrasmith
New Contributor
6 years ago

Appreciate direction on best way to leverage the basePath feature of swagger-ui

New to Swagger,

 

I am needing to specify an alternative path to be used in the try it exec section of swagger api documentation.

 

i.e. Need "/api" to be introduce only in the try it exec section

 

  • Curl:

 

curl -X GET "http://localhost:8080/myproject-mw/api/myOneOfMyEndPoint" -H "accept: application json" 

 

  • Request URL:

 

http://localhost:8080/myproject-my/api/myOneOfMyEndPoint

 

 

 

But, due to the specific implementation (out of my control) of the front and back end design ...  the normal mapping (via RequestMapping anotation) needs to remian without the "/api" (i.e. "/myOneOfMyEndPoint" without the prepended "/api" ) in order for the front end to be able to work with the back end. 

 

       @RequestMapping(value = "/myOneOfMyEndPoint", method = RequestMethod.GET, produces = "application/json")

       @ApiOperation(value = "Method to fetch blah, blah and more blah in the system",

    notes = "Method to fetch all blah, blah and more blah in the system that will return - myCustomPageDTO",

    response = myCustomPageDTO.class, 

    responseContainer = "myCustomPageDTO")

       public StatusPageDTO myOneOfMyEndPoint() {

 

        .... my code ....

 

       }

 

So, currently ... 

 

I have the swagger-ui.html (dynamic redering) working with annotation. Using the following...

 

<springfox-swagger2-version>2.8.0</springfox-swagger2-version>

<springfox-swaggerui-version>2.8.0</springfox-swaggerui-version>

 

  • I think and hope that one solution could be with using / leveraging  basePath, but not sure what would be the best way to do so.

 

Any direction / suggestion would be appriciated.

 

NOTE: THE FOLLOWING WAS THE MINIMUM THAT I NEEDED TO INTRODUCE SWAGGER-UI TO THE EXSISTING PROJECT (swagger-ui works as expected but need the custom URL in try it area):

 

1) Added the two lines ("<springfox- ... >") to pom.xml :

 

<properties>

 

...

 

<springfox-swagger2-version>2.8.0</springfox-swagger2-version>

<springfox-swaggerui-version>2.8.0</springfox-swaggerui-version>

</properties>

 

2) Added the two <dependency> for "<!--SpringfoxSwaggerdependency -->" and four <dependency> for "<!-- Jaxbdependency -->" to pom.xml :

 

<dependencies>

 

...

 

<!--SpringfoxSwaggerdependency -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-swagger2-version}</version>
</dependency>
 
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-swaggerui-version}</version>
</dependency>
 
<!-- Jaxbdependency -->
 
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
 
...
 
</dependency>

 

 

3) Added the import and @ApiOperation() to ExsistingController.java :

 

import io.swagger.annotations.ApiOperation;

 

...

 

@ApiOperation(value = "Method to test the connactivity to the Backend",
    notes = "Testing the backend response that will return - Status page backend.",
    response = String.class, 
    responseContainer = "String")

 

 

4) Added the two <mvc:resources ...> to src/main/webapp/WEB-INF/spring-servlet.xml :

 

<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/" /> 
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/" />

 

 

5) Added the one line "<!-- Swagger2 Configuration -->" to src/main/webapp/WEB-INF/spring-servlet.xml :

 

<!-- Swagger2 Configuration -->

 

<beans>

 

...

 
<bean id="swagger2Config" class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration" />

 

...

 

</beans>

 

 

 

 

 

No RepliesBe the first to reply