@@ -748,27 +748,16 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
748
748
}
749
749
}
750
750
751
- // also add all properties of all schemas to be checked for oneOf
752
- Map <String , Schema > propertySchemas = new HashMap <String , Schema >();
753
- for (Map .Entry <String , Schema > e : schemas .entrySet ()) {
754
- Schema s = e .getValue ();
755
- Map <String , Schema > props = s .getProperties ();
756
- if (props == null ) {
757
- props = new HashMap <String , Schema >();
758
- }
759
- for (Map .Entry <String , Schema > p : props .entrySet ()) {
760
- propertySchemas .put (e .getKey () + "/" + p .getKey (), p .getValue ());
761
- }
762
- }
763
- schemas .putAll (propertySchemas );
764
-
765
751
// go through all gathered schemas and add them as interfaces to be created
766
752
for (Map .Entry <String , Schema > e : schemas .entrySet ()) {
767
753
String n = toModelName (e .getKey ());
768
754
Schema s = e .getValue ();
769
755
String nOneOf = toModelName (n + "OneOf" );
770
756
if (ModelUtils .isComposedSchema (s )) {
771
- addOneOfForComposedSchema (e , n , (ComposedSchema ) s , nOneOf );
757
+ addOneOfNameExtension ((ComposedSchema ) s , n );
758
+ if (useOneOfInterfaces && "JavaSpring" .equals (templateDir )){
759
+ addOneOfInterfaceModel ((ComposedSchema ) s , nOneOf );
760
+ }
772
761
} else if (ModelUtils .isArraySchema (s )) {
773
762
Schema items = ((ArraySchema ) s ).getItems ();
774
763
if (ModelUtils .isComposedSchema (items )) {
@@ -786,18 +775,6 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
786
775
}
787
776
}
788
777
789
- protected void addOneOfForComposedSchema (Entry <String , Schema > stringSchemaEntry , String modelName , ComposedSchema composedSchema ,
790
- String nOneOf ) {
791
- if (stringSchemaEntry .getKey ().contains ("/" )) {
792
- // if this is property schema, we also need to generate the oneOf interface model
793
- addOneOfNameExtension (composedSchema , nOneOf );
794
- addOneOfInterfaceModel (composedSchema , nOneOf );
795
- } else {
796
- // else this is a component schema, so we will just use that as the oneOf interface model
797
- addOneOfNameExtension (composedSchema , modelName );
798
- }
799
- }
800
-
801
778
// override with any special handling of the entire OpenAPI spec document
802
779
@ SuppressWarnings ("unused" )
803
780
public void processOpenAPI (OpenAPI openAPI ) {
@@ -5764,19 +5741,15 @@ public void addOneOfNameExtension(ComposedSchema s, String name) {
5764
5741
}
5765
5742
5766
5743
/**
5767
- * Add a given ComposedSchema as an interface model to be generated, assuming it has `oneOf` defined
5744
+ * Add a given ComposedSchema as an interface model to be generated
5768
5745
* @param cs ComposedSchema object to create as interface model
5769
5746
* @param type name to use for the generated interface model
5770
5747
*/
5771
5748
public void addOneOfInterfaceModel (ComposedSchema cs , String type ) {
5772
- if (cs .getOneOf () == null ) {
5773
- return ;
5774
- }
5775
5749
CodegenModel cm = new CodegenModel ();
5776
5750
5777
5751
cm .discriminator = createDiscriminator ("" , (Schema ) cs );
5778
-
5779
- for (Schema o : Optional .ofNullable (cs .getOneOf ()).orElse (Collections .emptyList ())) {
5752
+ for (Schema o : cs .getOneOf ()) {
5780
5753
if (o .get$ref () == null ) {
5781
5754
if (cm .discriminator != null && o .get$ref () == null ) {
5782
5755
// OpenAPI spec states that inline objects should not be considered when discriminator is used
0 commit comments