r/SpringBoot • u/BluePillOverRedPill • Sep 09 '24
Too many annotations Swagger
I'm working on a Spring Boot project and using Swagger for API documentation. For my DTOs, I've been adding a lot of @Schema annotations to define the API schema properly, but it feels like it's really polluting my code and making the DTOs harder to read.
Is this a common issue, or am I overusing annotations? Are there better practices for integrating Swagger without cluttering the code too much? Any suggestions or alternatives would be appreciated!
25
Upvotes
14
u/mehmetozanguven Sep 09 '24
You can write your swagger documentation directly into the .yml file. Then frontend and your spring boot application can generate client and controllers using the yml file.(Contract based development)
But in this way you will duplicate your current response classes and controllers. (I think, it is worth it)