55import io .swagger .v3 .oas .models .Operation ;
66import io .swagger .v3 .oas .models .PathItem ;
77import io .swagger .v3 .oas .models .Paths ;
8+ import io .swagger .v3 .oas .models .SpecVersion ;
89import io .swagger .v3 .oas .models .callbacks .Callback ;
910import io .swagger .v3 .oas .models .examples .Example ;
1011import io .swagger .v3 .oas .models .headers .Header ;
@@ -56,7 +57,7 @@ public ResolverFully(boolean aggregateCombinators) {
5657 private Map <String , Link > links ;
5758 private Map <String , Schema > resolvedProperties = new IdentityHashMap <>();
5859 private Map <String , Callback > callbacks ;
59-
60+
6061 public void resolveFully (OpenAPI openAPI ) {
6162 Components components = openAPI .getComponents ();
6263 if (components != null && components .getRequestBodies () != null ) {
@@ -85,7 +86,7 @@ public void resolveFully(OpenAPI openAPI) {
8586 if (headers == null ) {
8687 headers = new HashMap <>();
8788 }
88- }
89+ }
8990
9091 if (components != null && components .getParameters () != null ) {
9192 parameters = components .getParameters ();
@@ -243,7 +244,7 @@ public Header resolveHeader(Header header){
243244 }
244245 return header ;
245246 }
246-
247+
247248 public Link resolveLink (Link link ){
248249 RefFormat refFormat = computeRefFormat (link .get$ref ());
249250 String $ref = link .get$ref ();
@@ -272,7 +273,7 @@ public RequestBody resolveRequestBody(RequestBody requestBody){
272273 }
273274 return requestBody ;
274275 }
275-
276+
276277 public Callback resolveCallback (Callback callback ){
277278 RefFormat refFormat = computeRefFormat (callback .get$ref ());
278279 String $ref = callback .get$ref ();
@@ -379,17 +380,30 @@ public Schema resolveSchema(Schema schema) {
379380 boolean adjacent = (hasAllOf && hasAnyOf ) || (hasAllOf && hasOneOf ) || (hasAnyOf && hasOneOf );
380381
381382 if (aggregateCombinators && (hasAllOf || adjacent )) {
382- Schema combinedModel = SchemaTypeUtil .createSchema (composedSchema .getType (), composedSchema .getFormat ());
383+ Schema combinedModel = null ;
384+ if (SpecVersion .V30 .equals (composedSchema .getSpecVersion ())) {
385+ combinedModel = SchemaTypeUtil .createSchema (getSchemaType (composedSchema ), composedSchema .getFormat ());
386+ } else {
387+ combinedModel = new JsonSchema ();
388+ combinedModel .setFormat (composedSchema .getFormat ());
389+ combinedModel .setTypes (composedSchema .getTypes ());
390+ }
391+
392+ // combinedModel.setDefault(composedSchema.getDefault());
383393 Set <Object > examples = new HashSet <>();
394+ Set <Object > defaultValues = new HashSet <>();
384395
385396 if (hasAllOf ) {
386- aggregateSchemaCombinators (composedSchema , combinedModel , composedSchema .getAllOf (), examples );
397+ aggregateSchemaCombinators (composedSchema , combinedModel , composedSchema .getAllOf (), examples , defaultValues );
387398 }
388399 if (hasOneOf ) {
389- aggregateSchemaCombinators (composedSchema , combinedModel , composedSchema .getOneOf (), examples );
400+ aggregateSchemaCombinators (composedSchema , combinedModel , composedSchema .getOneOf (), examples , defaultValues );
390401 }
391402 if (hasAnyOf ) {
392- aggregateSchemaCombinators (composedSchema , combinedModel , composedSchema .getAnyOf (), examples );
403+ aggregateSchemaCombinators (composedSchema , combinedModel , composedSchema .getAnyOf (), examples , defaultValues );
404+ }
405+ if (defaultValues .size () == 1 ) {
406+ combinedModel .setDefault (defaultValues .iterator ().next ());
393407 }
394408
395409 if (schema .getExample () != null ) {
@@ -431,8 +445,12 @@ public Schema resolveSchema(Schema schema) {
431445 Schema property = updated .get (key );
432446
433447 if (property .getProperties () != model .getProperties ()) {
434- if (property .getType () == null ) {
435- property .setType ("object" );
448+ if (!hasSchemaType (property )) {
449+ if (SpecVersion .V30 .equals (property .getSpecVersion ())) {
450+ property .setType ("object" );
451+ } else {
452+ property .addType ("object" );
453+ }
436454 }
437455 model .addProperties (key , property );
438456 } else {
@@ -448,6 +466,22 @@ public Schema resolveSchema(Schema schema) {
448466 return result ;
449467 }
450468
469+ protected String getSchemaType (Schema schema ) {
470+ if (SpecVersion .V30 .equals (schema .getSpecVersion ())) {
471+ return schema .getType ();
472+ }
473+ if (schema .getTypes () != null && schema .getTypes ().size () == 1 ) {
474+ return (String )schema .getTypes ().iterator ().next ();
475+ }
476+ return null ;
477+ }
478+
479+ protected boolean hasSchemaType (Schema schema ) {
480+ if (SpecVersion .V30 .equals (schema .getSpecVersion ())) {
481+ return schema .getType () != null ;
482+ }
483+ return schema .getTypes () != null && schema .getTypes ().size () > 0 ;
484+ }
451485 public Map <String ,Example > resolveExample (Map <String ,Example > examples ){
452486
453487 Map <String ,Example > resolveExamples = examples ;
@@ -469,10 +503,9 @@ public Map<String,Example> resolveExample(Map<String,Example> examples){
469503 }
470504
471505 private void aggregateSchemaCombinators (ComposedSchema sourceSchema , Schema targetSchema ,
472- List <Schema > schemasToAggregate , Set <Object > examples ) {
506+ List <Schema > schemasToAggregate , Set <Object > examples , Set < Object > defaultValues ) {
473507
474508 Set <String > requiredProperties = new HashSet <>();
475-
476509 for (Schema innerModel : schemasToAggregate ) {
477510 Schema resolved = resolveSchema (innerModel );
478511 Map <String , Schema > properties = resolved .getProperties ();
@@ -496,12 +529,23 @@ private void aggregateSchemaCombinators(ComposedSchema sourceSchema, Schema targ
496529 if (resolved .getExample () != null ) {
497530 examples .add (resolved .getExample ());
498531 }
532+ if (sourceSchema .getDefault () != null && resolved .getDefault () == null )
533+ defaultValues .add (sourceSchema .getDefault ());
534+ else
535+ defaultValues .add (resolved .getDefault ());
536+
499537 if (resolved .getExtensions () != null ) {
500538 Map <String , Object > extensions = resolved .getExtensions ();
501539 for (String key : extensions .keySet ()) {
502540 targetSchema .addExtension (key , extensions .get (key ));
503541 }
504542 }
543+ if (sourceSchema .getExtensions () != null ) {
544+ Map <String , Object > extensions = sourceSchema .getExtensions ();
545+ for (String key : extensions .keySet ()) {
546+ targetSchema .addExtension (key , sourceSchema .getExtensions ().get (key ));
547+ }
548+ }
505549 }
506550
507551 if (requiredProperties .size () > 0 ) {
0 commit comments