less than 1 minute read

Introduction

Today, I continued working on the backend integration process by adding input validation annotations and API documentations

Development Notes

Input Validation

First of all, I added a spring-boot-starter-validation dependency to the pom.xml file

Screenshot 2025-05-25 at 6 24 12 PM

Then, I updated the ClassificationRequest class with valid annotations by using @NotBlank for required fields (e.g. systemName and systemPurpose) and @Size to validate requests

Screenshot 2025-05-25 at 6 27 39 PM Screenshot 2025-05-25 at 6 27 51 PM

I also modified the controller to use @Valid annotation and added an exception handler that returns HTTP 400 for bad requests and error messages

Screenshot 2025-05-25 at 6 30 39 PM

API Documentation

First, I added a springdoc-openapi-starter-webmvc-ui dependency to the pom.xml file

Screenshot 2025-05-25 at 6 34 34 PM

Added documentation to the controller by using @Tag for API grouping, @Operation for endpoint description, and @ApiResponses for possible responses

Screenshot 2025-05-25 at 6 40 55 PM

Added documentation to the request and response classes by using @Schema to enhance documentation for API and Swagger UI (I also added examples for better understanding

Screenshot 2025-05-25 at 6 48 11 PM

Now I can run Swagger UI on http://localhost:8080/swagger-ui.html, and everything seems to work properly (the correct endpoints are visible)

Screenshot 2025-05-25 at 6 53 45 PM