diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java index e5fe46954bf..c3cf38349bb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java @@ -148,8 +148,9 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti public boolean isAnyType; public boolean isArray; public boolean isMap; - public boolean isEnum; + public boolean isEnum; // true if the enum is defined inline public boolean isInnerEnum; // Enums declared inline will be located inside the generic model, changing how the enum is referenced in some cases. + public boolean isEnumRef; // true if it's a reference to an enum public boolean isReadOnly; public boolean isWriteOnly; public boolean isNullable; @@ -225,10 +226,14 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti } @Override - public void setFormat(String format) { this.format = format; } + public void setFormat(String format) { + this.format = format; + } @Override - public String getFormat() { return format; } + public String getFormat() { + return format; + } @Override public boolean getIsBooleanSchemaTrue() { @@ -500,7 +505,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti return required; } - public boolean compulsory(){ + public boolean compulsory() { return getRequired() && !isNullable; } @@ -963,15 +968,32 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti this.hasMultipleTypes = hasMultipleTypes; } - public boolean getIsUuid() { return isUuid; } + public boolean getIsUuid() { + return isUuid; + } - public void setIsUuid(boolean isUuid) { this.isUuid = isUuid; } + public void setIsUuid(boolean isUuid) { + this.isUuid = isUuid; + } @Override - public Map getRequiredVarsMap() { return requiredVarsMap; } + public Map getRequiredVarsMap() { + return requiredVarsMap; + } @Override - public void setRequiredVarsMap(Map requiredVarsMap) { this.requiredVarsMap=requiredVarsMap; } + public void setRequiredVarsMap(Map requiredVarsMap) { + this.requiredVarsMap = requiredVarsMap; + } + + /** + * Return true if it's an enum (inline or ref) + * + * @return true if it's an enum (inline or ref) + */ + public boolean getIsEnumOrRef() { + return isEnum || isEnumRef; + } @Override public String toString() { @@ -1033,6 +1055,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti sb.append(", isMap=").append(isMap); sb.append(", isEnum=").append(isEnum); sb.append(", isInnerEnum=").append(isInnerEnum); + sb.append(", isEnumRef=").append(isEnumRef); sb.append(", isAnyType=").append(isAnyType); sb.append(", isReadOnly=").append(isReadOnly); sb.append(", isWriteOnly=").append(isWriteOnly); @@ -1122,6 +1145,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti isMap == that.isMap && isEnum == that.isEnum && isInnerEnum == that.isInnerEnum && + isEnumRef == that.isEnumRef && isAnyType == that.isAnyType && isReadOnly == that.isReadOnly && isWriteOnly == that.isWriteOnly && @@ -1205,7 +1229,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti hasMoreNonReadOnly, isPrimitiveType, isModel, isContainer, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isFile, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isFreeFormObject, - isArray, isMap, isEnum, isInnerEnum, isAnyType, isReadOnly, isWriteOnly, isNullable, isShort, + isArray, isMap, isEnum, isInnerEnum, isEnumRef, isAnyType, isReadOnly, isWriteOnly, isNullable, isShort, isUnboundedInteger, isSelfReference, isCircularReference, isDiscriminator, _enum, allowableValues, items, mostInnerItems, additionalProperties, vars, requiredVars, vendorExtensions, hasValidation, isInherited, discriminatorValue, nameInCamelCase, diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 63efb10c2d6..e6f0dd8d22e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -3798,6 +3798,8 @@ public class DefaultCodegen implements CodegenConfig { if (referencedSchema.getEnum() != null && !referencedSchema.getEnum().isEmpty()) { List _enum = referencedSchema.getEnum(); + property.isEnumRef = true; + Map allowableValues = new HashMap<>(); allowableValues.put("values", _enum); if (allowableValues.size() > 0) { @@ -3868,7 +3870,6 @@ public class DefaultCodegen implements CodegenConfig { updatePropertyForAnyType(property, p); } else if (!ModelUtils.isNullType(p)) { // referenced model - ; } if (p.get$ref() != null) { property.setRef(p.get$ref()); @@ -5626,7 +5627,7 @@ public class DefaultCodegen implements CodegenConfig { continue; } cm.hasOptional = cm.hasOptional || !cp.required; - if (cp.isEnum) { + if (cp.getIsEnumOrRef()) { // isEnum or isEnumRef set to true // FIXME: if supporting inheritance, when called a second time for allProperties it is possible for // m.hasEnums to be set incorrectly if allProperties has enumerations but properties does not. cm.hasEnums = true; diff --git a/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache b/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache index f7954411df8..8596a35858c 100644 --- a/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache @@ -34,11 +34,11 @@ function Initialize-{{{apiNamePrefix}}}{{{classname}}} { {{#pattern}} [ValidatePattern("{{{.}}}")] {{/pattern}} - {{#isEnum}} + {{#isEnumOrRef}} {{#allowableValues}} [ValidateSet({{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}})] {{/allowableValues}} - {{/isEnum}} + {{/isEnumOrRef}} [{{vendorExtensions.x-powershell-data-type}}] {{=<% %>=}} ${<%name%>}<%#defaultValue%> = <%&.%><%/defaultValue%><%^vendorExtensions.x-powershell-last-writable%>,<%/vendorExtensions.x-powershell-last-writable%> @@ -52,11 +52,11 @@ function Initialize-{{{apiNamePrefix}}}{{{classname}}} { {{#pattern}} [ValidatePattern("{{{.}}}")] {{/pattern}} - {{#isEnum}} + {{#isEnumOrRef}} {{#allowableValues}} [ValidateSet({{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}})] {{/allowableValues}} - {{/isEnum}} + {{/isEnumOrRef}} [{{vendorExtensions.x-powershell-data-type}}] {{=<% %>=}} ${<%name%>}<%#defaultValue%> = <%&.%><%/defaultValue%><%^-last%>,<%/-last%> diff --git a/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache index a75dd49ae00..6d404195a03 100644 --- a/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache @@ -54,11 +54,11 @@ {{#requiredVars}} if (!missing(`{{name}}`)) { {{^isContainer}} - {{#isEnum}} + {{#isEnumOrRef}} if (!(`{{name}}` %in% c({{#_enum}}"{{{.}}}"{{^-last}}, {{/-last}}{{/_enum}}))) { stop(paste("Error! \"", `{{name}}`, "\" cannot be assigned to `{{name}}`. Must be {{#_enum}}\"{{{.}}}\"{{^-last}}, {{/-last}}{{/_enum}}.", sep = "")) } - {{/isEnum}} + {{/isEnumOrRef}} {{#isInteger}} if (!(is.numeric(`{{name}}`) && length(`{{name}}`) == 1)) { stop(paste("Error! Invalid data for `{{name}}`. Must be an integer:", `{{name}}`)) @@ -126,11 +126,11 @@ {{#optionalVars}} if (!is.null(`{{name}}`)) { {{^isContainer}} - {{#isEnum}} + {{#isEnumOrRef}} if (!(`{{name}}` %in% c({{#_enum}}"{{{.}}}"{{^-last}}, {{/-last}}{{/_enum}}))) { stop(paste("Error! \"", `{{name}}`, "\" cannot be assigned to `{{name}}`. Must be {{#_enum}}\"{{{.}}}\"{{^-last}}, {{/-last}}{{/_enum}}.", sep = "")) } - {{/isEnum}} + {{/isEnumOrRef}} {{#isInteger}} if (!(is.numeric(`{{name}}`) && length(`{{name}}`) == 1)) { stop(paste("Error! Invalid data for `{{name}}`. Must be an integer:", `{{name}}`)) @@ -275,11 +275,11 @@ {{/isContainer}} {{^isContainer}} {{#isPrimitiveType}} - {{#isEnum}} + {{#isEnumOrRef}} if (!is.null(this_object$`{{baseName}}`) && !(this_object$`{{baseName}}` %in% c({{#_enum}}"{{{.}}}"{{^-last}}, {{/-last}}{{/_enum}}))) { stop(paste("Error! \"", this_object$`{{baseName}}`, "\" cannot be assigned to `{{baseName}}`. Must be {{#_enum}}\"{{{.}}}\"{{^-last}}, {{/-last}}{{/_enum}}.", sep = "")) } - {{/isEnum}} + {{/isEnumOrRef}} {{#isUri}} # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r if (!stringr::str_detect(this_object$`{{baseName}}`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { @@ -407,11 +407,11 @@ {{/isContainer}} {{^isContainer}} {{#isPrimitiveType}} - {{#isEnum}} + {{#isEnumOrRef}} if (!is.null(this_object$`{{baseName}}`) && !(this_object$`{{baseName}}` %in% c({{#_enum}}"{{{.}}}"{{^-last}}, {{/-last}}{{/_enum}}))) { stop(paste("Error! \"", this_object$`{{baseName}}`, "\" cannot be assigned to `{{baseName}}`. Must be {{#_enum}}\"{{{.}}}\"{{^-last}}, {{/-last}}{{/_enum}}.", sep = "")) } - {{/isEnum}} + {{/isEnumOrRef}} {{#isUri}} # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r if (!stringr::str_detect(this_object$`{{name}}`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { diff --git a/modules/openapi-generator/src/main/resources/r/model_doc.mustache b/modules/openapi-generator/src/main/resources/r/model_doc.mustache index c0c8f5b7dfc..2156292b47c 100644 --- a/modules/openapi-generator/src/main/resources/r/model_doc.mustache +++ b/modules/openapi-generator/src/main/resources/r/model_doc.mustache @@ -6,7 +6,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#isReadOnly}}[readonly] {{/isReadOnly}}{{#defaultValue}}[default to {{.}}] {{/defaultValue}}{{#maximum}}[Max: {{{.}}}] {{/maximum}}{{#minimum}}[Min: {{{.}}}] {{/minimum}}{{#isEnum}}[Enum: {{_enum}}] {{/isEnum}}{{#pattern}}[Pattern: {{.}}] {{/pattern}}{{#maxItems}}[Max. items: {{.}}] {{/maxItems}}{{#minItems}}[Min. items: {{.}}] {{/minItems}}{{#maxLength}}[Max. length: {{.}}] {{/maxLength}}{{#minLength}}[Min. length: {{.}}] {{/minLength}} +{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#isReadOnly}}[readonly] {{/isReadOnly}}{{#defaultValue}}[default to {{.}}] {{/defaultValue}}{{#maximum}}[Max: {{{.}}}] {{/maximum}}{{#minimum}}[Min: {{{.}}}] {{/minimum}}{{#isEnumOrRef}}[Enum: {{_enum}}] {{/isEnumOrRef}}{{#pattern}}[Pattern: {{.}}] {{/pattern}}{{#maxItems}}[Max. items: {{.}}] {{/maxItems}}{{#minItems}}[Min. items: {{.}}] {{/minItems}}{{#maxLength}}[Max. length: {{.}}] {{/maxLength}}{{#minLength}}[Min. length: {{.}}] {{/minLength}} {{/vars}} {{/model}}{{/models}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index 593a45266b5..6df19a13118 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -4253,4 +4253,50 @@ public class DefaultCodegenTest { codegen.setOpenAPI(openAPI); assertEquals(openAPI, codegen.openAPI); } + + @Test + public void testReferencedEnumType() { + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue-5676-enums.yaml"); + final DefaultCodegen codegen = new DefaultCodegen(); + codegen.setOpenAPI(openAPI); + String modelName = "fakeRequestObjectWithReferencedEnum_request"; + + Schema schemaWithReferencedEnum = openAPI.getComponents().getSchemas().get(modelName); + CodegenModel modelWithReferencedSchema = codegen.fromModel(modelName, schemaWithReferencedEnum); + CodegenProperty referencedEnumSchemaProperty = modelWithReferencedSchema.vars.get(1); + + Assert.assertNotNull(schemaWithReferencedEnum); + Assert.assertTrue(modelWithReferencedSchema.hasEnums); + Assert.assertEquals(referencedEnumSchemaProperty.getName(), "enumType"); + Assert.assertFalse(referencedEnumSchemaProperty.isEnum); + Assert.assertTrue(referencedEnumSchemaProperty.getIsEnumOrRef()); + Assert.assertTrue(referencedEnumSchemaProperty.isEnumRef); + Assert.assertFalse(referencedEnumSchemaProperty.isInnerEnum); + Assert.assertFalse(referencedEnumSchemaProperty.isString); + Assert.assertFalse(referencedEnumSchemaProperty.isContainer); + Assert.assertFalse(referencedEnumSchemaProperty.isPrimitiveType); + } + + @Test + public void testInlineEnumType() { + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue-5676-enums.yaml"); + final DefaultCodegen codegen = new DefaultCodegen(); + codegen.setOpenAPI(openAPI); + String modelName = "fakeRequestObjectWithInlineEnum_request"; + + Schema schemaWithReferencedEnum = openAPI.getComponents().getSchemas().get(modelName); + CodegenModel modelWithReferencedSchema = codegen.fromModel(modelName, schemaWithReferencedEnum); + CodegenProperty inlineEnumSchemaProperty = modelWithReferencedSchema.vars.get(1); + + Assert.assertNotNull(schemaWithReferencedEnum); + Assert.assertTrue(modelWithReferencedSchema.hasEnums); + Assert.assertEquals(inlineEnumSchemaProperty.getName(), "enumType"); + Assert.assertTrue(inlineEnumSchemaProperty.isEnum); + Assert.assertTrue(inlineEnumSchemaProperty.isInnerEnum); + Assert.assertTrue(inlineEnumSchemaProperty.isEnumRef); + Assert.assertTrue(inlineEnumSchemaProperty.getIsEnumOrRef()); + Assert.assertTrue(inlineEnumSchemaProperty.isString); + Assert.assertFalse(inlineEnumSchemaProperty.isContainer); + Assert.assertFalse(inlineEnumSchemaProperty.isPrimitiveType); + } } diff --git a/modules/openapi-generator/src/test/resources/3_0/issue-5676-enums.yaml b/modules/openapi-generator/src/test/resources/3_0/issue-5676-enums.yaml new file mode 100644 index 00000000000..23cdfdc053b --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue-5676-enums.yaml @@ -0,0 +1,213 @@ +openapi: 3.0.0 +info: + version: 1.0.0 + title: Enum test +servers: + - url: http://localhost:3000 +paths: + /fake/request-object-with-inline-enum: + post: + operationId: fakeRequestObjectWithInlineEnum + requestBody: + content: + application/json: + schema: + description: Contains property enumType that represents inline enum. + properties: + id: + type: number + enumType: + type: string + enum: + - one + - two + - three + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/EnumPatternObject' + /fake/request-object-with-referenced-enum: + post: + operationId: fakeRequestObjectWithReferencedEnum + requestBody: + content: + application/json: + schema: + description: Contains property enumType that represents referenced enum. + properties: + id: + type: number + enumType: + $ref: '#/components/schemas/StringEnum' + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/EnumPatternObject' + /fake/request-array-with-inline-enum: + post: + operationId: fakeRequestArrayWithInlineEnum + requestBody: + content: + application/json: + schema: + description: Contains property enumTypes that represents array of inline enums. + properties: + id: + type: number + enumTypes: + type: array + items: + type: string + enum: + - one + - two + - three + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/EnumPatternObject' + /fake/request-array-with-referenced-enum: + post: + operationId: fakeRequestArrayWithReferencedEnum + requestBody: + content: + application/json: + schema: + description: Contains property enumTypes that represents array of referenced enums. + properties: + id: + type: number + enumTypes: + type: array + items: + $ref: '#/components/schemas/StringEnum' + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/EnumPatternObject' + /fake/request-map-with-inline-enum: + post: + operationId: fakeRequestMapWithInlineEnum + requestBody: + content: + application/json: + schema: + description: Contains property enumTypes that represents map of inline enums. + properties: + id: + type: number + enumTypes: + type: object + additionalProperties: + type: string + enum: + - one + - two + - three + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/EnumPatternObject' + /fake/request-map-with-referenced-enum: + post: + operationId: fakeRequestMapWithReferencedEnum + requestBody: + content: + application/json: + schema: + description: Contains property enumTypes that represents map of referenced enums. + properties: + id: + type: number + enumTypes: + type: object + additionalProperties: + $ref: '#/components/schemas/StringEnum' + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/EnumPatternObject' + /fake/multipart-request-with-inline-enum: + post: + operationId: fakeRequestMultipartWithInlineEnum + requestBody: + content: + multipart/form-data: + schema: + description: Contains property enumType that represents inline enum. + properties: + id: + type: number + enumType: + type: string + enum: + - one + - two + - three + /fake/multipart-request-with-referenced-enum: + post: + operationId: fakeRequestMultipartWithReferencedEnum + requestBody: + content: + multipart/form-data: + schema: + description: Contains property enumType that represents referenced enum. + properties: + id: + type: number + enumType: + $ref: '#/components/schemas/StringEnum' + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/EnumPatternObject' +components: + schemas: + StringEnum: + type: string + enum: + - one + - two + - three + NumberEnum: + type: number + enum: + - 1 + - 2 + - 3 + EnumPatternObject: + type: object + properties: + string-enum: + $ref: "#/components/schemas/StringEnum" + nullable-string-enum: + nullable: true + allOf: + - $ref: "#/components/schemas/StringEnum" + number-enum: + $ref: "#/components/schemas/NumberEnum" + nullable-number-enum: + nullable: true + allOf: + - $ref: "#/components/schemas/NumberEnum" diff --git a/samples/client/petstore/powershell/src/PSPetstore/Model/EnumTest.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Model/EnumTest.ps1 index 8b9608f1925..867691b2491 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Model/EnumTest.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Model/EnumTest.ps1 @@ -55,6 +55,7 @@ function Initialize-PSEnumTest { [System.Nullable[Double]] ${EnumNumber}, [Parameter(Position = 5, ValueFromPipelineByPropertyName = $true)] + [ValidateSet("placed", "approved", "delivered")] [PSCustomObject] ${OuterEnum} ) diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_object_with_enum_property.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_object_with_enum_property.rb index 1fc41768c4d..f330319f596 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_object_with_enum_property.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_object_with_enum_property.rb @@ -17,6 +17,28 @@ module Petstore class OuterObjectWithEnumProperty attr_accessor :value + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_object_with_enum_property.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_object_with_enum_property.rb index 1fc41768c4d..f330319f596 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_object_with_enum_property.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_object_with_enum_property.rb @@ -17,6 +17,28 @@ module Petstore class OuterObjectWithEnumProperty attr_accessor :value + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { diff --git a/samples/client/petstore/ruby/lib/petstore/models/outer_object_with_enum_property.rb b/samples/client/petstore/ruby/lib/petstore/models/outer_object_with_enum_property.rb index 1fc41768c4d..f330319f596 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/outer_object_with_enum_property.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/outer_object_with_enum_property.rb @@ -17,6 +17,28 @@ module Petstore class OuterObjectWithEnumProperty attr_accessor :value + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterObjectWithEnumProperty.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterObjectWithEnumProperty.cpp index d32bc53fdbd..74e7df43386 100644 --- a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterObjectWithEnumProperty.cpp +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterObjectWithEnumProperty.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterObjectWithEnumProperty.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterObjectWithEnumProperty.h index f3e5ef3f51f..e3f5886c246 100644 --- a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterObjectWithEnumProperty.h +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterObjectWithEnumProperty.h @@ -24,6 +24,7 @@ #include "OuterEnumInteger.h" #include #include +#include #include #include "helpers.h" diff --git a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/model/OuterObjectWithEnumProperty.java b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/model/OuterObjectWithEnumProperty.java index 45002fd1d7f..552f07ecc3a 100644 --- a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/model/OuterObjectWithEnumProperty.java +++ b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/model/OuterObjectWithEnumProperty.java @@ -12,6 +12,8 @@ package org.openapitools.server.model; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; import org.openapitools.server.model.OuterEnumInteger; import jakarta.validation.constraints.*; import jakarta.validation.Valid; diff --git a/samples/server/petstore/java-helidon-server/se/src/main/java/org/openapitools/server/model/OuterObjectWithEnumProperty.java b/samples/server/petstore/java-helidon-server/se/src/main/java/org/openapitools/server/model/OuterObjectWithEnumProperty.java index 7a75e0e3b60..54e563c42d3 100644 --- a/samples/server/petstore/java-helidon-server/se/src/main/java/org/openapitools/server/model/OuterObjectWithEnumProperty.java +++ b/samples/server/petstore/java-helidon-server/se/src/main/java/org/openapitools/server/model/OuterObjectWithEnumProperty.java @@ -1,5 +1,7 @@ package org.openapitools.server.model; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; import org.openapitools.server.model.OuterEnumInteger; diff --git a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java index 84384bbef80..57217ef3e9a 100644 --- a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java +++ b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java @@ -539,10 +539,10 @@ public interface PathHandlerInterface { *

