@@ -271,10 +271,6 @@ public SwaggerParseResult deserialize(JsonNode rootNode) {
271
271
return deserialize (rootNode , null );
272
272
}
273
273
274
- public SwaggerParseResult deserialize (JsonNode rootNode , String path ) {
275
- return deserialize (rootNode , null , false );
276
- }
277
-
278
274
public SwaggerParseResult deserialize (JsonNode rootNode , String path ) {
279
275
return deserialize (rootNode ,path , new ParseOptions ());
280
276
}
@@ -290,7 +286,8 @@ public SwaggerParseResult deserialize(JsonNode rootNode, String path, ParseOptio
290
286
SwaggerParseResult result = new SwaggerParseResult ();
291
287
try {
292
288
ParseResult rootParse = new ParseResult ();
293
- rootParse .setOaiAuthor (isOaiAuthor );
289
+ rootParse .setOaiAuthor (options .isOaiAuthor ());
290
+ rootParse .setDefaultSchemaTypeObject (options .isDefaultSchemaTypeObject ());
294
291
rootParse .setAllowEmptyStrings (options .isAllowEmptyString ());
295
292
rootParse .setValidateInternalRefs (options .isValidateInternalRefs ());
296
293
OpenAPI api = parseRoot (rootNode , rootParse , path );
@@ -1376,7 +1373,7 @@ public MediaType getMediaType(ObjectNode contentNode, String location, ParseResu
1376
1373
, false ));
1377
1374
}
1378
1375
1379
- Object example = getAnyExample ("example" , contentNode , location , result );
1376
+ Object example = getAnyType ("example" , contentNode , location , result );
1380
1377
if (example != null ) {
1381
1378
if (examplesObject != null ) {
1382
1379
result .warning (location , "examples already defined -- ignoring \" example\" field" );
@@ -1986,7 +1983,7 @@ public Parameter getParameter(ObjectNode obj, String location, ParseResult resul
1986
1983
, false ));
1987
1984
}
1988
1985
1989
- Object example = getAnyExample ("example" , obj , location , result );
1986
+ Object example = getAnyType ("example" , obj , location , result );
1990
1987
if (example != null ) {
1991
1988
if (examplesObject != null ) {
1992
1989
result .warning (location , "examples already defined -- ignoring \" example\" field" );
@@ -2151,7 +2148,7 @@ public Header getHeader(ObjectNode headerNode, String location, ParseResult resu
2151
2148
header .setExamples (getExamples (examplesObject , location , result , false ));
2152
2149
}
2153
2150
2154
- Object example = getAnyExample ("example" , headerNode , location , result );
2151
+ Object example = getAnyType ("example" , headerNode , location , result );
2155
2152
if (example != null ) {
2156
2153
if (examplesObject != null ) {
2157
2154
result .warning (location , "examples already defined -- ignoring \" example\" field" );
@@ -2180,8 +2177,8 @@ public Header getHeader(ObjectNode headerNode, String location, ParseResult resu
2180
2177
2181
2178
return header ;
2182
2179
}
2183
- //TODO rename method as is used by different objects not only to get examples
2184
- public Object getAnyExample (String nodeKey , ObjectNode node , String location , ParseResult result ) {
2180
+
2181
+ public Object getAnyType (String nodeKey , ObjectNode node , String location , ParseResult result ) {
2185
2182
JsonNode example = node .get (nodeKey );
2186
2183
if (example != null ) {
2187
2184
if (example .getNodeType ().equals (JsonNodeType .STRING )) {
@@ -2602,7 +2599,7 @@ at the moment path passed as string (basePath) from upper components can be both
2602
2599
}
2603
2600
}
2604
2601
2605
- if (itemsNode != null ) {
2602
+ if (itemsNode != null && result . isDefaultSchemaTypeObject () ) {
2606
2603
ArraySchema items = new ArraySchema ();
2607
2604
if (itemsNode .getNodeType ().equals (JsonNodeType .OBJECT )) {
2608
2605
items .setItems (getSchema (itemsNode , location , result ));
@@ -2614,6 +2611,18 @@ at the moment path passed as string (basePath) from upper components can be both
2614
2611
}
2615
2612
}
2616
2613
schema = items ;
2614
+ }else if (itemsNode != null ){
2615
+ Schema items = new Schema ();
2616
+ if (itemsNode .getNodeType ().equals (JsonNodeType .OBJECT )) {
2617
+ items .setItems (getSchema (itemsNode , location , result ));
2618
+ } else if (itemsNode .getNodeType ().equals (JsonNodeType .ARRAY )) {
2619
+ for (JsonNode n : itemsNode ) {
2620
+ if (n .isValueNode ()) {
2621
+ items .setItems (getSchema (itemsNode , location , result ));
2622
+ }
2623
+ }
2624
+ }
2625
+ schema = items ;
2617
2626
}
2618
2627
2619
2628
Boolean additionalPropertiesBoolean = getBoolean ("additionalProperties" , node , false , location , result );
@@ -2628,7 +2637,7 @@ at the moment path passed as string (basePath) from upper components can be both
2628
2637
? getSchema (additionalPropertiesObject , location , result )
2629
2638
: additionalPropertiesBoolean ;
2630
2639
2631
- if (additionalProperties != null ) {
2640
+ if (additionalProperties != null && result . isDefaultSchemaTypeObject () ) {
2632
2641
if (schema == null ) {
2633
2642
schema =
2634
2643
additionalProperties .equals (Boolean .FALSE )
@@ -2857,7 +2866,7 @@ at the moment path passed as string (basePath) from upper components can be both
2857
2866
}
2858
2867
2859
2868
//sets default value according to the schema type
2860
- if (node .get ("default" ) != null ) {
2869
+ if (node .get ("default" ) != null && result . isDefaultSchemaTypeObject () ) {
2861
2870
if (!StringUtils .isBlank (schema .getType ())) {
2862
2871
if (schema .getType ().equals ("array" )) {
2863
2872
ArrayNode array = getArray ("default" , node , false , location , result );
@@ -2896,6 +2905,13 @@ at the moment path passed as string (basePath) from upper components can be both
2896
2905
}
2897
2906
}
2898
2907
}
2908
+ }else {
2909
+ schema .setDefault (null );
2910
+ }
2911
+
2912
+ bool = getBoolean ("nullable" , node , false , location , result );
2913
+ if (bool != null ) {
2914
+ schema .setNullable (bool );
2899
2915
}
2900
2916
2901
2917
bool = getBoolean ("readOnly" , node , false , location , result );
@@ -2931,7 +2947,7 @@ at the moment path passed as string (basePath) from upper components can be both
2931
2947
}
2932
2948
}
2933
2949
2934
- Object example = getAnyExample ("example" , node , location , result );
2950
+ Object example = getAnyType ("example" , node , location , result );
2935
2951
if (example != null ) {
2936
2952
schema .setExample (example instanceof NullNode ? null : example );
2937
2953
}
@@ -3139,7 +3155,7 @@ public Example getExample(ObjectNode node, String location, ParseResult result)
3139
3155
example .setDescription (value );
3140
3156
}
3141
3157
3142
- Object sample = getAnyExample ("value" , node , location , result );
3158
+ Object sample = getAnyType ("value" , node , location , result );
3143
3159
if (sample != null ) {
3144
3160
example .setValue (sample instanceof NullNode ? null : sample );
3145
3161
}
@@ -3648,8 +3664,19 @@ public Schema getJsonSchema(ObjectNode node, String location, ParseResult result
3648
3664
schema = composedSchema ;
3649
3665
}
3650
3666
}
3651
-
3652
- if (itemsNode != null ) {
3667
+ if (itemsNode != null && result .isDefaultSchemaTypeObject ()) {
3668
+ ArraySchema items = new ArraySchema ();
3669
+ if (itemsNode .getNodeType ().equals (JsonNodeType .OBJECT )) {
3670
+ items .setItems (getSchema (itemsNode , location , result ));
3671
+ } else if (itemsNode .getNodeType ().equals (JsonNodeType .ARRAY )) {
3672
+ for (JsonNode n : itemsNode ) {
3673
+ if (n .isValueNode ()) {
3674
+ items .setItems (getSchema (itemsNode , location , result ));
3675
+ }
3676
+ }
3677
+ }
3678
+ schema = items ;
3679
+ }else if (itemsNode != null ) {
3653
3680
JsonSchema items = new JsonSchema ();
3654
3681
if (itemsNode .getNodeType ().equals (JsonNodeType .OBJECT )) {
3655
3682
items .setItems (getJsonSchema (itemsNode , location , result ));
@@ -3675,7 +3702,16 @@ public Schema getJsonSchema(ObjectNode node, String location, ParseResult result
3675
3702
? getJsonSchema (additionalPropertiesObject , location , result )
3676
3703
: additionalPropertiesBoolean ;
3677
3704
3678
- if (additionalProperties != null ) {
3705
+
3706
+ if (additionalProperties != null && result .isDefaultSchemaTypeObject ()) {
3707
+ if (schema == null ) {
3708
+ schema =
3709
+ additionalProperties .equals (Boolean .FALSE )
3710
+ ? new ObjectSchema ()
3711
+ : new MapSchema ();
3712
+ }
3713
+ schema .setAdditionalProperties (additionalProperties );
3714
+ }else if (additionalProperties != null ) {
3679
3715
if (schema == null ) {
3680
3716
schema = new JsonSchema ();
3681
3717
}
@@ -3751,7 +3787,9 @@ public Schema getJsonSchema(ObjectNode node, String location, ParseResult result
3751
3787
3752
3788
if (node .get ("default" ) != null ) {
3753
3789
//TODO rename method
3754
- schema .setDefault (getAnyExample ("default" ,node ,location ,result ));
3790
+ if (result .isDefaultSchemaTypeObject ()) {
3791
+ schema .setDefault (getAnyType ("default" , node , location , result ));
3792
+ }
3755
3793
}
3756
3794
3757
3795
ObjectNode discriminatorNode = getObject ("discriminator" , node , false , location , result );
@@ -4136,7 +4174,7 @@ public Schema getJsonSchema(ObjectNode node, String location, ParseResult result
4136
4174
schema .setExamples (exampleList );
4137
4175
}
4138
4176
4139
- Object example = getAnyExample ("example" , node , location , result );
4177
+ Object example = getAnyType ("example" , node , location , result );
4140
4178
if (example != null ) {
4141
4179
schema .setExample (example instanceof NullNode ? null : example );
4142
4180
}
@@ -4196,9 +4234,23 @@ public static class ParseResult {
4196
4234
private List <Location > reserved = new ArrayList <>();
4197
4235
private boolean validateInternalRefs ;
4198
4236
4237
+ private boolean defaultSchemaTypeObject = true ;
4199
4238
private boolean openapi31 = false ;
4200
4239
private boolean oaiAuthor = false ;
4201
4240
4241
+ public boolean isDefaultSchemaTypeObject () {
4242
+ return defaultSchemaTypeObject ;
4243
+ }
4244
+
4245
+ public void setDefaultSchemaTypeObject (boolean defaultSchemaTypeObject ) {
4246
+ this .defaultSchemaTypeObject = defaultSchemaTypeObject ;
4247
+ }
4248
+
4249
+ public ParseResult defaultSchemaTypeObject (boolean defaultSchemaTypeObject ) {
4250
+ this .defaultSchemaTypeObject = defaultSchemaTypeObject ;
4251
+ return this ;
4252
+ }
4253
+
4202
4254
public ParseResult () {
4203
4255
}
4204
4256
0 commit comments