@@ -740,13 +740,34 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
740
740
}
741
741
}
742
742
743
+ // also add all properties of all schemas to be checked for oneOf
744
+ Map <String , Schema > propertySchemas = new HashMap <String , Schema >();
745
+ for (Map .Entry <String , Schema > e : schemas .entrySet ()) {
746
+ Schema s = e .getValue ();
747
+ Map <String , Schema > props = s .getProperties ();
748
+ if (props == null ) {
749
+ props = new HashMap <String , Schema >();
750
+ }
751
+ for (Map .Entry <String , Schema > p : props .entrySet ()) {
752
+ propertySchemas .put (e .getKey () + "/" + p .getKey (), p .getValue ());
753
+ }
754
+ }
755
+ schemas .putAll (propertySchemas );
756
+
743
757
// go through all gathered schemas and add them as interfaces to be created
744
758
for (Map .Entry <String , Schema > e : schemas .entrySet ()) {
745
759
String n = toModelName (e .getKey ());
746
760
Schema s = e .getValue ();
747
761
String nOneOf = toModelName (n + "OneOf" );
748
762
if (ModelUtils .isComposedSchema (s )) {
749
- addOneOfNameExtension ((ComposedSchema ) s , n );
763
+ if (e .getKey ().contains ("/" )) {
764
+ // if this is property schema, we also need to generate the oneOf interface model
765
+ addOneOfNameExtension ((ComposedSchema ) s , nOneOf );
766
+ addOneOfInterfaceModel ((ComposedSchema ) s , nOneOf );
767
+ } else {
768
+ // else this is a component schema, so we will just use that as the oneOf interface model
769
+ addOneOfNameExtension ((ComposedSchema ) s , n );
770
+ }
750
771
} else if (ModelUtils .isArraySchema (s )) {
751
772
Schema items = ((ArraySchema ) s ).getItems ();
752
773
if (ModelUtils .isComposedSchema (items )) {
@@ -5717,7 +5738,8 @@ public void addOneOfInterfaceModel(ComposedSchema cs, String type) {
5717
5738
CodegenModel cm = new CodegenModel ();
5718
5739
5719
5740
cm .discriminator = createDiscriminator ("" , (Schema ) cs );
5720
- for (Schema o : cs .getOneOf ()) {
5741
+
5742
+ for (Schema o : Optional .ofNullable (cs .getOneOf ()).orElse (Collections .emptyList ())) {
5721
5743
if (o .get$ref () == null ) {
5722
5744
if (cm .discriminator != null && o .get$ref () == null ) {
5723
5745
// OpenAPI spec states that inline objects should not be considered when discriminator is used
0 commit comments