I am integrate the OpenAPI with my project, when I access the url: http://127.0.0.1:11014/swagger-ui/index.html
, shows error like this:
Unable to render this definition
The provided definition does not specify a valid version field.
Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: "2.0" and those that match openapi: 3.0.n (for example, openapi: 3.0.0).
this is the OpenAPI config:
package misc.config.openapi;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* https://springdoc.org/
* https://github.com/springdoc/springdoc-openapi
*/
@Configuration
public class OpenApiConfig {
@Bean
public GroupedOpenApi fortuneApi() {
GroupedOpenApi.Builder builder = GroupedOpenApi.builder()
.pathsToMatch("/fortune/**")
.group("dddd");
GroupedOpenApi groupedOpenApi = builder.build();
return groupedOpenApi;
}
@Bean
public OpenAPI fortuneAPI() {
return new OpenAPI()
.info(new Info().title("Fortune API")
.description("Spring shop sample application")
.version("v0.0.1")
.license(new License().name("Apache 2.0").url("http://springdoc.org")))
.externalDocs(new ExternalDocumentation()
.description("SpringShop Wiki Documentation")
.url("https://springshop.wiki.github.org/docs"));
}
}
I have read the question Swagger..Unable to render this definition The provided definition does not specify a valid version field and tried the answer, both did not work. what should I do to specify the version? This is the dependencies looks like:
api "org.springdoc:springdoc-openapi-ui:1.6.9"
I make a minimal reproduce and found the normal response is json object, but the problem response return string. This is the correct response:
{
"openapi": "3.0.1",
"info": {
"title": "Fortune API",
"description": "Spring shop sample application",
"license": {
"name": "Apache 2.0",
"url": "http://springdoc.org"
},
"version": "v0.0.1"
},
"externalDocs": {
"description": "SpringShop Wiki Documentation",
"url": "https://springshop.wiki.github.org/docs"
},
"servers": [
{
"url": "http://127.0.0.1:11018",
"description": "Generated server url"
}
],
"paths": {},
"components": {}
}
this is the problem response in my project:
"{\"openapi\":\"3.0.1\",\"info\":{\"title\":\"Fortune API\",\"description\":\"Spri......
Finally I found that I changed the json converter cause this problem, this is a solved way:
this
StringHttpMessageConverter
should be the first one added into converter. I think this is the openapi design problem to make it hard to use. More information from here: