@@ -194,7 +194,8 @@ public SwaggerParseResult convert(SwaggerDeserializationResult parse) {
194
194
if ("body" .equals (v .getIn ())) {
195
195
components .addRequestBodies (k , convertParameterToRequestBody (v ));
196
196
} else if ("formData" .equals (v .getIn ())) {
197
- components .addRequestBodies (k , convertFormDataToRequestBody (v ));
197
+ // formData_ is added not to overwrite existing schemas
198
+ components .addSchemas ("formData_" + k , convertFormDataToSchema (v ));
198
199
} else {
199
200
components .addParameters (k , convert (v ));
200
201
}
@@ -529,6 +530,16 @@ private boolean isRefABodyParam(io.swagger.models.parameters.Parameter param) {
529
530
return false ;
530
531
}
531
532
533
+ private boolean isRefAFormParam (io .swagger .models .parameters .Parameter param ) {
534
+ if (param instanceof RefParameter ) {
535
+ RefParameter refParameter = (RefParameter ) param ;
536
+ String simpleRef = refParameter .getSimpleRef ();
537
+ io .swagger .models .parameters .Parameter parameter = globalV2Parameters .get (simpleRef );
538
+ return "formData" .equals (parameter .getIn ());
539
+ }
540
+ return false ;
541
+ }
542
+
532
543
public Operation convert (io .swagger .models .Operation v2Operation ) {
533
544
Operation operation = new Operation ();
534
545
if (StringUtils .isNotBlank (v2Operation .getDescription ())) {
@@ -555,10 +566,11 @@ public Operation convert(io.swagger.models.Operation v2Operation) {
555
566
String $ref = convert .get$ref ();
556
567
if ($ref != null && $ref .startsWith ("#/components/requestBodies/" ) && isRefABodyParam (param )) {
557
568
operation .setRequestBody (new RequestBody ().$ref ($ref ));
569
+ } else if ($ref != null && $ref .startsWith ("#/components/schemas/" ) && isRefAFormParam (param )) {
570
+ formParams .add (param );
558
571
} else {
559
572
operation .addParametersItem (convert );
560
573
}
561
- //operation.addParametersItem(convert(param));
562
574
}
563
575
}
564
576
@@ -611,8 +623,9 @@ private Map<String, Object> convert(Map<String, Object> vendorExtensions) {
611
623
return vendorExtensions ;
612
624
}
613
625
614
- private RequestBody convertFormDataToRequestBody (io .swagger .models .parameters .Parameter formParam ) {
615
- return convertFormDataToRequestBody (Arrays .asList (formParam ), null );
626
+ private Schema convertFormDataToSchema (io .swagger .models .parameters .Parameter formParam ) {
627
+ SerializableParameter sp = (SerializableParameter ) formParam ;
628
+ return convert (sp );
616
629
}
617
630
618
631
private RequestBody convertFormDataToRequestBody (List <io .swagger .models .parameters .Parameter > formParams , List <String > consumes ) {
@@ -621,73 +634,27 @@ private RequestBody convertFormDataToRequestBody(List<io.swagger.models.paramete
621
634
Schema formSchema = new Schema ();
622
635
623
636
for (io .swagger .models .parameters .Parameter param : formParams ) {
624
- SerializableParameter sp = ( SerializableParameter ) param ;
637
+ SerializableParameter sp ;
625
638
626
639
Schema schema ;
627
- if ("file" .equals (sp .getType ())) {
628
- schema = new FileSchema ();
629
- } else if ("array" .equals (sp .getType ())) {
630
- ArraySchema as = new ArraySchema ();
631
- if (sp .getItems () != null ) {
632
- as .setItems (convert (sp .getItems ()));
633
- }
634
- schema = as ;
640
+ String name ;
641
+ if (param instanceof RefParameter ) {
642
+ RefParameter refParameter = (RefParameter ) param ;
643
+ String simpleRef = refParameter .getSimpleRef ();
644
+ sp = (SerializableParameter ) globalV2Parameters .get (simpleRef );
645
+ name = components .getSchemas ().get ("formData_" + simpleRef ).getName ();
646
+ schema = new Schema ().$ref ("#/components/schemas/formData_" + simpleRef );
635
647
} else {
636
- schema = new Schema ();
637
- schema .setType (sp .getType ());
638
- schema .setFormat (sp .getFormat ());
639
- }
640
-
641
- schema .setDescription (sp .getDescription ());
642
- schema .setReadOnly (sp .isReadOnly ());
643
- schema .setEnum (sp .getEnum ());
644
-
645
- if (sp .getMaxItems () != null ) {
646
- schema .setMaxItems (sp .getMaxItems ());
647
- }
648
- if (sp .getMinItems () != null ) {
649
- schema .setMinItems (sp .getMinItems ());
650
- }
651
- if (sp .isUniqueItems () != null ) {
652
- schema .setUniqueItems (sp .isUniqueItems ());
653
- }
654
-
655
- schema .setMaximum (sp .getMaximum ());
656
- schema .setExclusiveMaximum (sp .isExclusiveMaximum ());
657
- schema .setMinimum (sp .getMinimum ());
658
- schema .setExclusiveMinimum (sp .isExclusiveMinimum ());
659
- schema .setMinLength (sp .getMinLength ());
660
- schema .setMaxLength (sp .getMaxLength ());
661
-
662
- if (sp .getVendorExtensions () != null ) {
663
- Object exampleExtension = sp .getVendorExtensions ().get ("x-example" );
664
- if (exampleExtension != null ) {
665
- schema .setExample (exampleExtension );
666
- }
667
- Object nullableExtension = sp .getVendorExtensions ().get ("x-nullable" );
668
- if (nullableExtension != null ) {
669
- schema .setNullable ((Boolean ) nullableExtension );
670
- }
671
- schema .setExtensions (convert (sp .getVendorExtensions ()));
672
- }
673
-
674
- if (sp .getMultipleOf () != null ) {
675
- schema .setMultipleOf (new BigDecimal (sp .getMultipleOf ().toString ()));
676
- }
677
-
678
- schema .setPattern (sp .getPattern ());
679
- schema .setExtensions (convert (sp .getVendorExtensions ()));
680
-
681
- if (sp instanceof AbstractSerializableParameter ) {
682
- AbstractSerializableParameter ap = (AbstractSerializableParameter ) sp ;
683
- schema .setDefault (ap .getDefault ());
648
+ sp = (SerializableParameter ) param ;
649
+ schema = convert (sp );
650
+ name = schema .getName ();
684
651
}
685
652
686
653
if (sp .getRequired ()) {
687
654
formSchema .addRequiredItem (sp .getName ());
688
655
}
689
656
690
- formSchema .addProperties (param . getName () , schema );
657
+ formSchema .addProperties (name , schema );
691
658
}
692
659
693
660
List <String > mediaTypes = new ArrayList <>(globalConsumes );
@@ -709,6 +676,69 @@ private RequestBody convertFormDataToRequestBody(List<io.swagger.models.paramete
709
676
return body ;
710
677
}
711
678
679
+ private Schema convert (SerializableParameter sp ) {
680
+ Schema schema ;
681
+ if ("file" .equals (sp .getType ())) {
682
+ schema = new FileSchema ();
683
+ } else if ("array" .equals (sp .getType ())) {
684
+ ArraySchema as = new ArraySchema ();
685
+ if (sp .getItems () != null ) {
686
+ as .setItems (convert (sp .getItems ()));
687
+ }
688
+ schema = as ;
689
+ } else {
690
+ schema = new Schema ();
691
+ schema .setType (sp .getType ());
692
+ schema .setFormat (sp .getFormat ());
693
+ }
694
+
695
+ schema .setDescription (sp .getDescription ());
696
+ schema .setReadOnly (sp .isReadOnly ());
697
+ schema .setEnum (sp .getEnum ());
698
+
699
+ if (sp .getMaxItems () != null ) {
700
+ schema .setMaxItems (sp .getMaxItems ());
701
+ }
702
+ if (sp .getMinItems () != null ) {
703
+ schema .setMinItems (sp .getMinItems ());
704
+ }
705
+ if (sp .isUniqueItems () != null ) {
706
+ schema .setUniqueItems (sp .isUniqueItems ());
707
+ }
708
+
709
+ schema .setMaximum (sp .getMaximum ());
710
+ schema .setExclusiveMaximum (sp .isExclusiveMaximum ());
711
+ schema .setMinimum (sp .getMinimum ());
712
+ schema .setExclusiveMinimum (sp .isExclusiveMinimum ());
713
+ schema .setMinLength (sp .getMinLength ());
714
+ schema .setMaxLength (sp .getMaxLength ());
715
+ schema .setName (sp .getName ());
716
+
717
+ if (sp .getVendorExtensions () != null ) {
718
+ Object exampleExtension = sp .getVendorExtensions ().get ("x-example" );
719
+ if (exampleExtension != null ) {
720
+ schema .setExample (exampleExtension );
721
+ }
722
+ Object nullableExtension = sp .getVendorExtensions ().get ("x-nullable" );
723
+ if (nullableExtension != null ) {
724
+ schema .setNullable ((Boolean ) nullableExtension );
725
+ }
726
+ schema .setExtensions (convert (sp .getVendorExtensions ()));
727
+ }
728
+
729
+ if (sp .getMultipleOf () != null ) {
730
+ schema .setMultipleOf (new BigDecimal (sp .getMultipleOf ().toString ()));
731
+ }
732
+
733
+ schema .setPattern (sp .getPattern ());
734
+
735
+ if (sp instanceof AbstractSerializableParameter ) {
736
+ AbstractSerializableParameter ap = (AbstractSerializableParameter ) sp ;
737
+ schema .setDefault (ap .getDefault ());
738
+ }
739
+ return schema ;
740
+ }
741
+
712
742
private RequestBody convertParameterToRequestBody (io .swagger .models .parameters .Parameter param ) {
713
743
return convertParameterToRequestBody (param , null );
714
744
}
@@ -957,6 +987,8 @@ public Parameter convert(io.swagger.models.parameters.Parameter v2Parameter) {
957
987
if (components .getRequestBodies () != null &&
958
988
components .getRequestBodies ().get (ref .getSimpleRef ()) != null ) {
959
989
updatedRef += "requestBodies" ;
990
+ } else if (components .getSchemas () != null && components .getSchemas ().get ("formData_" + ref .getSimpleRef ()) != null ) {
991
+ updatedRef += "schemas" ;
960
992
} else {
961
993
updatedRef += "parameters" ;
962
994
}
0 commit comments