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
Swagger-ui is incorrectly using a base path when you "Try Out" the api #3351
Comments
It started three days ago springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NoSuchMethodError: org.springframework.util.MultiValueMap.addIfAbsent(Ljava/lang/Object;Ljava/lang/Object;)V An attempt was made to call a method that does not exist. The attempt was made from the following location:
The following method did not exist:
|
hi @dilipkrish Hope you are doing well, thanks for taking time to look into the issue. Appreciate it. I took all latest snapshots after you closed the issue. To make sure snapshots are updated, i deleted all the local dependencies and took fresh update. I am still seeing the same issue. I still see contextpath appended twice. I noticed one more issue with content negotiation. I will open it as a separate issue. Here is the API docs outpput example: {
"swagger": "2.0",
"info": {
"description": "A demo restful webservice project using spring boot",
"version": "1.0",
"title": "Restful webservices using spring boot",
"license": {
"name": "Apache License Version 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0"
}
},
"host": "127.0.0.1:8181",
"basePath": "/rwsspringboot",
"tags": [
{
"name": "hello-controller",
"description": "Hello Controller"
}
],
"consumes": [
"application/json",
"application/xml"
],
"produces": [
"application/json",
"application/xml"
],
"paths": {
"/rwsspringboot/hello": {
"get": {
"tags": [
"hello-controller"
],
"summary": "hello",
"operationId": "helloUsingGET",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/rwsspringboot/sayHello": {
"get": {
"tags": [
"hello-controller"
],
"summary": "hello",
"operationId": "helloUsingGET_1",
"parameters": [
{
"name": "name",
"in": "query",
"description": "name",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/rwsspringboot/sayHelloAgain": {
"get": {
"tags": [
"hello-controller"
],
"summary": "helloViaGetMapping",
"operationId": "helloViaGetMappingUsingGET",
"parameters": [
{
"name": "name",
"in": "query",
"description": "name",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/rwsspringboot/sayHelloBean": {
"get": {
"tags": [
"hello-controller"
],
"summary": "helloBeanViaGetMapping",
"operationId": "helloBeanViaGetMappingUsingGET",
"parameters": [
{
"name": "name",
"in": "query",
"description": "name",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Response"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/rwsspringboot/sayHelloBean/pathvariable/{name}": {
"get": {
"tags": [
"hello-controller"
],
"summary": "helloBeanViaGetMappingPathVariable",
"operationId": "helloBeanViaGetMappingPathVariableUsingGET",
"parameters": [
{
"name": "name",
"in": "path",
"description": "name",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Response"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
}
},
"definitions": {
"Response": {
"type": "object",
"properties": {
"statusCode": {
"type": "string"
},
"statusMessage": {
"type": "string"
}
},
"title": "Response"
}
}
}
URLs, notice the context path appended twice: curl -X GET "http://127.0.0.1:8181/rwsspringboot/rwsspringboot/hello" -H "accept: application/json" http://127.0.0.1:8181/rwsspringboot/rwsspringboot/hello Can you please open the issue again? |
Can you try one of two things,
|
Hi @dilipkrish I tried all the suggestions you provided. 1- Used "mvn clean install -U" to force loading all the snapshot dependencies. I had done this before my last reply itself. I still see the same issue. I tried downloading the demos project, the demo project is by default going to url: http://127.0.0.1:8181/springfox/swagger-ui.html which seems like the old URL and i get error page, swagger ui doesn't display. I downloaded master copy of this project. This is what i see in the demo project: Also http://127.0.0.1:8181/springfox/v2/api-docs doesn't load anything, i see error page This was the context path in springfox-demos\boot-swagger demo project: server.contextPath=/springfox |
I believe there was an outage in jfrog which is why you're not seeing the latest snapshot |
Hi @dilipkrish I tried again after your latest update, followed the same steps to bump the snapshot dependencies. Here is the list of snapshot dependencies under "io.springfox" springfox-bean-validators : 3.0.0-20200629.203154-85
springfox-boot-starter : 3.0.0-20200629.203154-26
springfox-core : 3.0.0-20200629.205144-86
springfox-data-rest : 3.0.0-20200629.205144-85
springfox-oas : 3.0.0-20200629.205144-63
springfox-schema : 3.0.0-20200629.205145-85
springfox-spi : 3.0.0-20200629.203155-85
springfox-spring-web : 3.0.0-20200629.205146-84
springfox-spring-webflux : 3.0.0-20200629.205146-77
springfox-spring-webmvc : 3.0.0-20200629.205146-77
springfox-swagger-common : 3.0.0-20200629.205147-85
springfox-swagger-ui : 3.0.0-20200629.123819-84
springfox-swagger2 : 3.0.0-20200629.203157-85 I am still seeing the same issue in swagger-ui (/rwsspringboot/rwsspringboot/hello): curl -X GET "http://127.0.0.1:8181/rwsspringboot/rwsspringboot/hello" -H "accept: application/json" http://127.0.0.1:8181/rwsspringboot/rwsspringboot/hello Api docs are still showing duplicate context paths, see the basepath and path: {
"swagger": "2.0",
"info": {
"description": "A demo restful webservice project using spring boot",
"version": "1.0",
"title": "Restful webservices using spring boot",
"license": {
"name": "Apache License Version 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0"
}
},
"host": "127.0.0.1:8181",
"basePath": "/rwsspringboot",
"tags": [
{
"name": "hello-controller",
"description": "Hello Controller"
}
],
"consumes": [
"application/json",
"application/xml"
],
"produces": [
"application/json",
"application/xml"
],
"paths": {
"/rwsspringboot/hello": {
"get": {
"tags": [
"hello-controller"
],
"summary": "hello",
"operationId": "helloUsingGET",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
}
},
"definitions": {
"Response": {
"type": "object",
"properties": {
"statusCode": {
"type": "string"
},
"statusMessage": {
"type": "string"
}
},
"title": "Response"
}
}
} I can attach the project link here if you want. |
Could you change your docket to |
Hi @dilipkrish Thanks it worked with 'DocumentationType.OAS_30'. However, produces and consumes option is no longer available, it shows "/". Do i need to make any changes to the docket config? See my docket api class below. Api docs does show produces and consumes: consumes: [ Docket api class: import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
@Configuration
public class SwaggerConfig {
private static final Set<String> DEFAULT_PRODUCES_AND_CONSUMES = new HashSet<String>(
Arrays.asList("application/json", "application/xml"));
@Bean
public Docket apiDocket() {
return new Docket(DocumentationType.OAS_30)
.select()
.apis(RequestHandlerSelectors.basePackage("com.github.abhinavmishra14.rws.controller.hello"))
.paths(PathSelectors.any())
.build().consumes(DEFAULT_PRODUCES_AND_CONSUMES).produces(DEFAULT_PRODUCES_AND_CONSUMES)
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Restful webservices using spring boot")
.description("A demo restful webservice project using spring boot")
.version("1.0")
.license("Apache License Version 2.0")
.licenseUrl("https://www.apache.org/licenses/LICENSE-2.0")
.build();
}
} |
What does your hello request mapping look like? |
@dilipkrish thanks for the fix. I just took latest snapshots after 03a10e6 commit. its working with classpath and duplicate context path is also gone. I can also see content type option. This is working with DocumentationType.SWAGGER_2. Thanks alot for fixing the issue. Appreciate it. |
hi @dilipkrish I was doing some testing around the various http method. I came across another issue when i try to use "Try-Out" for a POST method implementation. I see below error. It doesn't allow to edit the request body content and also it doesn't allow to select the request content type. I see an error in browser console as well: This is the details of POST implementation method in API docs: Path: /rwsspringboot/users/{id}/posts:
Method in controller class: @PostMapping(path = "/users/{id}/posts")
public ResponseEntity<Response> createPost(@PathVariable final int id, @RequestBody final Post post) {
if (id > 0) {
final User userById = userDao.findOne(id);
if (userById == null) {
throw new UserNotFoundException(String.format("User with id '%s' not found!", id));
}
final Post createdPost = postDao.save(id, post.getContent());
final Response resp = new Response("CREATED", "Post created successfully.");
resp.setAdditionalProperty("post", createdPost);
final URI location = ServletUriComponentsBuilder.fromCurrentRequest().buildAndExpand(id).toUri();
return ResponseEntity.created(location).body(resp);
} else {
throw new RWSException(String.format("User id '%s' is invalid!", id));
}
} Let me know if you need any details. Thanks again for all the help resolving the issues. |
This is good thanks for persisting the testing. |
hi @dilipkrish
Thanks for responding. I really appreciate it. Followed the instructions as suggested:
1- Removed dependencies springfox-swagger-ui, springfox-swagger2 and springfox-spring-webmvc
2- Added springfox-boot-starter
3- Removed @EnableSpringfoxWebMvc annotation from SwaggerConfig class.
4- Updated contextPath in application.properties :
server.servlet.contextPath=/rwsspringboot
5- Restarted the spring boot app.
I can see the api-docs at : http://127.0.0.1:8181/rwsspringboot/v2/api-docs
Where basePath is -> "/rwsspringboot"
And all endpoints also shows context path in url, e.g.: /rwsspringboot/hello
Hence, when i load swagger-ui at : http://127.0.0.1:8181/rwsspringboot/swagger-ui/index.html , i see the UI loaded properly. However, when i use "Try-out" option, this is what i see:
CURL: curl -X GET "http://127.0.0.1:8181/rwsspringboot/rwsspringboot/hello" -H "accept: application/json"
Requsest URL: http://127.0.0.1:8181/rwsspringboot/rwsspringboot/hello
Notice the path in the URL above ^^^^
Error:
Response { "timestamp": "2020-06-27T18:35:49.913+00:00", "status": 404, "error": "Not Found", "message": "No message available", "path": "/rwsspringboot/rwsspringboot/hello" }
So, the problem is that, as soon as i add context path, i start seeing the context path twice in the request urls. I think basepath should remain "/" or it should not append "/rwsspringboot" in the endpoint path when basepath is already set: /rwsspringboot
Full APIDocs:
The text was updated successfully, but these errors were encountered: