springboot整合gson打开swagger报错:Unable to render this definition。The provided definition does not specify a valid version field.
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
).
springboot整合gson之后打开swagger会报错,
将gson获取方式改下
import springfox.documentation.spring.web.json.Json;
private static final Gson gson = new GsonBuilder() .registerTypeAdapter(Json.class, new SpringfoxJsonToGsonAdapter()) .create(); public static Gson getGson() { return gson; } private static class SpringfoxJsonToGsonAdapter implements JsonSerializer<Json> { @Override public JsonElement serialize(Json json, Type type, JsonSerializationContext context) { final JsonParser parser = new JsonParser(); return parser.parse(json.value()); } }
相关依赖,已经引入了就不需要了
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-spring-web</artifactId> <version>3.0.0</version> <scope>compile</scope> </dependency>
-----------------------有任何问题可以在评论区评论,也可以私信我,我看到的话会进行回复,欢迎大家指教------------------------
(蓝奏云官网有些地址失效了,需要把请求地址lanzous改成lanzoux才可以)