Skip to content

Commit d9dbcea

Browse files
committed
json schema
1 parent fde3960 commit d9dbcea

7 files changed

Lines changed: 70 additions & 9 deletions

File tree

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
125125
public String arrayModelType;
126126
public boolean isAlias; // Is this effectively an alias of another simple type
127127
public boolean isString, isInteger, isLong, isNumber, isNumeric, isFloat, isDouble, isDate, isDateTime,
128-
isDecimal, isShort, isUnboundedInteger, isPrimitiveType, isBoolean, isFreeFormObject;
128+
isDuration, isDecimal, isShort, isUnboundedInteger, isPrimitiveType, isBoolean, isFreeFormObject;
129129
private boolean additionalPropertiesIsAnyType;
130130
public List<CodegenProperty> vars = new ArrayList<>(); // all properties (without parent's properties)
131131
@Getter @Setter
@@ -544,6 +544,16 @@ public void setIsDateTime(boolean isDateTime) {
544544
this.isDateTime = isDateTime;
545545
}
546546

547+
@Override
548+
public boolean getIsDuration() {
549+
return isDuration;
550+
}
551+
552+
@Override
553+
public void setIsDuration(boolean isDuration) {
554+
this.isDuration = isDuration;
555+
}
556+
547557
@Override
548558
public boolean getIsMap() {
549559
return isMap;
@@ -878,6 +888,7 @@ public boolean equals(Object o) {
878888
isDouble == that.isDouble &&
879889
isDate == that.isDate &&
880890
isDateTime == that.isDateTime &&
891+
isDuration == that.isDuration &&
881892
hasVars == that.hasVars &&
882893
emptyVars == that.emptyVars &&
883894
hasMoreModels == that.hasMoreModels &&
@@ -979,7 +990,7 @@ public int hashCode() {
979990
getDescription(), getClassVarName(), getModelJson(), getDataType(), getXmlPrefix(), getXmlNamespace(),
980991
getXmlName(), getClassFilename(), getUnescapedDescription(), getDiscriminator(), getDefaultValue(),
981992
getArrayModelType(), isAlias, isString, isInteger, isLong, isNumber, isNumeric, isFloat, isDouble,
982-
isDate, isDateTime, isNull, hasValidation, isShort, isUnboundedInteger, isBoolean,
993+
isDate, isDateTime, isDuration, isNull, hasValidation, isShort, isUnboundedInteger, isBoolean,
983994
getVars(), getAllVars(), getNonNullableVars(), getRequiredVars(), getOptionalVars(), getReadOnlyVars(), getReadWriteVars(),
984995
getParentVars(), getAllowableValues(), getMandatory(), getAllMandatory(), getImports(), hasVars,
985996
isEmptyVars(), hasMoreModels, hasEnums, isEnum, isNullable, hasRequired, hasOptional, isArray,
@@ -1035,6 +1046,7 @@ public String toString() {
10351046
sb.append(", isDouble=").append(isDouble);
10361047
sb.append(", isDate=").append(isDate);
10371048
sb.append(", isDateTime=").append(isDateTime);
1049+
sb.append(", isDuration=").append(isDuration);
10381050
sb.append(", vars=").append(vars);
10391051
sb.append(", allVars=").append(allVars);
10401052
sb.append(", nonNullableVars=").append(nonNullableVars);

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
4848
public Map<String, Example> examples;
4949
public String jsonSchema;
5050
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary,
51-
isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isPassword, isFreeFormObject, isAnyType, isShort, isUnboundedInteger;
51+
isBoolean, isDate, isDateTime, isDuration, isUuid, isUri, isEmail, isPassword, isFreeFormObject, isAnyType, isShort, isUnboundedInteger;
5252
public boolean isArray, isMap;
5353
/** datatype is the generic inner parameter of a std::optional for C++, or Optional (Java) */
5454
public boolean isOptional;
@@ -259,6 +259,7 @@ public CodegenParameter copy() {
259259
output.isBoolean = this.isBoolean;
260260
output.isDate = this.isDate;
261261
output.isDateTime = this.isDateTime;
262+
output.isDuration = this.isDuration;
262263
output.isUuid = this.isUuid;
263264
output.isUri = this.isUri;
264265
output.isEmail = this.isEmail;
@@ -286,7 +287,7 @@ public int hashCode() {
286287
unescapedDescription, baseType, containerType, containerTypeMapped, defaultValue,
287288
enumDefaultValue, enumName, style, isDeepObject, isMatrix, isAllowEmptyValue, example, examples,
288289
jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal,
289-
isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isPassword,
290+
isByteArray, isBinary, isBoolean, isDate, isDateTime, isDuration, isUuid, isUri, isEmail, isPassword,
290291
isFreeFormObject, isAnyType, isArray, isMap, isOptional, isFile, isEnum, isEnumRef, _enum, allowableValues,
291292
items, mostInnerItems, additionalProperties, vars, requiredVars, vendorExtensions, hasValidation,
292293
getMaxProperties(), getMinProperties(), isNullable, isDeprecated, required, getMaximum(),
@@ -329,6 +330,7 @@ public boolean equals(Object o) {
329330
isBoolean == that.isBoolean &&
330331
isDate == that.isDate &&
331332
isDateTime == that.isDateTime &&
333+
isDuration == that.isDuration &&
332334
isUuid == that.isUuid &&
333335
isUri == that.isUri &&
334336
isEmail == that.isEmail &&
@@ -463,6 +465,7 @@ public String toString() {
463465
sb.append(", isBoolean=").append(isBoolean);
464466
sb.append(", isDate=").append(isDate);
465467
sb.append(", isDateTime=").append(isDateTime);
468+
sb.append(", isDuration=").append(isDuration);
466469
sb.append(", isUuid=").append(isUuid);
467470
sb.append(", isUri=").append(isUri);
468471
sb.append(", isEmail=").append(isEmail);
@@ -754,6 +757,16 @@ public void setIsDateTime(boolean isDateTime) {
754757
this.isDateTime = isDateTime;
755758
}
756759

760+
@Override
761+
public boolean getIsDuration() {
762+
return isDuration;
763+
}
764+
765+
@Override
766+
public void setIsDuration(boolean isDuration) {
767+
this.isDuration = isDuration;
768+
}
769+
757770
@Override
758771
public boolean getIsMap() {
759772
return isMap;

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
@@ -159,6 +159,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
159159
public boolean isBoolean;
160160
public boolean isDate; // full-date notation as defined by RFC 3339, section 5.6, for example, 2017-07-21
161161
public boolean isDateTime; // the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
162+
public boolean isDuration;
162163
public boolean isUuid;
163164
public boolean isUri;
164165
public boolean isEmail;
@@ -488,6 +489,16 @@ public void setIsDateTime(boolean isDateTime) {
488489
this.isDateTime = isDateTime;
489490
}
490491

492+
@Override
493+
public boolean getIsDuration() {
494+
return isDuration;
495+
}
496+
497+
@Override
498+
public void setIsDuration(boolean isDuration) {
499+
this.isDuration = isDuration;
500+
}
501+
491502
@Override
492503
public boolean getIsMap() {
493504
return isMap;
@@ -1014,6 +1025,7 @@ public String toString() {
10141025
sb.append(", isBoolean=").append(isBoolean);
10151026
sb.append(", isDate=").append(isDate);
10161027
sb.append(", isDateTime=").append(isDateTime);
1028+
sb.append(", isDuration=").append(isDuration);
10171029
sb.append(", isUuid=").append(isUuid);
10181030
sb.append(", isUri=").append(isUri);
10191031
sb.append(", isEmail=").append(isEmail);
@@ -1111,6 +1123,7 @@ public boolean equals(Object o) {
11111123
isBoolean == that.isBoolean &&
11121124
isDate == that.isDate &&
11131125
isDateTime == that.isDateTime &&
1126+
isDuration == that.isDuration &&
11141127
isUuid == that.isUuid &&
11151128
isUri == that.isUri &&
11161129
isEmail == that.isEmail &&
@@ -1210,7 +1223,7 @@ public int hashCode() {
12101223
exclusiveMinimum, exclusiveMaximum, required, deprecated,
12111224
hasMoreNonReadOnly, isPrimitiveType, isModel, isContainer, isString, isNumeric,
12121225
isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isFile,
1213-
isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isPassword, isFreeFormObject,
1226+
isBoolean, isDate, isDateTime, isDuration, isUuid, isUri, isEmail, isPassword, isFreeFormObject,
12141227
isArray, isMap, isOptional, isEnum, isInnerEnum, isEnumRef, isAnyType, isReadOnly, isWriteOnly, isNullable, isShort,
12151228
isUnboundedInteger, isSelfReference, isCircularReference, isDiscriminator, isNew, isOverridden, _enum,
12161229
allowableValues, items, mostInnerItems, additionalProperties, vars, requiredVars,

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
5353
public boolean isBoolean;
5454
public boolean isDate;
5555
public boolean isDateTime;
56+
public boolean isDuration;
5657
public boolean isUuid;
5758
public boolean isEmail;
5859
public boolean isPassword;
@@ -109,7 +110,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
109110
public int hashCode() {
110111
return Objects.hash(headers, code, message, examples, dataType, baseType, containerType, containerTypeMapped, hasHeaders,
111112
isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBoolean, isDate,
112-
isDateTime, isUuid, isEmail, isPassword, isModel, isFreeFormObject, isAnyType, isDefault, simpleType, primitiveType,
113+
isDateTime, isDuration, isUuid, isEmail, isPassword, isModel, isFreeFormObject, isAnyType, isDefault, simpleType, primitiveType,
113114
isMap, isOptional, isArray, isBinary, isFile, schema, jsonSchema, vendorExtensions, items, additionalProperties,
114115
vars, requiredVars, isNull, isVoid, hasValidation, isShort, isUnboundedInteger,
115116
getMaxProperties(), getMinProperties(), uniqueItems, getMaxItems(), getMinItems(), getMaxLength(),
@@ -139,6 +140,7 @@ public boolean equals(Object o) {
139140
isBoolean == that.isBoolean &&
140141
isDate == that.isDate &&
141142
isDateTime == that.isDateTime &&
143+
isDuration == that.isDuration &&
142144
isUuid == that.isUuid &&
143145
isEmail == that.isEmail &&
144146
isPassword == that.isPassword &&
@@ -485,6 +487,16 @@ public void setIsDateTime(boolean isDateTime) {
485487
this.isDateTime = isDateTime;
486488
}
487489

490+
@Override
491+
public boolean getIsDuration() {
492+
return isDuration;
493+
}
494+
495+
@Override
496+
public void setIsDuration(boolean isDuration) {
497+
this.isDuration = isDuration;
498+
}
499+
488500
@Override
489501
public boolean getIsMap() {
490502
return isMap;
@@ -586,6 +598,7 @@ public String toString() {
586598
sb.append(", isBoolean=").append(isBoolean);
587599
sb.append(", isDate=").append(isDate);
588600
sb.append(", isDateTime=").append(isDateTime);
601+
sb.append(", isDuration=").append(isDuration);
589602
sb.append(", isUuid=").append(isUuid);
590603
sb.append(", isEmail=").append(isEmail);
591604
sb.append(", isPassword=").append(isPassword);

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

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

102102
void setIsDateTime(boolean isDateTime);
103103

104+
boolean getIsDuration();
105+
106+
void setIsDuration(boolean isDuration);
107+
104108
// true when the schema type is object
105109
boolean getIsMap();
106110

@@ -312,6 +316,8 @@ default void setTypeProperties(Schema p, OpenAPI openAPI) {
312316
;
313317
} else if (ModelUtils.isDateTimeSchema(p)) {
314318
;
319+
} else if (ModelUtils.isDurationSchema(p)) {
320+
;
315321
} else if (ModelUtils.isDecimalSchema(p)) { // type: string, format: number
316322
;
317323
}

modules/openapi-generator/src/main/resources/csharp/libraries/generichost/JsonConverter.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@
226226
if (utf8JsonReader.TokenType != JsonTokenType.Null)
227227
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}JsonSerializer.Deserialize<DateTime{{#isNullable}}?{{/isNullable}}>(ref utf8JsonReader, jsonSerializerOptions));
228228
{{/isDateTime}}
229+
{{#isDuration}}
230+
if (utf8JsonReader.TokenType != JsonTokenType.Null)
231+
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}JsonSerializer.Deserialize<Timespan{{#isNullable}}?{{/isNullable}}>(ref utf8JsonReader, jsonSerializerOptions));
232+
{{/isDuration}}
229233
{{#isEnum}}
230234
{{^isMap}}
231235
{{#isNumeric}}

0 commit comments

Comments
 (0)