Skip to content

Commit 7d74fed

Browse files
committed
Override description of alias schema
1 parent 08da0ab commit 7d74fed

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,14 @@ public static Schema unaliasSchema(OpenAPI openAPI,
13791379
return schema;
13801380
}
13811381
Schema ref = allSchemas.get(simpleRef);
1382+
1383+
// override the description of the referenced component
1384+
if(ref != null) {
1385+
if(schema.getDescription() != null) {
1386+
ref.setDescription(schema.getDescription());
1387+
}
1388+
}
1389+
13821390
if (ref == null) {
13831391
if (!isRefToSchemaWithProperties(schema.get$ref())) {
13841392
once(LOGGER).warn("{} is not defined", schema.get$ref());

modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/ModelUtilsTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,24 @@ public void testAliasedTypeIsNotUnaliasedIfUsedForImportMapping() {
242242
Assert.assertEquals(stringSchema, ModelUtils.unaliasSchema(openAPI, emailSchema, new HashMap<>()));
243243
}
244244

245+
@Test
246+
public void testOverrideAliasedSchemaDescription() {
247+
Schema emailSchema = new Schema()
248+
.$ref("#/components/schemas/Email")
249+
.type("string")
250+
.description("description of the reference");
251+
StringSchema stringSchema = new StringSchema();
252+
stringSchema.setDescription("description of Email component");
253+
254+
HashMap<String, String> schemaMappings = new HashMap<>();
255+
schemaMappings.put("Email", "foo.bar.Email");
256+
257+
OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("Email", stringSchema);
258+
259+
var unaliasSchema = ModelUtils.unaliasSchema(openAPI, emailSchema, schemaMappings);
260+
Assert.assertEquals(unaliasSchema.getDescription(), "description of the reference");
261+
}
262+
245263
/**
246264
* Issue https://github.com/OpenAPITools/openapi-generator/issues/1624.
247265
* ModelUtils.isFreeFormObject() should not throw an NPE when passed an empty

0 commit comments

Comments
 (0)