Response headers: [CodegenProperty{openApiType='integer', baseName='X-Rate-Limit', complexType='null', getter='getxRateLimit', setter='setxRateLimit', description='calls per hour allowed by the user', dataType='Integer', datatypeWithEnum='Integer', dataFormat='int32', name='xRateLimit', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Rate-Limit;', baseType='Integer', containerType='null', title='null', unescapedDescription='calls per hour allowed by the user', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{ "type" : "integer", "format" : "int32" -}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=false, isNumeric=true, isInteger=true, isShort=true, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isFreeFormObject=false, isArray=false, isMap=false, isEnum=false, isInnerEnum=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='XRateLimit', nameInSnakeCase='X_RATE_LIMIT', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=int32, dependentRequired=null, contains=null}, CodegenProperty{openApiType='string', baseName='X-Expires-After', complexType='Date', getter='getxExpiresAfter', setter='setxExpiresAfter', description='date in UTC when token expires', dataType='Date', datatypeWithEnum='Date', dataFormat='date-time', name='xExpiresAfter', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Expires-After;', baseType='Date', containerType='null', title='null', unescapedDescription='date in UTC when token expires', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{ +}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=false, isNumeric=true, isInteger=true, isShort=true, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isFreeFormObject=false, isArray=false, isMap=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='XRateLimit', nameInSnakeCase='X_RATE_LIMIT', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=int32, dependentRequired=null, contains=null}, CodegenProperty{openApiType='string', baseName='X-Expires-After', complexType='Date', getter='getxExpiresAfter', setter='setxExpiresAfter', description='date in UTC when token expires', dataType='Date', datatypeWithEnum='Date', dataFormat='date-time', name='xExpiresAfter', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Expires-After;', baseType='Date', containerType='null', title='null', unescapedDescription='date in UTC when token expires', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{ "type" : "string", "format" : "date-time" -}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=false, isModel=false, isContainer=false, isString=false, isNumeric=false, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=true, isUuid=false, isUri=false, isEmail=false, isFreeFormObject=false, isArray=false, isMap=false, isEnum=false, isInnerEnum=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='XExpiresAfter', nameInSnakeCase='X_EXPIRES_AFTER', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=date-time, dependentRequired=null, contains=null}]

+}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=false, isModel=false, isContainer=false, isString=false, isNumeric=false, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=true, isUuid=false, isUri=false, isEmail=false, isFreeFormObject=false, isArray=false, isMap=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='XExpiresAfter', nameInSnakeCase='X_EXPIRES_AFTER', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=date-time, dependentRequired=null, contains=null}]

* *

Produces: [{mediaType=application/xml}, {mediaType=application/json}]

*

Returns: {@link String}

diff --git a/samples/server/petstore/jaxrs-jersey/src/gen/java/org/openapitools/model/OuterObjectWithEnumProperty.java b/samples/server/petstore/jaxrs-jersey/src/gen/java/org/openapitools/model/OuterObjectWithEnumProperty.java index 3db01589aba..9d2f9f0e107 100644 --- a/samples/server/petstore/jaxrs-jersey/src/gen/java/org/openapitools/model/OuterObjectWithEnumProperty.java +++ b/samples/server/petstore/jaxrs-jersey/src/gen/java/org/openapitools/model/OuterObjectWithEnumProperty.java @@ -16,6 +16,7 @@ package org.openapitools.model; 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 org.openapitools.model.OuterEnumInteger;