File tree Expand file tree Collapse file tree
modules/openapi-generator/src
main/java/org/openapitools/codegen
java/org/openapitools/codegen Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -943,7 +943,13 @@ private Schema processSimplifyOneOf(Schema schema) {
943943 if (oneOfSchemas .size () == 6 ) {
944944 TreeSet <String > ts = new TreeSet <>();
945945 for (Schema s : oneOfSchemas ) {
946- ts .add (ModelUtils .getType (s ));
946+ s = ModelUtils .getReferencedSchema (openAPI , s );
947+ String type = ModelUtils .getType (s );
948+ if (type == null ) {
949+ LOGGER .debug ("Error null type found in schema when simplifying any type with 6 sub-schemas: {}" , s );
950+ } else {
951+ ts .add (type );
952+ }
947953 }
948954
949955 if (ts .equals (anyTypeTreeSet )) {
@@ -1068,7 +1074,13 @@ private Schema processSimplifyAnyOf(Schema schema) {
10681074 if (anyOfSchemas .size () == 6 ) {
10691075 TreeSet <String > ts = new TreeSet <>();
10701076 for (Schema s : anyOfSchemas ) {
1071- ts .add (ModelUtils .getType (s ));
1077+ s = ModelUtils .getReferencedSchema (openAPI , s );
1078+ String type = ModelUtils .getType (s );
1079+ if (type == null ) {
1080+ LOGGER .debug ("Error null type found in schema when simplifying any type with 6 sub-schemas: {}" , s );
1081+ } else {
1082+ ts .add (type );
1083+ }
10721084 }
10731085
10741086 if (ts .equals (anyTypeTreeSet )) {
Original file line number Diff line number Diff line change @@ -178,6 +178,9 @@ public void testOpenAPINormalizerSimplifyOneOfAnyOf() {
178178 Schema schema13 = openAPI .getComponents ().getSchemas ().get ("OneOfAnyType" );
179179 assertEquals (schema13 .getOneOf ().size (), 6 );
180180
181+ Schema schema15 = openAPI .getComponents ().getSchemas ().get ("AnyOfAnyTypeWithRef" );
182+ assertEquals (schema15 .getAnyOf ().size (), 6 );
183+
181184 Map <String , String > options = new HashMap <>();
182185 options .put ("SIMPLIFY_ONEOF_ANYOF" , "true" );
183186 OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer (openAPI , options );
@@ -216,6 +219,9 @@ public void testOpenAPINormalizerSimplifyOneOfAnyOf() {
216219 assertEquals (schema14 .getOneOf (), null );
217220 assertEquals (schema14 .getType (), null );
218221
222+ Schema schema16 = openAPI .getComponents ().getSchemas ().get ("AnyOfAnyTypeWithRef" );
223+ assertEquals (schema16 .getAnyOf (), null );
224+ assertEquals (schema16 .getType (), null );
219225 }
220226
221227 @ Test
Original file line number Diff line number Diff line change @@ -103,6 +103,17 @@ components:
103103 - type : string
104104 - type : number
105105 - type : integer
106+ AnyOfAnyTypeWithRef :
107+ anyOf :
108+ - type : boolean
109+ - type : array
110+ items : { }
111+ - type : object
112+ - type : string
113+ - type : number
114+ - $ref : ' #/components/schemas/IntegerRef'
115+ IntegerRef :
116+ type : integer
106117 OneOfAnyType :
107118 oneOf :
108119 - type : object
You can’t perform that action at this time.
0 commit comments