@@ -242,6 +242,31 @@ public void testAliasedTypeIsNotUnaliasedIfUsedForImportMapping() {
242
242
Assert .assertEquals (stringSchema , ModelUtils .unaliasSchema (openAPI , emailSchema , new HashMap <>()));
243
243
}
244
244
245
+ /**
246
+ * This test verifies that nullable property is preserved when unaliasing a schema reference.
247
+ * See https://github.com/OpenAPITools/openapi-generator/issues/21612
248
+ */
249
+ @ Test
250
+ public void testNullableUnaliasedSchema () {
251
+ Schema refSchema = new Schema ().$ref ("#/components/schemas/MyString" ).nullable (true );
252
+ StringSchema myStringSchema = new StringSchema ();
253
+ OpenAPI openAPI = TestUtils .createOpenAPIWithOneSchema ("MyString" , myStringSchema );
254
+
255
+ Schema unaliased = ModelUtils .unaliasSchema (openAPI , refSchema , new HashMap <>());
256
+
257
+ Assert .assertTrue (unaliased .getNullable (), "Nullable property should be preserved after unaliasing" );
258
+ Assert .assertNotSame (unaliased , refSchema , "Unaliased schema should not be the same instance as the original reference" );
259
+
260
+ Schema refSchema2 = new Schema ().$ref ("#/components/schemas/MyString" );
261
+ StringSchema myStringSchema2 = new StringSchema ();
262
+ OpenAPI openAPI2 = TestUtils .createOpenAPIWithOneSchema ("MyString" , myStringSchema2 );
263
+
264
+ Schema unaliased2 = ModelUtils .unaliasSchema (openAPI2 , refSchema2 , new HashMap <>());
265
+
266
+ Assert .assertNull (unaliased2 .getNullable (), "Nullable property should be preserved after unaliasing" );
267
+ Assert .assertNotSame (unaliased2 , refSchema2 , "Unaliased schema should not be the same instance as the original reference" );
268
+ }
269
+
245
270
/**
246
271
* Issue https://github.com/OpenAPITools/openapi-generator/issues/1624.
247
272
* ModelUtils.isFreeFormObject() should not throw an NPE when passed an empty
0 commit comments