forked from loafle/openapi-generator-original
Add isEnumRef, isEnumOrRef to CodegenProperty (#13880)
* add isEnumRef to codegen property * better format * update R template to use isEnumOrRef * update powershell template to use isEnumOrRef * update samples
This commit is contained in:
parent
099a96b1ad
commit
ca5d9b5e69
@ -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<String, CodegenProperty> getRequiredVarsMap() { return requiredVarsMap; }
|
||||
public Map<String, CodegenProperty> getRequiredVarsMap() {
|
||||
return requiredVarsMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRequiredVarsMap(Map<String, CodegenProperty> requiredVarsMap) { this.requiredVarsMap=requiredVarsMap; }
|
||||
public void setRequiredVarsMap(Map<String, CodegenProperty> 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,
|
||||
|
@ -3798,6 +3798,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
if (referencedSchema.getEnum() != null && !referencedSchema.getEnum().isEmpty()) {
|
||||
List<Object> _enum = referencedSchema.getEnum();
|
||||
|
||||
property.isEnumRef = true;
|
||||
|
||||
Map<String, Object> 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;
|
||||
|
@ -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%>
|
||||
|
@ -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]*")) {
|
||||
|
@ -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}}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
@ -55,6 +55,7 @@ function Initialize-PSEnumTest {
|
||||
[System.Nullable[Double]]
|
||||
${EnumNumber},
|
||||
[Parameter(Position = 5, ValueFromPipelineByPropertyName = $true)]
|
||||
[ValidateSet("placed", "approved", "delivered")]
|
||||
[PSCustomObject]
|
||||
${OuterEnum}
|
||||
)
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <regex>
|
||||
#include <algorithm>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "OuterEnumInteger.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
@ -539,10 +539,10 @@ public interface PathHandlerInterface {
|
||||
* <p><b>Response headers</b>: [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}]</p>
|
||||
}', 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}]</p>
|
||||
*
|
||||
* <p><b>Produces</b>: [{mediaType=application/xml}, {mediaType=application/json}]</p>
|
||||
* <p><b>Returns</b>: {@link String}</p>
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user