0

I have a new Spring Boot project that I'm setting up and have modeled it after another similar project. For the swagger-ui.html page for the new project we get a generic "No operations defined in spec!" message and no Swagger documentation.

I've tracked the issue down to the generated v2/api-docs JSON file.

For my working project, we have the expected swagger JSON and the HTML page is generated correctly

{
    swagger: "2.0",
    info: {},
    basePath: "/",
    tags: [],
    paths: {},
    definitions: {}
}

For the new, broken project, there is a value key and all the usual swagger JSON is a stringified value for that key.

{
    value: "{"swagger":"2.0","info":{"...}"
}

The projects all have effectively the same version of Gradle, Java, Swagger, and any other versions that I've looked at. SwaggerConfigs look to be identical as well.

Is there some undocumented setting or API interaction that would cause this swagger JSO to generate incorrectly?

GeoGriffin
  • 1,065
  • 11
  • 26

1 Answers1

0

You can re-config the JsonSerializer,like something below described:

adapter:

public 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());
    }
 } 

Gson config:

@Configuration
public class GsonHttpMessageConverterConfig {

    @Bean
    public GsonHttpMessageConverter gsonHttpMessageConverter() {
        GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
        converter.setGson(gson());
        return converter;
    }

    private Gson gson() {
        final GsonBuilder builder = new GsonBuilder();
        builder.registerTypeAdapter(Json.class, new SpringfoxJsonToGsonAdapter());
        return builder.create();
    }
}