@@ -670,7 +670,10 @@ public void addOneOfInterfaceModel(ComposedSchema cs, String name) {
670
670
cm .interfaceModels = new ArrayList <CodegenModel >();
671
671
672
672
for (Schema schema : cs .getOneOf ()){
673
- cm .vars .add (fromProperty ("property" , schema ));
673
+ String singleSchemaType = getSingleSchemaType (schema );
674
+ CodegenProperty codegenProperty = fromProperty (singleSchemaType , schema );
675
+ codegenProperty .setBaseName (singleSchemaType .toLowerCase (Locale .getDefault ()));
676
+ cm .vars .add (codegenProperty );
674
677
}
675
678
addOneOfInterfaces .add (cm );
676
679
}
@@ -721,9 +724,12 @@ public void addFromInterfaceModel(CodegenModel cm, List<Map<String, String>> mod
721
724
omitAdding .add (v .baseName );
722
725
}
723
726
}
724
- for (CodegenProperty v : toAdd ) {
725
- if (!omitAdding .contains (v .baseName )) {
726
- additionalProps .add (v .clone ());
727
+ for (int i = 0 ; i < toAdd .size (); i ++) {
728
+ if (!omitAdding .contains (toAdd .get (i ).baseName )) {
729
+ if (i != toAdd .size () - 1 ) {
730
+ toAdd .get (i ).hasMore = true ;
731
+ }
732
+ additionalProps .add (toAdd .get (i ));
727
733
}
728
734
}
729
735
@@ -734,46 +740,8 @@ public void addFromInterfaceModel(CodegenModel cm, List<Map<String, String>> mod
734
740
}
735
741
}
736
742
737
- public void addToImplementor (CodegenModel implcm , List <Map <String , String >> implImports ) {
738
- implcm .getVendorExtensions ().putIfAbsent ("implements" , new ArrayList <String >());
739
-
740
- // Add implemented interfaces
741
- for (String intf : additionalInterfaces ) {
742
- List <String > impl = (List <String >) implcm .getVendorExtensions ().get ("implements" );
743
- impl .add (intf );
744
- // Add imports for interfaces
745
- implcm .imports .add (intf );
746
- Map <String , String > importsItem = new HashMap <String , String >();
747
- importsItem .put ("import" , toModelImport (intf ));
748
- implImports .add (importsItem );
749
- }
750
-
751
- // Add oneOf-containing models properties - we need to properly set the hasMore values to make renderind correct
752
- if (implcm .vars .size () > 0 && additionalProps .size () > 0 ) {
753
- implcm .vars .get (implcm .vars .size () - 1 ).hasMore = true ;
754
- }
755
- for (int i = 0 ; i < additionalProps .size (); i ++) {
756
- CodegenProperty var = additionalProps .get (i );
757
- if (i == additionalProps .size () - 1 ) {
758
- var .hasMore = false ;
759
- } else {
760
- var .hasMore = true ;
761
- }
762
- implcm .vars .add (var );
763
- }
764
-
765
- // Add imports
766
- for (Map <String , String > oneImport : additionalImports ) {
767
- // exclude imports from this package - these are imports that only the oneOf interface needs
768
- if (!implImports .contains (oneImport ) && !oneImport .getOrDefault ("import" , "" ).startsWith (modelPackage ())) {
769
- implImports .add (oneImport );
770
- }
771
- }
772
- }
773
743
}
774
744
775
-
776
-
777
745
@ Override
778
746
public Map <String , Object > postProcessAllModels (Map <String , Object > objs ) {
779
747
objs = super .postProcessAllModels (objs );
@@ -821,7 +789,7 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
821
789
if (cm .oneOf .size () > 0 ) {
822
790
cm .vendorExtensions .put ("isOneOfInterface" , true );
823
791
// if this is oneOf interface, make sure we include the necessary jackson imports for it
824
- for (String s : Arrays .asList ("JsonTypeInfo" , "JsonSubTypes" )) {
792
+ for (String s : Arrays .asList ("JsonTypeInfo" , "JsonSubTypes" , "JsonProperty" , "ApiModelProperty" )) {
825
793
Map <String , String > i = new HashMap <String , String >() {{
826
794
put ("import" , importMapping .get (s ));
827
795
}};
@@ -849,6 +817,8 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S
849
817
Schema schema = ModelUtils .getSchemaFromRequestBody (body );
850
818
CodegenProperty codegenProperty = fromProperty ("property" , schema );
851
819
if (codegenProperty != null && codegenProperty .getComplexType () != null && schema instanceof ComposedSchema ) {
820
+ // will be set with imports.add(codegenParameter.baseType); in defaultcodegen
821
+ imports .remove ("UNKNOWN_BASE_TYPE" );
852
822
String codegenModelName = codegenProperty .getComplexType ();
853
823
codegenParameter .baseName = codegenModelName ;
854
824
codegenParameter .paramName = toParamName (codegenParameter .baseName );
0 commit comments