r/SpringBoot • • 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

17 comments sorted by

View all comments

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)

2

u/No-Philosophy-1189 Sep 09 '24

Wouldn't that add more confusion? Which controller would the request reach. The one we created or the one spring created? If we have to make changes in the controller, do we have to make changes in bothe files?

1

u/asarathy Sep 09 '24

You generate interfaces. Then when the yml changes you need to fix the implementation to deal with those changes.