Better inline model resolver to handle inline schema in array item (#12104)

* better support of inline schema in array item

* update tests

* update samples

* regenerate samples

* fix allof naming, remove files

* add files

* update samples

* update readme

* fix tests

* update samples

* update samples

* add new files

* update test spec

* add back tests

* remove unused files

* comment out python test

* update js test using own spec

* remove files

* remove unused files

* remove files

* remove unused files

* better handling of allOf with a single type

* comment out go test

* remove test_all_of_with_single_ref_single_ref_type.py

* fix inline resolver, uncomment go test
This commit is contained in:
William Cheng
2022-04-20 10:28:15 +08:00
committed by GitHub
parent 12454de3ac
commit 8330e16d66
200 changed files with 7495 additions and 975 deletions

View File

@@ -0,0 +1,164 @@
/*
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.model;
import java.util.Objects;
import java.util.Arrays;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.openapitools.client.model.SingleRefType;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* AllOfWithSingleRef
*/
@JsonPropertyOrder({
AllOfWithSingleRef.JSON_PROPERTY_USERNAME,
AllOfWithSingleRef.JSON_PROPERTY_SINGLE_REF_TYPE
})
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class AllOfWithSingleRef {
public static final String JSON_PROPERTY_USERNAME = "username";
private String username;
public static final String JSON_PROPERTY_SINGLE_REF_TYPE = "SingleRefType";
private JsonNullable<SingleRefType> singleRefType = JsonNullable.<SingleRefType>undefined();
public AllOfWithSingleRef() {
}
public AllOfWithSingleRef username(String username) {
this.username = username;
return this;
}
/**
* Get username
* @return username
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")
@JsonProperty(JSON_PROPERTY_USERNAME)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public String getUsername() {
return username;
}
@JsonProperty(JSON_PROPERTY_USERNAME)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setUsername(String username) {
this.username = username;
}
public AllOfWithSingleRef singleRefType(SingleRefType singleRefType) {
this.singleRefType = JsonNullable.<SingleRefType>of(singleRefType);
return this;
}
/**
* Get singleRefType
* @return singleRefType
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")
@JsonIgnore
public SingleRefType getSingleRefType() {
return singleRefType.orElse(null);
}
@JsonProperty(JSON_PROPERTY_SINGLE_REF_TYPE)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public JsonNullable<SingleRefType> getSingleRefType_JsonNullable() {
return singleRefType;
}
@JsonProperty(JSON_PROPERTY_SINGLE_REF_TYPE)
public void setSingleRefType_JsonNullable(JsonNullable<SingleRefType> singleRefType) {
this.singleRefType = singleRefType;
}
public void setSingleRefType(SingleRefType singleRefType) {
this.singleRefType = JsonNullable.<SingleRefType>of(singleRefType);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AllOfWithSingleRef allOfWithSingleRef = (AllOfWithSingleRef) o;
return Objects.equals(this.username, allOfWithSingleRef.username) &&
equalsNullable(this.singleRefType, allOfWithSingleRef.singleRefType);
}
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
}
@Override
public int hashCode() {
return Objects.hash(username, hashCodeNullable(singleRefType));
}
private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class AllOfWithSingleRef {\n");
sb.append(" username: ").append(toIndentedString(username)).append("\n");
sb.append(" singleRefType: ").append(toIndentedString(singleRefType)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}

View File

@@ -22,9 +22,9 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
/**
* Gets or Sets UserType
* Gets or Sets SingleRefType
*/
public enum UserType {
public enum SingleRefType {
ADMIN("admin"),
@@ -32,7 +32,7 @@ public enum UserType {
private String value;
UserType(String value) {
SingleRefType(String value) {
this.value = value;
}
@@ -47,8 +47,8 @@ public enum UserType {
}
@JsonCreator
public static UserType fromValue(String value) {
for (UserType b : UserType.values()) {
public static SingleRefType fromValue(String value) {
for (SingleRefType b : SingleRefType.values()) {
if (b.value.equals(value)) {
return b;
}

View File

@@ -22,11 +22,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.openapitools.client.model.UserType;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;
@@ -41,8 +36,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
User.JSON_PROPERTY_EMAIL,
User.JSON_PROPERTY_PASSWORD,
User.JSON_PROPERTY_PHONE,
User.JSON_PROPERTY_USER_STATUS,
User.JSON_PROPERTY_USER_TYPE
User.JSON_PROPERTY_USER_STATUS
})
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class User {
@@ -70,9 +64,6 @@ public class User {
public static final String JSON_PROPERTY_USER_STATUS = "userStatus";
private Integer userStatus;
public static final String JSON_PROPERTY_USER_TYPE = "userType";
private JsonNullable<UserType> userType = JsonNullable.<UserType>undefined();
public User() {
}
@@ -292,41 +283,6 @@ public class User {
}
public User userType(UserType userType) {
this.userType = JsonNullable.<UserType>of(userType);
return this;
}
/**
* Get userType
* @return userType
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")
@JsonIgnore
public UserType getUserType() {
return userType.orElse(null);
}
@JsonProperty(JSON_PROPERTY_USER_TYPE)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public JsonNullable<UserType> getUserType_JsonNullable() {
return userType;
}
@JsonProperty(JSON_PROPERTY_USER_TYPE)
public void setUserType_JsonNullable(JsonNullable<UserType> userType) {
this.userType = userType;
}
public void setUserType(UserType userType) {
this.userType = JsonNullable.<UserType>of(userType);
}
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -343,24 +299,12 @@ public class User {
Objects.equals(this.email, user.email) &&
Objects.equals(this.password, user.password) &&
Objects.equals(this.phone, user.phone) &&
Objects.equals(this.userStatus, user.userStatus) &&
equalsNullable(this.userType, user.userType);
}
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
Objects.equals(this.userStatus, user.userStatus);
}
@Override
public int hashCode() {
return Objects.hash(id, username, firstName, lastName, email, password, phone, userStatus, hashCodeNullable(userType));
}
private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
return Objects.hash(id, username, firstName, lastName, email, password, phone, userStatus);
}
@Override
@@ -375,7 +319,6 @@ public class User {
sb.append(" password: ").append(toIndentedString(password)).append("\n");
sb.append(" phone: ").append(toIndentedString(phone)).append("\n");
sb.append(" userStatus: ").append(toIndentedString(userStatus)).append("\n");
sb.append(" userType: ").append(toIndentedString(userType)).append("\n");
sb.append("}");
return sb.toString();
}

View File

@@ -0,0 +1,63 @@
/*
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.openapitools.client.model.SingleRefType;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
/**
* Model tests for AllOfWithSingleRef
*/
public class AllOfWithSingleRefTest {
private final AllOfWithSingleRef model = new AllOfWithSingleRef();
/**
* Model tests for AllOfWithSingleRef
*/
@Test
public void testAllOfWithSingleRef() {
// TODO: test AllOfWithSingleRef
}
/**
* Test the property 'username'
*/
@Test
public void usernameTest() {
// TODO: test username
}
/**
* Test the property 'singleRefType'
*/
@Test
public void singleRefTypeTest() {
// TODO: test singleRefType
}
}

View File

@@ -19,15 +19,15 @@ import org.junit.Test;
/**
* Model tests for UserType
* Model tests for SingleRefType
*/
public class UserTypeTest {
public class SingleRefTypeTest {
/**
* Model tests for UserType
* Model tests for SingleRefType
*/
@Test
public void testUserType() {
// TODO: test UserType
public void testSingleRefType() {
// TODO: test SingleRefType
}
}