@@ -1253,56 +1253,23 @@ public void testRemoveXInternalFromInlineProperties() {
12531253
12541254 @ Test
12551255 public void testSimplifyNullableOneOf () {
1256- // 1. Define the OpenAPI spec string that contains the bug pattern
1257- final String yaml =
1258- "openapi: 3.0.0\n " +
1259- "info:\n " +
1260- " version: 1.0.0\n " +
1261- " title: API\n " +
1262- "paths:\n " +
1263- " /test:\n " +
1264- " get:\n " +
1265- " responses:\n " +
1266- " '200':\n " +
1267- " description: OK\n " +
1268- " content:\n " +
1269- " application/json:\n " +
1270- " schema:\n " +
1271- " $ref: '#/components/schemas/Recipe'\n " +
1272- "components:\n " +
1273- " schemas:\n " +
1274- " Category:\n " +
1275- " type: object\n " +
1276- " properties:\n " +
1277- " name:\n " +
1278- " type: string\n " +
1279- " Recipe:\n " +
1280- " type: object\n " +
1281- " properties:\n " +
1282- " category:\n " + // This is the property with the nullable oneOf
1283- " description: 'This should become nullable'\n " +
1284- " oneOf:\n " +
1285- " - $ref: '#/components/schemas/Category'\n " +
1286- " - type: 'null'\n " ;
1287-
1288- // 2. Load the spec and run the normalizer (with default rules)
1289- final OpenAPI openAPI = TestUtils .parseSpec (yaml );
1256+ // Load from YAML file for consistency
1257+ final OpenAPI openAPI = TestUtils .parseSpec ("src/test/resources/3_0/nullable-oneof.yaml" );
1258+ // Run the normalizer
12901259 new OpenAPINormalizer (openAPI , Collections .emptyMap ()).normalize ();
1291-
1292- // 3. Get the specific schema property that should have been fixed
1260+
1261+ // Case 1: Recipe -> ref + null
12931262 Schema recipeSchema = openAPI .getComponents ().getSchemas ().get ("Recipe" );
12941263 Schema categoryProperty = (Schema ) recipeSchema .getProperties ().get ("category" );
1295-
1296- // 4. Assert that the fix worked as expected
1297- assertNotNull (categoryProperty , "The category property should not be null." );
1298-
1299- // Key Assertions:
1300- assertTrue (categoryProperty .getNullable (), "The property should be marked as nullable." );
1301- assertNull (categoryProperty .getOneOf (), "The oneOf should have been removed." );
1302- assertEquals (categoryProperty .get$ref (), "#/components/schemas/Category" , "The $ref should be preserved." );
1303-
1304- // Also check that metadata was preserved
1305- assertEquals (categoryProperty .getDescription (), "This should become nullable'" );
1264+ assertNotNull (categoryProperty );
1265+ assertTrue (categoryProperty .getNullable ());
1266+ assertNull (categoryProperty .getOneOf ());
1267+ assertEquals (categoryProperty .get$ref (), "#/components/schemas/Category" );
1268+
1269+ // Case 2: Inline object + null
1270+ Schema inline = openAPI .getComponents ().getSchemas ().get ("CategoryInline" );
1271+ assertTrue (inline .getNullable ());
1272+ assertNull (inline .getOneOf ());
13061273 }
13071274
13081275 public static class RemoveRequiredNormalizer extends OpenAPINormalizer {
0 commit comments