Rora
Rora

Reputation: 1

Swagger 2.8.0 unable to generate api-docs

I am unable to get a valid json in my spring boot application, when i call the swagger /v2/api-docs endpoint.

Chrome error message:

This page contains the following errors: error on line 1 at column 1330: xmlParseEntityRef: no name Below is a rendering of the page up to the first error.

With the developer tools i see that the swagger.json is wrapped in xml tags, also the content type is set to application/xhtml+xml. The response look like this:

<Json>{"swagger":"2.0",..............</Json>

I am using Spring Boot 2.0.0.RELEASE, Spring 5.0.4.RELEASE and for XML mapping the jackson-dataformat-xml dependency version 2.9.4.

Is there a way that i can send application/json as content type or configure the jackson dependency, that spring loads it not as the first in classpath? Or is there any other way to fix it?

For Jackson we only used the import, no seperate configuration.

Swagger Configuration:

@SpringBootApplication (exclude = {SecurityAutoConfiguration.class})
public class Main {

public static void main(String[] args) {
    SpringApplication.run(Main.class, args);
}

@ConditionalOnWebApplication
@EnableSwagger2
public static class SwaggerConfig {

    @Bean
    public Docket springfoxDocket() {

        StringVendorExtension vendorExtension = new StringVendorExtension("x-wso2-security", Wso2Config.serialize());
        List<VendorExtension> vendorExtensions = new ArrayList<>();
        vendorExtensions.add(vendorExtension);

        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com"))
                .build()
                .protocols(protocolSet())
                .apiInfo(apiInfo())
                .extensions(vendorExtensions)
                .directModelSubstitute(LocalDateTime.class, Date.class)
                .useDefaultResponseMessages(false).enableUrlTemplating(false)
                ;
    }

    private ApiInfo apiInfo() {
        return new ApiInfo(
                "Event",
                "Creates, deletes, reads events",
                "2.0",
                "",
                null,
                null, null, Collections.emptyList());
    }

    private Set<String> protocolSet() {
        Set<String> protocolsSet = new HashSet<>();
        protocolsSet.add("http");
        protocolsSet.add("https");
        return protocolsSet;
    }

}
}

Upvotes: 0

Views: 1638

Answers (1)

Rahul B
Rahul B

Reputation: 132

Since you have jackson-dataformat-xml dependency spring boot will default the content type to application/xml. If you want application\jsonas content type then configure restTemplate to do so. Please follow the question Swagger 2 accept xml instead of json

Upvotes: 0

Related Questions