Swagger UI Error validation when deployed a spring

2019-07-26 15:59发布

Swagger-ui.html shows a error at the bottom of the page due to validation

`{"schemaValidationMessages":[{"level":"error","message":"Can't read from file https://www.example.com/v2/api-docs"}]}`

I did some research on it and came to know that we need to turn off the validations to remove the error. but how to turn it off from spring boot application.? or is there any way to edit the swagger-ui.html in a spring boot app ?

error as shown in picture

2条回答
乱世女痞
2楼-- · 2019-07-26 16:17

Since Swagger 2.8.0 many constructors have been deprecated. I think it's better to use the corresponding builder which takes care of all the undefined parameters for us like this:

@Bean
public UiConfiguration uiConfig()
{
    return UiConfigurationBuilder.builder() //
             .displayRequestDuration( true ) //
             .validatorUrl( StringUtils.EMPTY ) // Disable the validator to avoid "Error" at the bottom of the Swagger UI page
             .build();
}

See also this post regarding null or empty string validator

查看更多
疯言疯语
3楼-- · 2019-07-26 16:23

I solved it by disabling the validation by adding the following code

`@Bean
 public UiConfiguration getConfig(){
        String validatorUrl = "validatorUrl";
        return new UiConfiguration(validatorUrl);
    }`
查看更多
登录 后发表回答