Skip to content

Commit c59759f

Browse files
authored
Adds IJsonSchemaValidationProperties format getter and setter +uses the format info (#13360)
* Adds format getter and setter * Updates codegenProperty * Updates codegenModel * Updates codegenParameter + Response * Sets format and removes unused import code in python-experimental * Samples regenerated * Samples regenerated * Adds AnyTypeAndFormat * Separates format bases out from their str or number bases * Docs updated * Updates python-exp, stops setting isDate and uses format instead * Removes python-experimental isDate usages * Fixes password usages * Turns off isDateTime in python-experimental java layer * Sample regnerated without isDateTime * Removes isUuid * Turns off isDecimal, decimal_payload broken * Removes isDecimal * Removes isByteArray * Removes isBinary python-exp usages * Removes isFloat isDouble setting from python-experimental * Removes isDouble isFloat usages in sample * Stops setting isShort and isLong in python-exp java layer * Removes isShort isLong usages from python-exp and generates sample * Adds decimal as integer input * Adds missing bool type * Adds validations to format mixins, adds test_uuid * Adds test_date * Adds test_date_time * Adds test_number * Adds test_int32 * Adds test_int64 * Adds test_double * Adds test_float * Samples updated * Fixes javadoc
1 parent 928070c commit c59759f

File tree

416 files changed

+3729
-1004
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

416 files changed

+3729
-1004
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
114114
private boolean schemaIsFromAdditionalProperties;
115115
private boolean isBooleanSchemaTrue;
116116
private boolean isBooleanSchemaFalse;
117+
private String format;
117118

118119
/**
119120
* The type of the value for the additionalProperties keyword in the OAS document.
@@ -199,6 +200,16 @@ public void setIsBooleanSchemaFalse(boolean isBooleanSchemaFalse) {
199200
this.isBooleanSchemaFalse = isBooleanSchemaFalse;
200201
}
201202

203+
@Override
204+
public String getFormat() {
205+
return format;
206+
}
207+
208+
@Override
209+
public void setFormat(String format) {
210+
this.format = format;
211+
}
212+
202213
@Override
203214
public String getRef() {
204215
return ref;
@@ -987,6 +998,7 @@ public boolean equals(Object o) {
987998
getUniqueItems() == that.getUniqueItems() &&
988999
getExclusiveMinimum() == that.getExclusiveMinimum() &&
9891000
getExclusiveMaximum() == that.getExclusiveMaximum() &&
1001+
Objects.equals(format, that.getFormat()) &&
9901002
Objects.equals(uniqueItemsBoolean, that.getUniqueItemsBoolean()) &&
9911003
Objects.equals(ref, that.getRef()) &&
9921004
Objects.equals(requiredVarsMap, that.getRequiredVarsMap()) &&
@@ -1063,7 +1075,8 @@ hasChildren, isMap, isDeprecated, hasOnlyReadOnly, getExternalDocumentation(), g
10631075
getMaximum(), getPattern(), getMultipleOf(), getItems(), getAdditionalProperties(), getIsModel(),
10641076
getAdditionalPropertiesIsAnyType(), hasDiscriminatorWithNonEmptyMapping,
10651077
isAnyType, getComposedSchemas(), hasMultipleTypes, isDecimal, isUuid, requiredVarsMap, ref,
1066-
uniqueItemsBoolean, schemaIsFromAdditionalProperties, isBooleanSchemaTrue, isBooleanSchemaFalse);
1078+
uniqueItemsBoolean, schemaIsFromAdditionalProperties, isBooleanSchemaTrue, isBooleanSchemaFalse,
1079+
format);
10671080
}
10681081

10691082
@Override
@@ -1166,6 +1179,7 @@ public String toString() {
11661179
sb.append(", schemaIsFromAdditionalProperties=").append(schemaIsFromAdditionalProperties);
11671180
sb.append(", isBooleanSchemaTrue=").append(isBooleanSchemaTrue);
11681181
sb.append(", isBooleanSchemaFalse=").append(isBooleanSchemaFalse);
1182+
sb.append(", format=").append(format);
11691183
sb.append('}');
11701184
return sb.toString();
11711185
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenParameter.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,16 @@ public boolean getIsBooleanSchemaFalse() {
460460
@Override
461461
public void setIsBooleanSchemaFalse(boolean isBooleanSchemaFalse) {}
462462

463+
// use schema.getFormat or content.mediaType.schema.getFormat instead of this
464+
@Override
465+
public String getFormat() {
466+
return null;
467+
}
468+
469+
// use schema.setFormat or content.mediaType.schema.setFormat instead of this
470+
@Override
471+
public void setFormat(String format) {}
472+
463473
@Override
464474
public String getPattern() {
465475
return pattern;

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
200200
private boolean schemaIsFromAdditionalProperties;
201201
private boolean isBooleanSchemaTrue;
202202
private boolean isBooleanSchemaFalse;
203+
private String format;
204+
205+
@Override
206+
public void setFormat(String format) { this.format = format; }
207+
208+
@Override
209+
public String getFormat() { return format; }
203210

204211
@Override
205212
public boolean getIsBooleanSchemaTrue() {
@@ -742,6 +749,9 @@ public CodegenProperty clone() {
742749
if (this.ref != null) {
743750
cp.setRef(this.ref);
744751
}
752+
if (this.format != null) {
753+
cp.setFormat(this.format);
754+
}
745755

746756
return cp;
747757
} catch (CloneNotSupportedException e) {
@@ -1040,6 +1050,7 @@ public String toString() {
10401050
sb.append(", schemaIsFromAdditionalProperties=").append(schemaIsFromAdditionalProperties);
10411051
sb.append(", isBooleanSchemaTrue=").append(isBooleanSchemaTrue);
10421052
sb.append(", isBooleanSchemaFalse=").append(isBooleanSchemaFalse);
1053+
sb.append(", format=").append(format);
10431054
sb.append('}');
10441055
return sb.toString();
10451056
}
@@ -1101,6 +1112,7 @@ public boolean equals(Object o) {
11011112
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
11021113
getHasVars() == that.getHasVars() &&
11031114
getHasRequired() == that.getHasRequired() &&
1115+
Objects.equals(format, that.getFormat()) &&
11041116
Objects.equals(uniqueItemsBoolean, that.getUniqueItemsBoolean()) &&
11051117
Objects.equals(ref, that.getRef()) &&
11061118
Objects.equals(requiredVarsMap, that.getRequiredVarsMap()) &&
@@ -1168,6 +1180,7 @@ public int hashCode() {
11681180
nameInSnakeCase, enumName, maxItems, minItems, isXmlAttribute, xmlPrefix, xmlName,
11691181
xmlNamespace, isXmlWrapped, isNull, additionalPropertiesIsAnyType, hasVars, hasRequired,
11701182
hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes, requiredVarsMap,
1171-
ref, uniqueItemsBoolean, schemaIsFromAdditionalProperties, isBooleanSchemaTrue, isBooleanSchemaFalse);
1183+
ref, uniqueItemsBoolean, schemaIsFromAdditionalProperties, isBooleanSchemaTrue, isBooleanSchemaFalse,
1184+
format);
11721185
}
11731186
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenResponse.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ public boolean getIsBooleanSchemaFalse() {
209209
@Override
210210
public void setIsBooleanSchemaFalse(boolean isBooleanSchemaFalse) {}
211211

212+
// use content.mediaType.schema.getFormat instead of this
213+
@Override
214+
public String getFormat() {
215+
return null;
216+
}
217+
218+
// use content.mediaType.schema.setFormat instead of this
219+
@Override
220+
public void setFormat(String format) {}
221+
212222
public LinkedHashMap<String, CodegenMediaType> getContent() {
213223
return content;
214224
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 74 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2785,6 +2785,52 @@ private HashMap<String, SchemaTestCase> extractSchemaTestCases(String refToTestC
27852785
return schemaTestCases;
27862786
}
27872787

2788+
/**
2789+
* Sets the booleans that define the model's type
2790+
*
2791+
* @param model the model to update
2792+
* @param schema the model's schema
2793+
*/
2794+
protected void updateModelForString(CodegenModel model, Schema schema) {
2795+
// NOTE: String schemas as CodegenModel is a rare use case and may be removed at a later date.
2796+
if (ModelUtils.isDateTimeSchema(schema)) {
2797+
// NOTE: DateTime schemas as CodegenModel is a rare use case and may be removed at a later date.
2798+
model.setIsString(false); // for backward compatibility with 2.x
2799+
model.isDateTime = Boolean.TRUE;
2800+
} else if (ModelUtils.isDateSchema(schema)) {
2801+
// NOTE: Date schemas as CodegenModel is a rare use case and may be removed at a later date.
2802+
model.setIsString(false); // for backward compatibility with 2.x
2803+
model.isDate = Boolean.TRUE;
2804+
} else if (ModelUtils.isUUIDSchema(schema)) {
2805+
// NOTE: UUID schemas as CodegenModel is a rare use case and may be removed at a later date.
2806+
model.setIsString(false);
2807+
model.setIsUuid(true);
2808+
}
2809+
}
2810+
2811+
protected void updateModelForNumber(CodegenModel model, Schema schema) {
2812+
// NOTE: Number schemas as CodegenModel is a rare use case and may be removed at a later date.
2813+
model.isNumeric = Boolean.TRUE;
2814+
if (ModelUtils.isFloatSchema(schema)) { // float
2815+
model.isFloat = Boolean.TRUE;
2816+
} else if (ModelUtils.isDoubleSchema(schema)) { // double
2817+
model.isDouble = Boolean.TRUE;
2818+
}
2819+
}
2820+
2821+
protected void updateModelForInteger(CodegenModel model, Schema schema) {
2822+
// NOTE: Integral schemas as CodegenModel is a rare use case and may be removed at a later date.
2823+
model.isNumeric = Boolean.TRUE;
2824+
if (ModelUtils.isLongSchema(schema)) { // int64/long format
2825+
model.isLong = Boolean.TRUE;
2826+
} else {
2827+
model.isInteger = Boolean.TRUE; // older use case, int32 and unbounded int
2828+
if (ModelUtils.isShortSchema(schema)) { // int32
2829+
model.setIsShort(Boolean.TRUE);
2830+
}
2831+
}
2832+
}
2833+
27882834
/**
27892835
* Convert OAS Model object to Codegen Model object.
27902836
*
@@ -2866,46 +2912,19 @@ public CodegenModel fromModel(String name, Schema schema) {
28662912
}
28672913

28682914
m.setTypeProperties(schema);
2915+
m.setFormat(schema.getFormat());
28692916
m.setComposedSchemas(getComposedSchemas(schema));
28702917
if (ModelUtils.isArraySchema(schema)) {
28712918
CodegenProperty arrayProperty = fromProperty(name, schema, false);
28722919
m.setItems(arrayProperty.items);
28732920
m.arrayModelType = arrayProperty.complexType;
28742921
addParentContainer(m, name, schema);
28752922
} else if (ModelUtils.isIntegerSchema(schema)) { // integer type
2876-
// NOTE: Integral schemas as CodegenModel is a rare use case and may be removed at a later date.
2877-
m.isNumeric = Boolean.TRUE;
2878-
if (ModelUtils.isLongSchema(schema)) { // int64/long format
2879-
m.isLong = Boolean.TRUE;
2880-
} else {
2881-
m.isInteger = Boolean.TRUE; // older use case, int32 and unbounded int
2882-
if (ModelUtils.isShortSchema(schema)) { // int32
2883-
m.setIsShort(Boolean.TRUE);
2884-
}
2885-
}
2923+
updateModelForInteger(m, schema);
28862924
} else if (ModelUtils.isStringSchema(schema)) {
2887-
// NOTE: String schemas as CodegenModel is a rare use case and may be removed at a later date.
2888-
if (ModelUtils.isDateTimeSchema(schema)) {
2889-
// NOTE: DateTime schemas as CodegenModel is a rare use case and may be removed at a later date.
2890-
m.setIsString(false); // for backward compatibility with 2.x
2891-
m.isDateTime = Boolean.TRUE;
2892-
} else if (ModelUtils.isDateSchema(schema)) {
2893-
// NOTE: Date schemas as CodegenModel is a rare use case and may be removed at a later date.
2894-
m.setIsString(false); // for backward compatibility with 2.x
2895-
m.isDate = Boolean.TRUE;
2896-
} else if (ModelUtils.isUUIDSchema(schema)) {
2897-
// NOTE: UUID schemas as CodegenModel is a rare use case and may be removed at a later date.
2898-
m.setIsString(false);
2899-
m.setIsUuid(true);
2900-
}
2925+
updateModelForString(m, schema);
29012926
} else if (ModelUtils.isNumberSchema(schema)) {
2902-
// NOTE: Number schemas as CodegenModel is a rare use case and may be removed at a later date.
2903-
m.isNumeric = Boolean.TRUE;
2904-
if (ModelUtils.isFloatSchema(schema)) { // float
2905-
m.isFloat = Boolean.TRUE;
2906-
} else if (ModelUtils.isDoubleSchema(schema)) { // double
2907-
m.isDouble = Boolean.TRUE;
2908-
}
2927+
updateModelForNumber(m, schema);
29092928
} else if (ModelUtils.isAnyType(schema)) {
29102929
updateModelForAnyType(m, schema);
29112930
} else if (ModelUtils.isTypeObjectSchema(schema)) {
@@ -3575,6 +3594,27 @@ protected void updatePropertyForString(CodegenProperty property, Schema p) {
35753594
property.pattern = toRegularExpression(p.getPattern());
35763595
}
35773596

3597+
protected void updatePropertyForNumber(CodegenProperty property, Schema p) {
3598+
property.isNumeric = Boolean.TRUE;
3599+
if (ModelUtils.isFloatSchema(p)) { // float
3600+
property.isFloat = Boolean.TRUE;
3601+
} else if (ModelUtils.isDoubleSchema(p)) { // double
3602+
property.isDouble = Boolean.TRUE;
3603+
}
3604+
}
3605+
3606+
protected void updatePropertyForInteger(CodegenProperty property, Schema p) {
3607+
property.isNumeric = Boolean.TRUE;
3608+
if (ModelUtils.isLongSchema(p)) { // int64/long format
3609+
property.isLong = Boolean.TRUE;
3610+
} else {
3611+
property.isInteger = Boolean.TRUE; // older use case, int32 and unbounded int
3612+
if (ModelUtils.isShortSchema(p)) { // int32
3613+
property.setIsShort(Boolean.TRUE);
3614+
}
3615+
}
3616+
}
3617+
35783618
/**
35793619
* TODO remove this in 7.0.0 as a breaking change
35803620
* This method was kept when required was added to the fromProperty signature
@@ -3646,6 +3686,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
36463686
property.setSchemaIsFromAdditionalProperties(schemaIsFromAdditionalProperties);
36473687
property.required = required;
36483688
ModelUtils.syncValidationProperties(p, property);
3689+
property.setFormat(p.getFormat());
36493690

36503691
property.name = toVarName(name);
36513692
property.baseName = name;
@@ -3763,15 +3804,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
37633804
property.setTypeProperties(p);
37643805
property.setComposedSchemas(getComposedSchemas(p));
37653806
if (ModelUtils.isIntegerSchema(p)) { // integer type
3766-
property.isNumeric = Boolean.TRUE;
3767-
if (ModelUtils.isLongSchema(p)) { // int64/long format
3768-
property.isLong = Boolean.TRUE;
3769-
} else {
3770-
property.isInteger = Boolean.TRUE; // older use case, int32 and unbounded int
3771-
if (ModelUtils.isShortSchema(p)) { // int32
3772-
property.setIsShort(Boolean.TRUE);
3773-
}
3774-
}
3807+
updatePropertyForInteger(property, p);
37753808
} else if (ModelUtils.isBooleanSchema(p)) { // boolean type
37763809
property.getter = toBooleanGetter(name);
37773810
} else if (ModelUtils.isFileSchema(p) && !ModelUtils.isStringSchema(p)) {
@@ -3780,12 +3813,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
37803813
} else if (ModelUtils.isStringSchema(p)) {
37813814
updatePropertyForString(property, p);
37823815
} else if (ModelUtils.isNumberSchema(p)) {
3783-
property.isNumeric = Boolean.TRUE;
3784-
if (ModelUtils.isFloatSchema(p)) { // float
3785-
property.isFloat = Boolean.TRUE;
3786-
} else if (ModelUtils.isDoubleSchema(p)) { // double
3787-
property.isDouble = Boolean.TRUE;
3788-
}
3816+
updatePropertyForNumber(property, p);
37893817
} else if (ModelUtils.isArraySchema(p)) {
37903818
// default to string if inner item is undefined
37913819
property.isContainer = true;

modules/openapi-generator/src/main/java/org/openapitools/codegen/IJsonSchemaValidationProperties.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ public interface IJsonSchemaValidationProperties {
202202

203203
void setSchemaIsFromAdditionalProperties(boolean schemaIsFromAdditionalProperties);
204204

205+
void setFormat(String format);
206+
207+
String getFormat();
208+
205209
/**
206210
* Syncs all the schema's type properties into the IJsonSchemaValidationProperties instance
207211
* for now this only supports types without format information

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PerlClientCodegen.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,40 @@ public void postProcess() {
663663
System.out.println("################################################################################");
664664
}
665665

666+
/**
667+
* Convert OAS Model object to Codegen Model object
668+
* A custom version is made for this method to ensure that
669+
* model.format remains empty string
670+
*
671+
* @param name the name of the model
672+
* @param sc OAS Model object
673+
* @return Codegen Model object
674+
*/
675+
@Override
676+
public CodegenModel fromModel(String name, Schema sc) {
677+
CodegenModel cm = super.fromModel(name, sc);
678+
cm.setFormat("");
679+
return cm;
680+
}
681+
682+
/**
683+
* Convert OAS Property object to Codegen Property object
684+
* A custom version is made for this method to ensure that
685+
* property.format remains empty string
686+
*
687+
* @param name name of the property
688+
* @param p OAS property schema
689+
* @param required true if the property is required in the next higher object schema, false otherwise
690+
* @param schemaIsFromAdditionalProperties true if the property is defined by additional properties schema
691+
* @return Codegen Property object
692+
*/
693+
@Override
694+
public CodegenProperty fromProperty(String name, Schema p, boolean required, boolean schemaIsFromAdditionalProperties) {
695+
CodegenProperty property = super.fromProperty(name, p, required, schemaIsFromAdditionalProperties);
696+
property.setFormat("");
697+
return property;
698+
}
699+
666700
@Override
667701
public GeneratorLanguage generatorLanguage() { return GeneratorLanguage.PERL; }
668702
}

0 commit comments

Comments
 (0)