You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -88,13 +101,15 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
88
101
}
89
102
{{/isArray}}
90
103
{{/isPrimitiveType}}
104
+
{{^isMap}}
91
105
{{^isArray}}
92
106
{{^isPrimitiveType}}
93
107
JsonElement element = adapter{{{dataType}}}.toJsonTree(({{{dataType}}})value.getActualInstance());
94
108
elementAdapter.write(out, element);
95
109
return;
96
110
{{/isPrimitiveType}}
97
111
{{/isArray}}
112
+
{{/isMap}}
98
113
}
99
114
{{/vendorExtensions.x-duplicated-data-type}}
100
115
{{/oneOf}}
@@ -143,6 +158,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
143
158
try {
144
159
// validate the JSON object to see if any exception is thrown
145
160
{{^isArray}}
161
+
{{^isMap}}
146
162
{{#isNumber}}
147
163
if (!jsonElement.getAsJsonPrimitive().isNumber()) {
148
164
throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString()));
@@ -163,6 +179,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
throw new IllegalArgumentException(String.format("Expected json element to be a object type in the JSON string but got `%s`", jsonElement.toString()));
if (!jsonElement.getAsJsonPrimitive().isNumber()) {
226
+
throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString()));
227
+
}
228
+
{{/isNumber}}
229
+
{{^isNumber}}
230
+
{{#isPrimitiveType}}
231
+
if (!element.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) {
232
+
throw new IllegalArgumentException(String.format("Expected array items to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString()));
log.log(Level.FINER, "Input data matches schema '{{{dataType}}}'");
199
248
} catch (Exception e) {
@@ -280,7 +329,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
280
329
{{#composedSchemas}}
281
330
{{#oneOf}}
282
331
{{^vendorExtensions.x-duplicated-data-type}}
283
-
if (instance instanceof {{#isArray}}List<?>{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}) {
332
+
if (instance instanceof {{#isArray}}List<?>{{/isArray}}{{#isMap}}Map<?, ?>{{/isMap}}{{^isMap}}{{^isArray}}{{{dataType}}}{{/isArray}}{{/isMap}}) {
284
333
{{#isArray}}
285
334
List<?> list = (List<?>) instance;
286
335
if (list.get(0) instanceof {{{items.dataType}}}) {
@@ -322,7 +371,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
322
371
* @return The actual instance of `{{{dataType}}}`
323
372
* @throws ClassCastException if the instance is not `{{{dataType}}}`
324
373
*/
325
-
public {{{dataType}}} get{{#isArray}}{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}() throws ClassCastException {
374
+
public {{{dataType}}} get{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}() throws ClassCastException {
326
375
return ({{{dataType}}})super.getActualInstance();
327
376
}
328
377
{{/vendorExtensions.x-duplicated-data-type}}
@@ -345,6 +394,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
345
394
// validate the json string with {{{dataType}}}
346
395
try {
347
396
{{^hasVars}}
397
+
{{^isMap}}
348
398
{{^isArray}}
349
399
{{#isNumber}}
350
400
if (!jsonElement.getAsJsonPrimitive().isNumber()) {
@@ -364,6 +414,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
364
414
{{/isPrimitiveType}}
365
415
{{/isNumber}}
366
416
{{/isArray}}
417
+
{{/isMap}}
367
418
{{#isArray}}
368
419
if (!jsonElement.isJsonArray()) {
369
420
throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString()));
@@ -392,6 +443,37 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
392
443
{{/items}}
393
444
}
394
445
{{/isArray}}
446
+
{{#isMap}}
447
+
if (!jsonElement.isJsonObject()) {
448
+
throw new IllegalArgumentException(String.format("Expected json element to be a object type in the JSON string but got `%s`", jsonElement.toString()));
if (!jsonElement.getAsJsonPrimitive().isNumber()) {
458
+
throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString()));
459
+
}
460
+
{{/isNumber}}
461
+
{{^isNumber}}
462
+
{{#isPrimitiveType}}
463
+
if (!element.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) {
464
+
throw new IllegalArgumentException(String.format("Expected array items to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString()));
Copy file name to clipboardExpand all lines: modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml
+22
Original file line number
Diff line number
Diff line change
@@ -1048,6 +1048,18 @@ paths:
1048
1048
schema:
1049
1049
$ref: '#/components/schemas/FileSchemaTestClass'
1050
1050
required: true
1051
+
/fake/get-free-form-object:
1052
+
get:
1053
+
tags:
1054
+
- fake
1055
+
description: Get a free form object or Json string
0 commit comments