forked from loafle/openapi-generator-original
[Java][jersey2]Support enum discriminator value in child objects (#7267)
* support enum discriminator value in child (java jersey2) * update samples * add tests, use public
This commit is contained in:
@@ -2401,6 +2401,12 @@ components:
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
pet_type:
|
||||
default: ChildCat
|
||||
enum:
|
||||
- ChildCat
|
||||
type: string
|
||||
x-enum-as-string: true
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
|
||||
@@ -7,6 +7,15 @@
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**name** | **String** | | [optional]
|
||||
**petType** | [**String**](#String) | | [optional]
|
||||
|
||||
|
||||
|
||||
## Enum: String
|
||||
|
||||
Name | Value
|
||||
---- | -----
|
||||
CHILDCAT | "ChildCat"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,15 @@
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**name** | **String** | | [optional]
|
||||
**petType** | [**String**](#String) | | [optional]
|
||||
|
||||
|
||||
|
||||
## Enum: String
|
||||
|
||||
Name | Value
|
||||
---- | -----
|
||||
CHILDCAT | "ChildCat"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.openapitools.client.model.ChildCatAllOf;
|
||||
import org.openapitools.client.model.ParentPet;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import org.openapitools.client.JSON;
|
||||
|
||||
@@ -40,7 +42,8 @@ import org.openapitools.client.JSON;
|
||||
* ChildCat
|
||||
*/
|
||||
@JsonPropertyOrder({
|
||||
ChildCat.JSON_PROPERTY_NAME
|
||||
ChildCat.JSON_PROPERTY_NAME,
|
||||
ChildCat.JSON_PROPERTY_PET_TYPE
|
||||
})
|
||||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "pet_type", visible = true)
|
||||
@@ -49,6 +52,9 @@ public class ChildCat extends ParentPet {
|
||||
public static final String JSON_PROPERTY_NAME = "name";
|
||||
private String name;
|
||||
|
||||
public static final String JSON_PROPERTY_PET_TYPE = "pet_type";
|
||||
private String petType = "ChildCat";
|
||||
|
||||
|
||||
public ChildCat name(String name) {
|
||||
this.name = name;
|
||||
@@ -73,6 +79,42 @@ public class ChildCat extends ParentPet {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public static final Set<String> PET_TYPE_VALUES = new HashSet<>(Arrays.asList(
|
||||
"ChildCat"
|
||||
));
|
||||
|
||||
public ChildCat petType(String petType) {
|
||||
if (!PET_TYPE_VALUES.contains(petType)) {
|
||||
throw new IllegalArgumentException(petType + " is invalid. Possible values for petType: " + String.join(", ", PET_TYPE_VALUES));
|
||||
}
|
||||
|
||||
this.petType = petType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get petType
|
||||
* @return petType
|
||||
**/
|
||||
@javax.annotation.Nullable
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty(JSON_PROPERTY_PET_TYPE)
|
||||
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
|
||||
|
||||
public String getPetType() {
|
||||
return petType;
|
||||
}
|
||||
|
||||
|
||||
public void setPetType(String petType) {
|
||||
if (!PET_TYPE_VALUES.contains(petType)) {
|
||||
throw new IllegalArgumentException(petType + " is invalid. Possible values for petType: " + String.join(", ", PET_TYPE_VALUES));
|
||||
}
|
||||
|
||||
this.petType = petType;
|
||||
}
|
||||
|
||||
/**
|
||||
* A container for additional, undeclared properties.
|
||||
* This is a holder for any undeclared properties as specified with
|
||||
@@ -123,14 +165,15 @@ public class ChildCat extends ParentPet {
|
||||
return false;
|
||||
}
|
||||
ChildCat childCat = (ChildCat) o;
|
||||
return Objects.equals(this.name, childCat.name)&&
|
||||
return Objects.equals(this.name, childCat.name) &&
|
||||
Objects.equals(this.petType, childCat.petType)&&
|
||||
Objects.equals(this.additionalProperties, childCat.additionalProperties) &&
|
||||
super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, super.hashCode(), additionalProperties);
|
||||
return Objects.hash(name, petType, super.hashCode(), additionalProperties);
|
||||
}
|
||||
|
||||
|
||||
@@ -140,6 +183,7 @@ public class ChildCat extends ParentPet {
|
||||
sb.append("class ChildCat {\n");
|
||||
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
|
||||
sb.append(" name: ").append(toIndentedString(name)).append("\n");
|
||||
sb.append(" petType: ").append(toIndentedString(petType)).append("\n");
|
||||
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
|
||||
@@ -24,6 +24,8 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import org.openapitools.client.JSON;
|
||||
|
||||
@@ -32,13 +34,17 @@ import org.openapitools.client.JSON;
|
||||
* ChildCatAllOf
|
||||
*/
|
||||
@JsonPropertyOrder({
|
||||
ChildCatAllOf.JSON_PROPERTY_NAME
|
||||
ChildCatAllOf.JSON_PROPERTY_NAME,
|
||||
ChildCatAllOf.JSON_PROPERTY_PET_TYPE
|
||||
})
|
||||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
|
||||
public class ChildCatAllOf {
|
||||
public static final String JSON_PROPERTY_NAME = "name";
|
||||
private String name;
|
||||
|
||||
public static final String JSON_PROPERTY_PET_TYPE = "pet_type";
|
||||
private String petType = "ChildCat";
|
||||
|
||||
|
||||
public ChildCatAllOf name(String name) {
|
||||
this.name = name;
|
||||
@@ -64,6 +70,42 @@ public class ChildCatAllOf {
|
||||
}
|
||||
|
||||
|
||||
public static final Set<String> PET_TYPE_VALUES = new HashSet<>(Arrays.asList(
|
||||
"ChildCat"
|
||||
));
|
||||
|
||||
public ChildCatAllOf petType(String petType) {
|
||||
if (!PET_TYPE_VALUES.contains(petType)) {
|
||||
throw new IllegalArgumentException(petType + " is invalid. Possible values for petType: " + String.join(", ", PET_TYPE_VALUES));
|
||||
}
|
||||
|
||||
this.petType = petType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get petType
|
||||
* @return petType
|
||||
**/
|
||||
@javax.annotation.Nullable
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty(JSON_PROPERTY_PET_TYPE)
|
||||
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
|
||||
|
||||
public String getPetType() {
|
||||
return petType;
|
||||
}
|
||||
|
||||
|
||||
public void setPetType(String petType) {
|
||||
if (!PET_TYPE_VALUES.contains(petType)) {
|
||||
throw new IllegalArgumentException(petType + " is invalid. Possible values for petType: " + String.join(", ", PET_TYPE_VALUES));
|
||||
}
|
||||
|
||||
this.petType = petType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return true if this ChildCat_allOf object is equal to o.
|
||||
*/
|
||||
@@ -76,12 +118,13 @@ public class ChildCatAllOf {
|
||||
return false;
|
||||
}
|
||||
ChildCatAllOf childCatAllOf = (ChildCatAllOf) o;
|
||||
return Objects.equals(this.name, childCatAllOf.name);
|
||||
return Objects.equals(this.name, childCatAllOf.name) &&
|
||||
Objects.equals(this.petType, childCatAllOf.petType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name);
|
||||
return Objects.hash(name, petType);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +133,7 @@ public class ChildCatAllOf {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class ChildCatAllOf {\n");
|
||||
sb.append(" name: ").append(toIndentedString(name)).append("\n");
|
||||
sb.append(" petType: ").append(toIndentedString(petType)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -66,6 +66,18 @@ public class JSONComposedSchemaTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to ensure the setter will throw IllegalArgumentException
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEnumDiscriminator() throws Exception {
|
||||
ChildCat cc = new ChildCat();
|
||||
cc.setPetType("ChildCat");
|
||||
assertEquals("ChildCat", cc.getPetType());
|
||||
|
||||
cc.setPetType("WrongValue");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to ensure the getter will throw ClassCastException
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user