@@ -744,13 +744,34 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
744
744
}
745
745
}
746
746
747
+ // also add all properties of all schemas to be checked for oneOf
748
+ Map <String , Schema > propertySchemas = new HashMap <String , Schema >();
749
+ for (Map .Entry <String , Schema > e : schemas .entrySet ()) {
750
+ Schema s = e .getValue ();
751
+ Map <String , Schema > props = s .getProperties ();
752
+ if (props == null ) {
753
+ props = new HashMap <String , Schema >();
754
+ }
755
+ for (Map .Entry <String , Schema > p : props .entrySet ()) {
756
+ propertySchemas .put (e .getKey () + "/" + p .getKey (), p .getValue ());
757
+ }
758
+ }
759
+ schemas .putAll (propertySchemas );
760
+
747
761
// go through all gathered schemas and add them as interfaces to be created
748
762
for (Map .Entry <String , Schema > e : schemas .entrySet ()) {
749
763
String n = toModelName (e .getKey ());
750
764
Schema s = e .getValue ();
751
765
String nOneOf = toModelName (n + "OneOf" );
752
766
if (ModelUtils .isComposedSchema (s )) {
753
- addOneOfNameExtension ((ComposedSchema ) s , n );
767
+ if (e .getKey ().contains ("/" )) {
768
+ // if this is property schema, we also need to generate the oneOf interface model
769
+ addOneOfNameExtension ((ComposedSchema ) s , nOneOf );
770
+ addOneOfInterfaceModel ((ComposedSchema ) s , nOneOf );
771
+ } else {
772
+ // else this is a component schema, so we will just use that as the oneOf interface model
773
+ addOneOfNameExtension ((ComposedSchema ) s , n );
774
+ }
754
775
} else if (ModelUtils .isArraySchema (s )) {
755
776
Schema items = ((ArraySchema ) s ).getItems ();
756
777
if (ModelUtils .isComposedSchema (items )) {
@@ -5726,15 +5747,19 @@ public void addOneOfNameExtension(ComposedSchema s, String name) {
5726
5747
}
5727
5748
5728
5749
/**
5729
- * Add a given ComposedSchema as an interface model to be generated
5750
+ * Add a given ComposedSchema as an interface model to be generated, assuming it has `oneOf` defined
5730
5751
* @param cs ComposedSchema object to create as interface model
5731
5752
* @param type name to use for the generated interface model
5732
5753
*/
5733
5754
public void addOneOfInterfaceModel (ComposedSchema cs , String type ) {
5755
+ if (cs .getOneOf () == null ) {
5756
+ return ;
5757
+ }
5734
5758
CodegenModel cm = new CodegenModel ();
5735
5759
5736
5760
cm .discriminator = createDiscriminator ("" , (Schema ) cs );
5737
- for (Schema o : cs .getOneOf ()) {
5761
+
5762
+ for (Schema o : Optional .ofNullable (cs .getOneOf ()).orElse (Collections .emptyList ())) {
5738
5763
if (o .get$ref () == null ) {
5739
5764
if (cm .discriminator != null && o .get$ref () == null ) {
5740
5765
// OpenAPI spec states that inline objects should not be considered when discriminator is used
0 commit comments