而不是使用
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate
-i http://petstore.swagger.io/v2/swagger.json
-l java
-o samples/client/petstore/java
你可以一起工作
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate
-i http://petstore.swagger.io/v2/swagger.json
-l spring
-o samples/client/petstore/java
通过语言更改,他们还将 gson 换成了 Jackson。
在你的情况下,你会有类似的东西
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.model.Category;
import io.swagger.model.Tag;
import java.util.ArrayList;
import java.util.List;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import javax.validation.constraints.*;
/**
* Pet
*/
@Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2020-06-04T13:33:18.844+02:00")
public class Pet {
@JsonProperty("id")
private Long id = null;
@JsonProperty("category")
private Category category = null;
@JsonProperty("name")
private String name = null;
@JsonProperty("photoUrls")
@Valid
private List<String> photoUrls = new ArrayList<String>();
@JsonProperty("tags")
@Valid
private List<Tag> tags = null;
...
来源:https ://github.com/swagger-api/swagger-codegen/issues/5785
当您使用 Generator.Swagger ( https://generator.swagger.io/在线 swagger Codegen api:/gen/clients/{language}) 构建客户端时,您可以查看 /gen/clients/{language } 或https://openapi-generator.tech/docs/generators/java/并构建您的请求。