Skip to content

Commit 837d8c9

Browse files
committed
Correct generation of DateTime schema
1 parent 6a515e8 commit 837d8c9

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

docs/domains/Domain.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@
122122
"clusterName"
123123
]
124124
},
125+
"DateTime": {
126+
"format": "date-time",
127+
"type": "string"
128+
},
125129
"DomainCondition": {
126130
"type": "object",
127131
"properties": {
@@ -130,9 +134,8 @@
130134
"type": "string"
131135
},
132136
"lastTransitionTime": {
133-
"format": "date-time",
134137
"description": "Last time the condition transitioned from one status to another.",
135-
"type": "string"
138+
"$ref": "#/definitions/DateTime"
136139
},
137140
"message": {
138141
"description": "Human-readable message indicating details about last transition.",
@@ -143,9 +146,8 @@
143146
"type": "string"
144147
},
145148
"lastProbeTime": {
146-
"format": "date-time",
147149
"description": "Last time we probed the condition.",
148-
"type": "string"
150+
"$ref": "#/definitions/DateTime"
149151
},
150152
"status": {
151153
"description": "Status is the status of the condition. Can be True, False, Unknown. Required",
@@ -290,9 +292,8 @@
290292
"minimum": 0
291293
},
292294
"startTime": {
293-
"format": "date-time",
294295
"description": "RFC 3339 date and time at which the operator started the domain. This will be when the operator begins processing and will precede when the various servers or clusters are available.",
295-
"type": "string"
296+
"$ref": "#/definitions/DateTime"
296297
},
297298
"conditions": {
298299
"description": "Current service state of domain.",
@@ -390,9 +391,8 @@
390391
"type": "string"
391392
},
392393
"activationTime": {
393-
"format": "date-time",
394394
"description": "RFC 3339 date and time at which the server started.",
395-
"type": "string"
395+
"$ref": "#/definitions/DateTime"
396396
},
397397
"subsystems": {
398398
"description": "Status of unhealthy subsystems, if any.",
@@ -1014,8 +1014,7 @@
10141014
"type": "string"
10151015
},
10161016
"deletionTimestamp": {
1017-
"format": "date-time",
1018-
"type": "string"
1017+
"$ref": "#/definitions/DateTime"
10191018
},
10201019
"labels": {
10211020
"$ref": "#/definitions/Map"
@@ -1042,8 +1041,7 @@
10421041
"type": "string"
10431042
},
10441043
"creationTimestamp": {
1045-
"format": "date-time",
1046-
"type": "string"
1044+
"$ref": "#/definitions/DateTime"
10471045
},
10481046
"name": {
10491047
"type": "string"

docs/domains/index.html

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,10 @@
10431043
"clusterName"
10441044
]
10451045
},
1046+
"DateTime": {
1047+
"format": "date-time",
1048+
"type": "string"
1049+
},
10461050
"DomainCondition": {
10471051
"type": "object",
10481052
"properties": {
@@ -1051,9 +1055,8 @@
10511055
"type": "string"
10521056
},
10531057
"lastTransitionTime": {
1054-
"format": "date-time",
10551058
"description": "Last time the condition transitioned from one status to another.",
1056-
"type": "string"
1059+
"$ref": "#/definitions/DateTime"
10571060
},
10581061
"message": {
10591062
"description": "Human-readable message indicating details about last transition.",
@@ -1064,9 +1067,8 @@
10641067
"type": "string"
10651068
},
10661069
"lastProbeTime": {
1067-
"format": "date-time",
10681070
"description": "Last time we probed the condition.",
1069-
"type": "string"
1071+
"$ref": "#/definitions/DateTime"
10701072
},
10711073
"status": {
10721074
"description": "Status is the status of the condition. Can be True, False, Unknown. Required",
@@ -1211,9 +1213,8 @@
12111213
"minimum": 0.0
12121214
},
12131215
"startTime": {
1214-
"format": "date-time",
12151216
"description": "RFC 3339 date and time at which the operator started the domain. This will be when the operator begins processing and will precede when the various servers or clusters are available.",
1216-
"type": "string"
1217+
"$ref": "#/definitions/DateTime"
12171218
},
12181219
"conditions": {
12191220
"description": "Current service state of domain.",
@@ -1311,9 +1312,8 @@
13111312
"type": "string"
13121313
},
13131314
"activationTime": {
1314-
"format": "date-time",
13151315
"description": "RFC 3339 date and time at which the server started.",
1316-
"type": "string"
1316+
"$ref": "#/definitions/DateTime"
13171317
},
13181318
"subsystems": {
13191319
"description": "Status of unhealthy subsystems, if any.",
@@ -1935,8 +1935,7 @@
19351935
"type": "string"
19361936
},
19371937
"deletionTimestamp": {
1938-
"format": "date-time",
1939-
"type": "string"
1938+
"$ref": "#/definitions/DateTime"
19401939
},
19411940
"labels": {
19421941
"$ref": "#/definitions/Map"
@@ -1963,8 +1962,7 @@
19631962
"type": "string"
19641963
},
19651964
"creationTimestamp": {
1966-
"format": "date-time",
1967-
"type": "string"
1965+
"$ref": "#/definitions/DateTime"
19681966
},
19691967
"name": {
19701968
"type": "string"

json-schema/src/main/java/oracle/kubernetes/json/SchemaGenerator.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ private Object getSubSchema(Field field) {
215215
String description = getDescription(field);
216216
if (description != null) result.put("description", description);
217217
if (isString(field.getType())) addStringRestrictions(result, field);
218-
if (isDateTime(field.getType())) result.put("format", "date-time");
219218
if (isNumeric(field.getType())) addRange(result, field);
220219

221220
return result;
@@ -285,7 +284,7 @@ private class SubSchemaGenerator {
285284
private void generateTypeIn(Map<String, Object> result, Class<?> type) {
286285
if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) result.put("type", "boolean");
287286
else if (isNumeric(type)) result.put("type", "number");
288-
else if (isString(type) || isDateTime(type)) result.put("type", "string");
287+
else if (isString(type)) result.put("type", "string");
289288
else if (type.isEnum()) generateEnumTypeIn(result, (Class<? extends Enum>) type);
290289
else if (type.isArray()) this.generateArrayTypeIn(result, type);
291290
else if (Collection.class.isAssignableFrom(type)) generateCollectionTypeIn(result);
@@ -403,20 +402,25 @@ private boolean satisfiesQualifier(Object enumConstant, Method qualifier) {
403402
}
404403

405404
private void generateObjectTypeIn(Map<String, Object> result, Class<?> type) {
406-
Map<String, Object> properties = new HashMap<>();
407-
List<String> requiredFields = new ArrayList<>();
408-
result.put("type", "object");
409-
if (includeAdditionalProperties) result.put("additionalProperties", "false");
410-
result.put("properties", properties);
411-
412-
for (Field field : getPropertyFields(type)) {
413-
if (!isSelfReference(field)) generateFieldIn(properties, field);
414-
if (isRequired(field) && includeInSchema(field)) {
415-
requiredFields.add(getPropertyName(field));
405+
if (isDateTime(type)) {
406+
result.put("type", "string");
407+
result.put("format", "date-time");
408+
} else {
409+
Map<String, Object> properties = new HashMap<>();
410+
List<String> requiredFields = new ArrayList<>();
411+
result.put("type", "object");
412+
if (includeAdditionalProperties) result.put("additionalProperties", "false");
413+
result.put("properties", properties);
414+
415+
for (Field field : getPropertyFields(type)) {
416+
if (!isSelfReference(field)) generateFieldIn(properties, field);
417+
if (isRequired(field) && includeInSchema(field)) {
418+
requiredFields.add(getPropertyName(field));
419+
}
416420
}
417-
}
418421

419-
if (!requiredFields.isEmpty()) result.put("required", requiredFields.toArray(new String[0]));
422+
if (!requiredFields.isEmpty()) result.put("required", requiredFields.toArray(new String[0]));
423+
}
420424
}
421425

422426
private Collection<Field> getPropertyFields(Class<?> type) {

0 commit comments

Comments
 (0)