@@ -1266,36 +1266,90 @@ public void testRemoveXInternalFromInlineProperties() {
12661266 OpenAPI openAPI = TestUtils .parseSpec ("src/test/resources/3_0/inline_x_internal_test.yaml" );
12671267 Schema parentSchema = openAPI .getComponents ().getSchemas ().get ("ParentSchema" );
12681268 Schema inlineProperty = (Schema ) parentSchema .getProperties ().get ("inlineXInternalProperty" );
1269-
1269+
12701270 // Before normalization: x-internal should be present on inline property
12711271 assertNotNull (inlineProperty .getExtensions ());
12721272 assertEquals (inlineProperty .getExtensions ().get ("x-internal" ), true );
1273-
1273+
12741274 // Run normalizer with REMOVE_X_INTERNAL=true
12751275 Map <String , String > options = new HashMap <>();
12761276 options .put ("REMOVE_X_INTERNAL" , "true" );
12771277 OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer (openAPI , options );
12781278 openAPINormalizer .normalize ();
1279-
1279+
12801280 // After normalization: x-internal should be removed from inline property
12811281 Schema parentSchemaAfter = openAPI .getComponents ().getSchemas ().get ("ParentSchema" );
12821282 Schema inlinePropertyAfter = (Schema ) parentSchemaAfter .getProperties ().get ("inlineXInternalProperty" );
1283-
1283+
12841284 // x-internal extension should be removed (null or not present in map)
12851285 if (inlinePropertyAfter .getExtensions () != null ) {
12861286 assertNull (inlinePropertyAfter .getExtensions ().get ("x-internal" ));
12871287 }
1288-
1288+
12891289 // The property itself should still exist (we're removing the flag, not the property)
12901290 assertNotNull (inlinePropertyAfter );
12911291 assertEquals (inlinePropertyAfter .getType (), "object" );
1292-
1292+
12931293 // Nested properties should still exist
12941294 assertNotNull (inlinePropertyAfter .getProperties ());
12951295 assertNotNull (inlinePropertyAfter .getProperties ().get ("nestedField" ));
12961296 assertNotNull (inlinePropertyAfter .getProperties ().get ("nestedNumber" ));
12971297 }
12981298
1299+ /**
1300+ * Test oneOf items with only title (discriminator label) are NOT wrapped in allOf
1301+ */
1302+ @ Test
1303+ public void testOneOfWithOnlyTitleDoesNotNormalize () {
1304+ OpenAPI openAPI = TestUtils .parseSpec ("src/test/resources/3_1/oneOf.yaml" );
1305+
1306+ Schema fruitSchema = openAPI .getComponents ().getSchemas ().get ("fruit" );
1307+ assertNotNull (fruitSchema .getOneOf ());
1308+ assertEquals (fruitSchema .getOneOf ().size (), 3 );
1309+
1310+ Schema item1Before = (Schema ) fruitSchema .getOneOf ().get (0 );
1311+ assertEquals (item1Before .get$ref (), "#/components/schemas/apple" );
1312+ assertNull (item1Before .getAllOf ());
1313+
1314+ OpenAPINormalizer normalizer = new OpenAPINormalizer (openAPI , new HashMap <>());
1315+ normalizer .normalize ();
1316+
1317+ Schema normalizedFruit = openAPI .getComponents ().getSchemas ().get ("fruit" );
1318+ assertNotNull (normalizedFruit .getOneOf ());
1319+ assertEquals (normalizedFruit .getOneOf ().size (), 3 );
1320+
1321+ Schema normalizedItem1 = (Schema ) normalizedFruit .getOneOf ().get (0 );
1322+ assertEquals (normalizedItem1 .get$ref (), "#/components/schemas/apple" );
1323+ assertNull (normalizedItem1 .getAllOf ());
1324+ }
1325+
1326+ /**
1327+ * Test anyOf items with only title (discriminator label) are NOT wrapped in allOf
1328+ */
1329+ @ Test
1330+ public void testAnyOfWithOnlyTitleDoesNotNormalize () {
1331+ OpenAPI openAPI = TestUtils .parseSpec ("src/test/resources/3_1/anyOf.yaml" );
1332+
1333+ Schema fruitSchema = openAPI .getComponents ().getSchemas ().get ("fruit" );
1334+ assertNotNull (fruitSchema .getAnyOf ());
1335+ assertEquals (fruitSchema .getAnyOf ().size (), 2 );
1336+
1337+ Schema item1Before = (Schema ) fruitSchema .getAnyOf ().get (0 );
1338+ assertEquals (item1Before .get$ref (), "#/components/schemas/apple" );
1339+ assertNull (item1Before .getAllOf ());
1340+
1341+ OpenAPINormalizer normalizer = new OpenAPINormalizer (openAPI , new HashMap <>());
1342+ normalizer .normalize ();
1343+
1344+ Schema normalizedFruit = openAPI .getComponents ().getSchemas ().get ("fruit" );
1345+ assertNotNull (normalizedFruit .getAnyOf ());
1346+ assertEquals (normalizedFruit .getAnyOf ().size (), 2 );
1347+
1348+ Schema normalizedItem1 = (Schema ) normalizedFruit .getAnyOf ().get (0 );
1349+ assertEquals (normalizedItem1 .get$ref (), "#/components/schemas/apple" );
1350+ assertNull (normalizedItem1 .getAllOf ());
1351+ }
1352+
12991353 public static class RemoveRequiredNormalizer extends OpenAPINormalizer {
13001354
13011355 public RemoveRequiredNormalizer (OpenAPI openAPI , Map <String , String > inputRules ) {
0 commit comments