/easy-restdocs-generator

Generator to support Spring REST docs

Primary LanguageJavaApache License 2.0Apache-2.0

Easy Spring Rest-docs Generator

Maven Central GitHub license

This is a generator that suggest easier way to use rest-docs.

Install

  • JDK 17 or higher is required
  • Spring Boot 3.X is required

Gradle

testImplementation("io.github.hejow:easy-restdocs-generator:0.0.8")

Maven

<dependency>
    <groupId>io.github.hejow</groupId>
    <artifactId>easy-restdocs-generator</artifactId>
    <version>0.0.8</version>
    <scope>test</scope>
</dependency>

How to use

Only you have to do is Customize tags and Use builder.

Customize tags

To specify your api, easy-restdoc use ApiTag to generate documents.

// example
public enum MyTag implements ApiTag {
  USER("user api");

  private final String content;  

  // ... constructor

  @Override
  public String getName() {
    return this.content;
  }
}

Use builder

After test with mockMvc just use builder to generate as like below.

Planning to support RestAssured.

💡 Tips

To generate documents you MUST put tag, result on Builder.

If you don’t put identifier on Builder, Method name of the test you wrote will be used as identifier

Tests MUST run with rest-docs settings such as @ExtendWith(RestDocumentationExtension.class) (see here)

// example
@Test
void myTest() throws Exception {
  // given
  
  // when
  var result = mockMvc.perform(...);

  // then
  result.andExpectAll(
    status().isOk(),
    ...
  );

  // docs
  result.andDo(
    RestDocument.builder()
      .identifier("identifier of your API") // Can skip
      .tag(MyTag.USER) // Custom tags
      .summary("this will be name of API")
      .description("write description about your API")
      .result(result) // Test result
      .generateDocs()
  );
}