@@ -38,6 +38,8 @@ public class OpenAPINormalizer {
3838 private Map <String , String > inputRules = new HashMap <>();
3939 private Map <String , Boolean > rules = new HashMap <>();
4040
41+ private TreeSet <String > anyTypeTreeSet = new TreeSet <>();
42+
4143 final Logger LOGGER = LoggerFactory .getLogger (OpenAPINormalizer .class );
4244
4345 Set <String > ruleNames = new TreeSet <>();
@@ -160,6 +162,14 @@ public OpenAPINormalizer(OpenAPI openAPI, Map<String, String> inputRules) {
160162 rules .put (SIMPLIFY_BOOLEAN_ENUM , true );
161163
162164 processRules (inputRules );
165+
166+ // represent any type in tree set
167+ anyTypeTreeSet .add ("string" );
168+ anyTypeTreeSet .add ("number" );
169+ anyTypeTreeSet .add ("integer" );
170+ anyTypeTreeSet .add ("boolean" );
171+ anyTypeTreeSet .add ("object" );
172+ anyTypeTreeSet .add ("array" );
163173 }
164174
165175 /**
@@ -922,6 +932,27 @@ private Schema processSimplifyOneOf(Schema schema) {
922932
923933 List <Schema > oneOfSchemas = schema .getOneOf ();
924934 if (oneOfSchemas != null ) {
935+ // simplify any type with 6 sub-schemas (string, integer, etc) in oneOf
936+ if (oneOfSchemas .size () == 6 ) {
937+ TreeSet <String > ts = new TreeSet <>();
938+ for (Schema s : oneOfSchemas ) {
939+ ts .add (s .getType ());
940+ }
941+
942+ if (ts .equals (anyTypeTreeSet )) {
943+ Schema anyType = new Schema ();
944+ anyType .setDescription (schema .getDescription ());
945+ anyType .setNullable (schema .getNullable ());
946+ anyType .setExtensions (schema .getExtensions ());
947+ anyType .setTitle (schema .getTitle ());
948+ anyType .setExample (schema .getExample ());
949+ anyType .setExamples (schema .getExamples ());
950+ anyType .setDefault (schema .getDefault ());
951+ anyType .setDeprecated (schema .getDeprecated ());
952+ return anyType ;
953+ }
954+ }
955+
925956 if (oneOfSchemas .removeIf (oneOf -> isNullTypeSchema (oneOf ))) {
926957 schema .setNullable (true );
927958
@@ -1026,6 +1057,27 @@ private Schema processSimplifyAnyOf(Schema schema) {
10261057
10271058 List <Schema > anyOfSchemas = schema .getAnyOf ();
10281059 if (anyOfSchemas != null ) {
1060+ // simplify any type with 6 sub-schemas (string, integer, etc) in anyOf
1061+ if (anyOfSchemas .size () == 6 ) {
1062+ TreeSet <String > ts = new TreeSet <>();
1063+ for (Schema s : anyOfSchemas ) {
1064+ ts .add (s .getType ());
1065+ }
1066+
1067+ if (ts .equals (anyTypeTreeSet )) {
1068+ Schema anyType = new Schema ();
1069+ anyType .setDescription (schema .getDescription ());
1070+ anyType .setNullable (schema .getNullable ());
1071+ anyType .setExtensions (schema .getExtensions ());
1072+ anyType .setTitle (schema .getTitle ());
1073+ anyType .setExample (schema .getExample ());
1074+ anyType .setExamples (schema .getExamples ());
1075+ anyType .setDefault (schema .getDefault ());
1076+ anyType .setDeprecated (schema .getDeprecated ());
1077+ return anyType ;
1078+ }
1079+ }
1080+
10291081 if (anyOfSchemas .removeIf (anyOf -> isNullTypeSchema (anyOf ))) {
10301082 schema .setNullable (true );
10311083 }
0 commit comments