Swagger UI Error validation when deployed a spring boot application

旧时模样 提交于 2019-12-11 07:27:42

问题


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 ?


回答1:


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




回答2:


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

`@Bean
 public UiConfiguration getConfig(){
        String validatorUrl = "validatorUrl";
        return new UiConfiguration(validatorUrl);
    }`


来源:https://stackoverflow.com/questions/47340976/swagger-ui-error-validation-when-deployed-a-spring-boot-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!