This is article 61 of the Stick to Technical Writing Project (including translation). Set a small goal of 999, at least 2 articles per week.

In this article, we will show you how to reverse engineer the SDK from the openAPi-like documentation provided by the three parties (without the hassle of knocking on each other) and generate poJOs that support Lombok

Lead to

  • Nodejs12 LTS+
  • Java8+
  • Git

Researched Swagger’s own github.com/swagger-api… Microsoft home github.com/Azure/autor… And openAPI’s github.com/OpenAPITool… Finally choose github.com/OpenAPITool…

The installationopenapi-generator

npm install @openapitools/openapi-generator-cli -g

git clone https://github.com/anjia0532/openapi-generator-templates

openapi-generator-cli generate -t openapi-generator-templates\generator-templates\JavaSpring\spring-boot-lombok-actuator -g spring -puseLombok=true -i swaggerApi.json --skip-validate-spec
Copy the code

Resources github.com/OpenAPITool… Resources github.com/anjia0532/o…

Generate results

SRC ├─ ├─ Java │ ├─ Java │ ├─ SRC │ ├─ Java │ ├─ Java │ ├─Call the client of the other API│ ├─ ├─ Java │ ├─ Configuration# config dependency│ ├─ Bass Exercises. Java │ ├─ Model# pojo class│ │ ├ ─ XXX. Java │ ├ ─ OpenAPI2SpringBoot. Java │ └ ─ RFC3339DateFormat. Java ├ ─ resources │ └ ─ application. The properties │ └ ─ RFC3339DateFormat. Java └ ─ pom. XMLCopy the code

Demonstrate the resulting effect with an unimportant Model class that is actually used

package org.openapitools.model;

import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.openapitools.jackson.nullable.JsonNullable;
import javax.validation.Valid;
import javax.validation.constraints.*;

import lombok.*;

/** * EmptyObject2 */
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "The 2021-04-09 T19: and. 687 + 08:00 Asia/Shanghai." ")
@Getter
@Setter
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class EmptyObject2   {
        /** ** access channels */
        @JsonProperty("getChannel")
        private String getChannel;

        /** * Coupon ID */
        @JsonProperty("couponIds")
        private String couponIds;

        /** * Member ID */
        @JsonProperty("memberId")
        private String memberId;

}
Copy the code

Want ads

Friends in Jinan, Shandong, welcome to join us and do things together. Long-term recruitment, Java programmer, big data engineer, operation and maintenance engineer, front-end engineer.

The resources