Saurabh Kohade
Saurabh Kohade

Reputation: 55

Can we Document Model/entity with using Spring rest docs

Writing all fields with the snippets description is not reliable solution is there any way to implement Model/Entity as a table with the fields and description, constraints, Type seprately.


fieldWithPath("id").description("Id of Student."),
               fieldWithPath("name").description("Name of the Student."),
               fieldWithPath("contact").description("Contact of the Student."),
               fieldWithPath("marks").description("Marks of the Student."));

Upvotes: 0

Views: 279

Answers (1)

Andy Wilkinson
Andy Wilkinson

Reputation: 116091

Documenting an entity directly is exactly what Spring REST Docs is designed to avoid. If that's the approach that you want to take then Spring REST Docs isn't the right tool for the job.

Spring REST Docs is built around the belief that, when documenting a REST API, it's the HTTP requests and responses that should be used to generate that documentation. This ensures that the documentation accurately describes the requests that the service expects to receive and the responses that it will send.

If you try to use an entity to document your API, you are ignoring the transformations that could be applied to that entity when serialising it to JSON. This can result in documentation that's inaccurate as serialization may omit some of an entity's properties, change the name of some of those properties, or even change the structure entirely.

Upvotes: 0

Related Questions