当前位置: 首页 > 知识库问答 >
问题:

Swagger UI+Spring Boot中不想要的Paramters

阚正真
2023-03-14

我看到很多不想要的字段显示在一个spring boot应用程序的昂首阔步ui中。

我傲慢的依赖是

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.9.2</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.9.2</version>

我的Rest控制器代码如下所示

    @ApiOperation(value = "Get Data")
    @GetMapping(value = "/applicant", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> getApplicant(@Valid  ApplicantRequestBean 
    applicantRequestBean, Errors errors) throws APIValidationException {
     if (errors.hasErrors()) {
     //check for constraintsviolation here and throw an error if found
     throw new APIValidationException(HttpStatus.BAD_REQUEST, "Bad Request", errorWrapper);
     }

}
    @NotBlank(message = "Id is mandatory")
    @Size(min = 9, max = 9, message = "Id should be 9 characters long")
    @ApiModelProperty(example = "@12345678", value = "Applicant Id", position = 3)
    private String id=null;
    @NotBlank(message = "Date of Birth is mandatory")
    @ApiModelProperty(example = "30-12-2000", value = "Applicant Date of Birth in DD-MM-YYYY format",  position = 2)
    private String dateOfBirth=null;
    @Email
    @ApiModelProperty(example = "id@domain.com", value = "Applicant Email Id", position = 1)
    private String emailId=null;
    @ApiModelProperty(example = "971505504XXX", value = "Applicant Contact Number", position = 0)
    private String contactNumber=null;
private HttpStatus status;
private String message;
private Object errors;
 @ExceptionHandler(APIValidationException.class)
    public final ResponseEntity<Object> handleAPIValidationExceptions(APIValidationException ex, WebRequest request) {
        ErrorResponse error = new ErrorResponse("error", ex.getMessage(), ex.getErrors());
        return new ResponseEntity(error, HttpStatus.BAD_REQUEST);
    }
public Docket swaggerConfiguration() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName(swaggerGroupName)
                .select()
                .paths(PathSelectors.ant("/api/**"))
                .apis(RequestHandlerSelectors.basePackage("a.b.c.d"))
                .build()
                .apiInfo(apiInfo())
                .tags(new Tag("Applicant", "Applicant APIs"));
    }

共有1个答案

卢志业
2023-03-14

我需要错误,但解决它的方法是通过添加

.IgnoredParameterTypes(errors.class)到Swagger配置

和@apiparam(hidden=true)在RestController中的错误参数之前

 类似资料:
  • SwaggerUI 汉化版;修改了部分样式;结合SpringFox SpringFox-Swagger-UI实现API管理

  • 问题内容: 在我的一个类中,一种方法执行AJAX请求。在请求的回调函数中,我需要使用调用对象的另一个方法。但是在这种情况下并没有引用我的对象,所以我不知道该怎么做。 为了澄清,请考虑以下代码: 问题答案: 您可以定义一个变量存储在闭包中: 或使用$ .proxy: 或者,如果您不做任何事情,只需要调用回调: 在现代浏览器中,您也可以使用bind。当我不必与IE8兼容时,我可以

  • 我想在Rest API(spring-mvc)文档中使用Springfox SwaggerUI。我在@RequestMapping注释中使用版本头,但是如果我有相同方法的两个版本,在SwaggerUI中只能看到一个。 上面的代码导致api文档中只有一个可见的方法。 考虑到我的版本头,是否有任何选项可以将Swagger配置为不同的endpoint?

  • 以下是代码: 如果我输入999999999,它会调用自己,但在第四行它不会再要求输入。调试器不能给出更多的信息,因为这是一个更具体的语言问题。提前感谢。祝您愉快!是的,目标是将输入解析为短输入。我知道从最小负值中丢失1,wip:) ==编辑=== 我试过goto...不,是一样的。所以我想这与可见变量或地址无关。 ==编辑=== 我不能用操作员

  • 我搜索了很多stackoverflow,但没有找到解决问题的方法。当将SpringBoot应用程序作为WAR文件部署到Tomcat 8时,我发现以下错误,在本地它确实可以正常工作 有一个接口 和两个实现类 和二等舱 还有Rest服务 所以我不明白Tomcat怎么找不到像boolean这样的原始数据类型,也不明白为什么我在本地运行它时它能工作。 任何帮助都将不胜感激 问候马蒂亚斯

  • 已删除MyTestConfig.class,但问题仍然相同。即使我使用@SpringBootTest(classes={Application.Class,MyProblematicServiceImpl.Class}),它仍然在自动连线的地方返回模拟对象。MyProblematicServiceImpl是用@Service注释的空类。