From 95fc78603c71b1450ecd784b71c79b4a0f4be9a7 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 21 Aug 2020 22:43:42 +0800 Subject: [PATCH 1/3] support enum discriminator value in child (java jersey2) --- .../codegen/languages/JavaClientCodegen.java | 25 ++++++++++ .../Java/libraries/jersey2/pojo.mustache | 20 ++++++++ ...odels-for-testing-with-http-signature.yaml | 6 +++ .../java/jersey2-java8/api/openapi.yaml | 6 +++ .../java/jersey2-java8/docs/ChildCat.md | 9 ++++ .../java/jersey2-java8/docs/ChildCatAllOf.md | 9 ++++ .../openapitools/client/model/ChildCat.java | 50 +++++++++++++++++-- .../client/model/ChildCatAllOf.java | 50 +++++++++++++++++-- 8 files changed, 169 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index 664a65ffb472..731803e7c0c2 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -784,7 +784,32 @@ public Map postProcessModels(Map objs) { // only add JsonNullable and related imports to optional and nullable values addImports |= isOptionalNullable; var.getVendorExtensions().put("x-is-jackson-optional-nullable", isOptionalNullable); + + if (Boolean.TRUE.equals(var.getVendorExtensions().get("x-enum-as-string"))) { + // treat enum string as just string + var.datatypeWithEnum = var.dataType; + + if (StringUtils.isNotEmpty(var.defaultValue)) { // has default value + String defaultValue = var.defaultValue.substring(var.defaultValue.lastIndexOf('.') + 1); + for (Map enumVars : (List>) var.getAllowableValues().get("enumVars")) { + if (defaultValue.equals(enumVars.get("name"))) { + // update default to use the string directly instead of enum string + var.defaultValue = (String) enumVars.get("value"); + } + } + } + + // add import for Set, HashSet + cm.imports.add("Set"); + Map importsSet = new HashMap(); + importsSet.put("import", "java.util.Set"); + imports.add(importsSet); + Map importsHashSet = new HashMap(); + importsHashSet.put("import", "java.util.HashSet"); + imports.add(importsHashSet); + } } + if (addImports) { Map imports2Classnames = new HashMap() {{ put("JsonNullable", "org.openapitools.jackson.nullable.JsonNullable"); diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache index a74a9d35f4a8..17a4f308f9f3 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache @@ -18,7 +18,9 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorE {{#vars}} {{#isEnum}} {{^isContainer}} + {{^vendorExtensions.x-enum-as-string}} {{>modelInnerEnum}} + {{/vendorExtensions.x-enum-as-string}} {{/isContainer}} {{#isContainer}} {{#mostInnerItems}} @@ -98,7 +100,19 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorE {{#vars}} {{^isReadOnly}} + {{#vendorExtensions.x-enum-as-string}} + private static final Set {{{nameInSnakeCase}}}_VALUES = new HashSet<>(Arrays.asList( + {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}} + )); + + {{/vendorExtensions.x-enum-as-string}} public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) { + {{#vendorExtensions.x-enum-as-string}} + if (!{{{nameInSnakeCase}}}_VALUES.contains({{name}})) { + throw new IllegalArgumentException({{name}} + " is invalid. Possible values for {{name}}: " + String.join(", ", {{{nameInSnakeCase}}}_VALUES)); + } + + {{/vendorExtensions.x-enum-as-string}} {{#vendorExtensions.x-is-jackson-optional-nullable}} this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{name}}); {{/vendorExtensions.x-is-jackson-optional-nullable}} @@ -220,6 +234,12 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorE {{^isReadOnly}} public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { + {{#vendorExtensions.x-enum-as-string}} + if (!{{{nameInSnakeCase}}}_VALUES.contains({{name}})) { + throw new IllegalArgumentException({{name}} + " is invalid. Possible values for {{name}}: " + String.join(", ", {{{nameInSnakeCase}}}_VALUES)); + } + + {{/vendorExtensions.x-enum-as-string}} {{#vendorExtensions.x-is-jackson-optional-nullable}} this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{name}}); {{/vendorExtensions.x-is-jackson-optional-nullable}} diff --git a/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index a0f064611b15..b16f87513080 100644 --- a/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -2087,6 +2087,12 @@ components: properties: name: type: string + pet_type: + x-enum-as-string: true + type: string + enum: + - ChildCat + default: ChildCat ArrayOfEnums: type: array items: diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/api/openapi.yaml b/samples/openapi3/client/petstore/java/jersey2-java8/api/openapi.yaml index e09549a0c3d6..f22df8f6bbdf 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/api/openapi.yaml +++ b/samples/openapi3/client/petstore/java/jersey2-java8/api/openapi.yaml @@ -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: diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/docs/ChildCat.md b/samples/openapi3/client/petstore/java/jersey2-java8/docs/ChildCat.md index e6548f036ffb..0715369e4e96 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/docs/ChildCat.md +++ b/samples/openapi3/client/petstore/java/jersey2-java8/docs/ChildCat.md @@ -7,6 +7,15 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **name** | **String** | | [optional] +**petType** | [**String**](#String) | | [optional] + + + +## Enum: String + +Name | Value +---- | ----- +CHILDCAT | "ChildCat" diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/docs/ChildCatAllOf.md b/samples/openapi3/client/petstore/java/jersey2-java8/docs/ChildCatAllOf.md index abd7adedbcc5..f4c3ece5de95 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/docs/ChildCatAllOf.md +++ b/samples/openapi3/client/petstore/java/jersey2-java8/docs/ChildCatAllOf.md @@ -7,6 +7,15 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **name** | **String** | | [optional] +**petType** | [**String**](#String) | | [optional] + + + +## Enum: String + +Name | Value +---- | ----- +CHILDCAT | "ChildCat" diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCat.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCat.java index e96b56a28479..f829e312509c 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCat.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCat.java @@ -32,6 +32,8 @@ 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 @@ * 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 void setName(String name) { this.name = name; } + + private static final Set 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 boolean equals(java.lang.Object o) { 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 String toString() { 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(); diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCatAllOf.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCatAllOf.java index 8ad157bf8d82..bf12db7b7328 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCatAllOf.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCatAllOf.java @@ -24,6 +24,8 @@ 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 @@ * 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 void setName(String name) { } + private static final Set 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 boolean equals(java.lang.Object o) { 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 String toString() { 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(); } From 892eedb37b7454f7815b7927a9601f07cef529b7 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 21 Aug 2020 23:38:12 +0800 Subject: [PATCH 2/3] update samples --- .../OpenAPIClientCore/docs/ChildCat.md | 1 + .../OpenAPIClientCore/docs/ChildCatAllOf.md | 1 + .../src/Org.OpenAPITools/Model/ChildCat.cs | 26 +++++++++++++++++-- .../Org.OpenAPITools/Model/ChildCatAllOf.cs | 25 +++++++++++++++++- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/docs/ChildCat.md b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/docs/ChildCat.md index 3942b9d1b9ca..02a1c823c5a7 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/docs/ChildCat.md +++ b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/docs/ChildCat.md @@ -4,6 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **Name** | **string** | | [optional] +**PetType** | **string** | | [optional] [default to PetTypeEnum.ChildCat] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/docs/ChildCatAllOf.md b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/docs/ChildCatAllOf.md index b016be9f69e0..18044560aa87 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/docs/ChildCatAllOf.md +++ b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/docs/ChildCatAllOf.md @@ -4,6 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **Name** | **string** | | [optional] +**PetType** | **string** | | [optional] [default to PetTypeEnum.ChildCat] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/ChildCat.cs b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/ChildCat.cs index fa978d1760b7..55789e18cbbb 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/ChildCat.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/ChildCat.cs @@ -31,6 +31,25 @@ namespace Org.OpenAPITools.Model [DataContract(Name = "ChildCat")] public partial class ChildCat : ParentPet, IEquatable, IValidatableObject { + /// + /// Defines PetType + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum PetTypeEnum + { + /// + /// Enum ChildCat for value: ChildCat + /// + [EnumMember(Value = "ChildCat")] + ChildCat = 1 + + } + + /// + /// Gets or Sets PetType + /// + [DataMember(Name = "pet_type", EmitDefaultValue = false)] + public PetTypeEnum? PetType { get; set; } /// /// Initializes a new instance of the class. /// @@ -40,10 +59,11 @@ protected ChildCat() { } /// Initializes a new instance of the class. /// /// name. - /// petType (required). - public ChildCat(string name = default(string), string petType = default(string)) : base() + /// petType (default to PetTypeEnum.ChildCat). + public ChildCat(string name = default(string), PetTypeEnum? petType = PetTypeEnum.ChildCat) : base() { this.Name = name; + this.PetType = petType; } /// @@ -62,6 +82,7 @@ public override string ToString() sb.Append("class ChildCat {\n"); sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n"); sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" PetType: ").Append(PetType).Append("\n"); sb.Append("}\n"); return sb.ToString(); } @@ -106,6 +127,7 @@ public override int GetHashCode() int hashCode = base.GetHashCode(); if (this.Name != null) hashCode = hashCode * 59 + this.Name.GetHashCode(); + hashCode = hashCode * 59 + this.PetType.GetHashCode(); return hashCode; } } diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/ChildCatAllOf.cs b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/ChildCatAllOf.cs index 05147447b0e4..3214fb19a636 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/ChildCatAllOf.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/ChildCatAllOf.cs @@ -31,13 +31,34 @@ namespace Org.OpenAPITools.Model [DataContract(Name = "ChildCat_allOf")] public partial class ChildCatAllOf : IEquatable, IValidatableObject { + /// + /// Defines PetType + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum PetTypeEnum + { + /// + /// Enum ChildCat for value: ChildCat + /// + [EnumMember(Value = "ChildCat")] + ChildCat = 1 + + } + + /// + /// Gets or Sets PetType + /// + [DataMember(Name = "pet_type", EmitDefaultValue = false)] + public PetTypeEnum? PetType { get; set; } /// /// Initializes a new instance of the class. /// /// name. - public ChildCatAllOf(string name = default(string)) + /// petType (default to PetTypeEnum.ChildCat). + public ChildCatAllOf(string name = default(string), PetTypeEnum? petType = PetTypeEnum.ChildCat) { this.Name = name; + this.PetType = petType; } /// @@ -55,6 +76,7 @@ public override string ToString() var sb = new StringBuilder(); sb.Append("class ChildCatAllOf {\n"); sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" PetType: ").Append(PetType).Append("\n"); sb.Append("}\n"); return sb.ToString(); } @@ -99,6 +121,7 @@ public override int GetHashCode() int hashCode = 41; if (this.Name != null) hashCode = hashCode * 59 + this.Name.GetHashCode(); + hashCode = hashCode * 59 + this.PetType.GetHashCode(); return hashCode; } } From 1b9dedcc73529b046e9946c280a79ead041ba5ab Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 24 Aug 2020 21:08:37 +0800 Subject: [PATCH 3/3] add tests, use public --- .../resources/Java/libraries/jersey2/pojo.mustache | 2 +- .../java/org/openapitools/client/model/ChildCat.java | 2 +- .../org/openapitools/client/model/ChildCatAllOf.java | 2 +- .../openapitools/client/JSONComposedSchemaTest.java | 12 ++++++++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache index 17a4f308f9f3..6c8ff2cebe8f 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache @@ -101,7 +101,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorE {{^isReadOnly}} {{#vendorExtensions.x-enum-as-string}} - private static final Set {{{nameInSnakeCase}}}_VALUES = new HashSet<>(Arrays.asList( + public static final Set {{{nameInSnakeCase}}}_VALUES = new HashSet<>(Arrays.asList( {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}} )); diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCat.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCat.java index f829e312509c..5c827b913936 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCat.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCat.java @@ -80,7 +80,7 @@ public void setName(String name) { } - private static final Set PET_TYPE_VALUES = new HashSet<>(Arrays.asList( + public static final Set PET_TYPE_VALUES = new HashSet<>(Arrays.asList( "ChildCat" )); diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCatAllOf.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCatAllOf.java index bf12db7b7328..4df3dda94f59 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCatAllOf.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ChildCatAllOf.java @@ -70,7 +70,7 @@ public void setName(String name) { } - private static final Set PET_TYPE_VALUES = new HashSet<>(Arrays.asList( + public static final Set PET_TYPE_VALUES = new HashSet<>(Arrays.asList( "ChildCat" )); diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/test/java/org/openapitools/client/JSONComposedSchemaTest.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/test/java/org/openapitools/client/JSONComposedSchemaTest.java index 1f78f71db78c..3013a0bf533f 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/test/java/org/openapitools/client/JSONComposedSchemaTest.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/test/java/org/openapitools/client/JSONComposedSchemaTest.java @@ -66,6 +66,18 @@ public void testOneOfSchemaAdditionalProperties() throws Exception { } } + /** + * 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 */