4343
4444public class OpenAPINormalizerTest {
4545
46+ private static final String SIMPLIFY_ONE_OF_ANY_OF = "SIMPLIFY_ONEOF_ANYOF" ;
47+ private static final String SIMPLIFY_ONEOF_ANYOF_ENUM = "SIMPLIFY_ONEOF_ANYOF_ENUM" ;
4648 private static final String REF_AS_PARENT_IN_ALLOF = "REF_AS_PARENT_IN_ALLOF" ;
4749 private static final String X_PARENT = "x-parent" ;
4850 private static final String X_INTERNAL = "x-internal" ;
@@ -210,7 +212,7 @@ public void testSimplifyOneOfAnyOfEnum() throws Exception {
210212
211213 // Test with rule enabled (default)
212214 Map <String , String > options = new HashMap <>();
213- options .put (" SIMPLIFY_ONEOF_ANYOF_ENUM" , "true" );
215+ options .put (SIMPLIFY_ONEOF_ANYOF_ENUM , "true" );
214216 OpenAPINormalizer normalizer = new OpenAPINormalizer (openAPI , options );
215217 normalizer .normalize ();
216218
@@ -248,7 +250,7 @@ public void testSimplifyOneOfAnyOfEnum() throws Exception {
248250 // Test with rule disabled
249251 OpenAPI openAPI2 = TestUtils .parseSpec ("src/test/resources/3_0/simplifyOneOfWithEnums_test.yaml" );
250252 Map <String , String > options2 = new HashMap <>();
251- options2 .put (" SIMPLIFY_ONEOF_ANYOF_ENUM" , "false" );
253+ options2 .put (SIMPLIFY_ONEOF_ANYOF_ENUM , "false" );
252254 OpenAPINormalizer normalizer2 = new OpenAPINormalizer (openAPI2 , options2 );
253255 normalizer2 .normalize ();
254256
@@ -312,7 +314,7 @@ public void testOpenAPINormalizerSimplifyOneOfAnyOf() {
312314 assertEquals (schema19 .getAnyOf ().size (), 1 );
313315
314316 Map <String , String > options = new HashMap <>();
315- options .put ("SIMPLIFY_ONEOF_ANYOF" , "true" );
317+ options .put (SIMPLIFY_ONE_OF_ANY_OF , "true" );
316318 OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer (openAPI , options );
317319 openAPINormalizer .normalize ();
318320
@@ -370,7 +372,7 @@ public void testOpenAPINormalizerSimplifyOneOfWithSingleRef() {
370372 assertEquals (((Schema ) oneOfWithSingleRef .getProperties ().get ("number" )).getOneOf ().size (), 1 );
371373
372374 Map <String , String > options = new HashMap <>();
373- options .put ("SIMPLIFY_ONEOF_ANYOF" , "true" );
375+ options .put (SIMPLIFY_ONE_OF_ANY_OF , "true" );
374376 OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer (openAPI , options );
375377 openAPINormalizer .normalize ();
376378
@@ -511,7 +513,7 @@ public void testOpenAPINormalizerConvertEnumNullToNullable() {
511513 assertNull (schema .getNullable ());
512514
513515 Map <String , String > options = new HashMap <>();
514- options .put ("SIMPLIFY_ONEOF_ANYOF" , "true" );
516+ options .put (SIMPLIFY_ONE_OF_ANY_OF , "true" );
515517 OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer (openAPI , options );
516518 openAPINormalizer .normalize ();
517519
@@ -1539,7 +1541,7 @@ public void testOpenAPINormalizerSimplifyOneOfAnyOf31Spec() {
15391541
15401542 // start the normalization
15411543 Map <String , String > options = new HashMap <>();
1542- options .put ("SIMPLIFY_ONEOF_ANYOF" , "true" );
1544+ options .put (SIMPLIFY_ONE_OF_ANY_OF , "true" );
15431545 OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer (openAPI , options );
15441546 openAPINormalizer .normalize ();
15451547
@@ -1613,6 +1615,40 @@ public void testOpenAPINormalizerSimplifyOneOfAnyOf31Spec() {
16131615 assertEquals (((Schema ) schema24 .getProperties ().get ("anyof_nullable_number" )).getTypes ().size (), 1 );
16141616 }
16151617
1618+ @ Test
1619+ public void testOneOfWithStringsWithDifferentPatternsAreCollapsedWithSimplifyOneOfAnyOf () {
1620+ OpenAPI openAPI = TestUtils .parseSpec ("src/test/resources/3_1/simplifyOneOfAnyOf_test.yaml" );
1621+
1622+ Schema stringPatternsWithOneOf = openAPI .getComponents ().getSchemas ().get ("StringPatternsWithOneOf" );
1623+ assertEquals (stringPatternsWithOneOf .getOneOf ().size (), 2 );
1624+
1625+ // start the normalization
1626+ Map <String , String > options = new HashMap <>();
1627+ options .put (SIMPLIFY_ONE_OF_ANY_OF , "true" );
1628+ OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer (openAPI , options );
1629+ openAPINormalizer .normalize ();
1630+
1631+ Schema normalizedStringPatternsWithOneOf = openAPI .getComponents ().getSchemas ().get ("StringPatternsWithOneOf" );
1632+ assertNull (normalizedStringPatternsWithOneOf .getOneOf ());
1633+ }
1634+
1635+ @ Test
1636+ public void testOneOfWithConstsIsUntouchedBySimplifyOneOfAnyOf () {
1637+ OpenAPI openAPI = TestUtils .parseSpec ("src/test/resources/3_1/simplifyOneOfAnyOf_test.yaml" );
1638+
1639+ Schema integerWithOneOfConsts = openAPI .getComponents ().getSchemas ().get ("TypeIntegerWithOneOf" );
1640+ assertEquals (integerWithOneOfConsts .getOneOf ().size (), 3 );
1641+
1642+ // start the normalization
1643+ Map <String , String > options = new HashMap <>();
1644+ options .put (SIMPLIFY_ONEOF_ANYOF_ENUM , "false" );
1645+ OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer (openAPI , options );
1646+ openAPINormalizer .normalize ();
1647+
1648+ Schema normalizedIntegerWithOneOfConsts = openAPI .getComponents ().getSchemas ().get ("TypeIntegerWithOneOf" );
1649+ assertEquals (normalizedIntegerWithOneOfConsts .getOneOf ().size (), 3 );
1650+ }
1651+
16161652 @ Test
16171653 public void testOpenAPINormalizerSimplifyOneOfWithSingleRef31Spec () {
16181654 OpenAPI openAPI = TestUtils .parseSpec ("src/test/resources/3_1/simplifyOneOfAnyOf_test.yaml" );
@@ -1621,7 +1657,7 @@ public void testOpenAPINormalizerSimplifyOneOfWithSingleRef31Spec() {
16211657 assertEquals (((Schema ) oneOfWithSingleRef .getProperties ().get ("number" )).getOneOf ().size (), 1 );
16221658
16231659 Map <String , String > options = new HashMap <>();
1624- options .put ("SIMPLIFY_ONEOF_ANYOF" , "true" );
1660+ options .put (SIMPLIFY_ONE_OF_ANY_OF , "true" );
16251661 OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer (openAPI , options );
16261662 openAPINormalizer .normalize ();
16271663
0 commit comments