@@ -1205,4 +1205,51 @@ public void doNotWrapSingleAllOfRefs() {
12051205 assertNotNull (allOfRefWithDescriptionAndReadonly .getAllOf ());
12061206 assertEquals (numberRangeRef , ((Schema ) allOfRefWithDescriptionAndReadonly .getAllOf ().get (0 )).get$ref ());
12071207 }
1208+
1209+ @ Test
1210+ public void testDeduplicationAddsAliasName () {
1211+ // Test that when inline schemas are deduplicated, the x-alias-name extension is set
1212+ OpenAPI openapi = new OpenAPI ();
1213+ openapi .setComponents (new Components ());
1214+
1215+ // Create two models with identical inline schemas that will be deduplicated
1216+ openapi .getComponents ().addSchemas ("ModelA" , new ObjectSchema ()
1217+ .addProperty ("name" , new StringSchema ())
1218+ .addProperty ("details" , new ObjectSchema ()
1219+ .addProperty ("field1" , new StringSchema ())
1220+ .addProperty ("field2" , new IntegerSchema ())));
1221+
1222+ openapi .getComponents ().addSchemas ("ModelB" , new ObjectSchema ()
1223+ .addProperty ("title" , new StringSchema ())
1224+ .addProperty ("info" , new ObjectSchema ()
1225+ .addProperty ("field1" , new StringSchema ())
1226+ .addProperty ("field2" , new IntegerSchema ())));
1227+
1228+ new InlineModelResolver ().flatten (openapi );
1229+
1230+ // Check ModelA's property reference
1231+ Schema modelA = openapi .getComponents ().getSchemas ().get ("ModelA" );
1232+ assertNotNull (modelA );
1233+ Schema detailsRef = (Schema ) modelA .getProperties ().get ("details" );
1234+ assertNotNull (detailsRef );
1235+ assertNotNull (detailsRef .get$ref ());
1236+ assertEquals ("#/components/schemas/ModelA_details" , detailsRef .get$ref ());
1237+
1238+ // Check ModelB's property reference - should be deduplicated to ModelA_details
1239+ Schema modelB = openapi .getComponents ().getSchemas ().get ("ModelB" );
1240+ assertNotNull (modelB );
1241+ Schema infoRef = (Schema ) modelB .getProperties ().get ("info" );
1242+ assertNotNull (infoRef );
1243+ assertNotNull (infoRef .get$ref ());
1244+ // The ref should point to the first schema created (ModelA_details)
1245+ assertEquals ("#/components/schemas/ModelA_details" , infoRef .get$ref ());
1246+
1247+ // Verify x-alias-name extension is set on the deduplicated reference
1248+ assertNotNull (infoRef .getExtensions ());
1249+ assertTrue (infoRef .getExtensions ().containsKey ("x-alias-name" ));
1250+ assertEquals ("ModelB_info" , infoRef .getExtensions ().get ("x-alias-name" ));
1251+
1252+ // Verify the first reference does not have x-alias-name (it's the original)
1253+ assertNull (detailsRef .getExtensions () != null ? detailsRef .getExtensions ().get ("x-alias-name" ) : null );
1254+ }
12081255}
0 commit comments