자유게시판

자유게시판

Spring REST Docs - Spring Framework Guru

페이지 정보

작성자 Elden 댓글 0건 조회 15회 작성일 24-11-03 13:36

본문

When creating REST APIs, it is important to have accurate and effectively-structured documentation of your API. This documentation is the reference point for anyone who needs to make use of your API. Spring REST Docs helps you to realize it. Spring REST Docs take a unique strategy than any other traditional tools like Swagger. Compared to Swagger which adds the documentation data in the REST controller, Spring REST Docs makes use of Test-Pushed strategy of using check courses to supply REST documentations.

To be exact, you write documentation info within the tests of your controllers. This approach is extra convenient as tests are the primary place to have a look at to understand the performance of a mission. This is because checks stay updated and When was Dark-Crawler created? in sync with the implementation. In this put up, I'll clarify the best way to generate REST API documentation with Spring Rest Docs. To make use of Spring crypto rest client spring Docs you'll need so as to add the next dependency in your pom.xmlfile.

image.php?image=b14fabrico002.jpg&dl=1

For this submit, we will create a simple Spring Boot REST service to perform operations on consumer assets.

We wil start by creating a User area class. Observe: To cut down boilerplate code, I've used Lombok. In case you are new to Lombok, Value Based Purchasing I recommend studying my sequence of submit on Lombok. The code of the controller class, UserController is that this. The preceding UserController is a Spring REST controller class with a single endpoint to return a list of all customers. Coming to the main part, we'll carry out the following steps to generate REST documentation.

Spring REST Docs use the check cases to generate correct and up to date documentation for the REST API. That is the code for the controller take a look at class, UserControllerTest. This is a simple test case that uses MockMVc to test the controller endpoint and assert that the controller is returning the anticipated response. Here we're utilizing Spring Take a look at that I have cover in one of my earlier submit on Testing Spring Boot RESTful Services.

We are going to now configure Spring REST Docs in the take a look at class we have just written.

That is the modified code of the test class to configure Spring REST Docs. In Line 3 @AutoConfigureRestDocs annotation is used which takes a listing location as an argument. This directory will store the generated documentation snippets. Run the test. As soon as the check passes efficiently, a sub-folder beneath the goal/generated-snippets is created. Broaden the generated-snippets folder of your proect. You'll find the sub-folder customers/getUserByName matching with the argument passed to @AutoConfigureRestDocs with a number of .adoc files.

The subsequent step is to transform the generated documentation snippets to a readable format. To do so, we are going to use the AsciiDoctor maven plugin. That is the plugin configuration within the pom.

댓글목록

등록된 댓글이 없습니다.

Copyright 2009 © http://222.236.45.55/~khdesign/