Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,14 @@ public static Schema unaliasSchema(OpenAPI openAPI,
return schema;
}
Schema ref = allSchemas.get(simpleRef);

// override the description of the referenced component
if(ref != null) {
if(schema.getDescription() != null) {
ref.setDescription(schema.getDescription());
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the fix

but this change will permanently update the description of the reference schema.

if the reference schema is used somewhere else, the description will be the overridden one instead of the original one.

i think a better way to fix it is in the fromProperty in default codegen. or maybe using normalizer to fix it.

I'll try to find time to come up with a fix later this week

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fromProperty what do you mean? Please clarify, maybe I can update the approach

if (ref == null) {
if (!isRefToSchemaWithProperties(schema.get$ref())) {
once(LOGGER).warn("{} is not defined", schema.get$ref());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,33 @@ public void testUseErasableSyntaxConfig() throws IOException {
}
}
}

@Test
public void testRefDescription() throws Exception {
final File output = Files.createTempDirectory("typescriptnodeclient_").toFile();
output.deleteOnExit();

final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("typescript")
.setInputSpec("src/test/resources/3_0/typescript/ref-description.yaml")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));

final ClientOptInput clientOptInput = configurator.toClientOptInput();
final DefaultGenerator generator = new DefaultGenerator();
final List<File> files = generator.opts(clientOptInput).generate();
files.forEach(File::deleteOnExit);

Path file = Paths.get(output + "/models/PetUpdateRequest.ts");
// verify ref description is found
TestUtils.assertFileContains(
file,
"Reference description of Date schema"
);
// verify component description is not present
TestUtils.assertFileNotContains(
file,
"Component description of Date schema"
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,24 @@ public void testAliasedTypeIsNotUnaliasedIfUsedForImportMapping() {
Assert.assertEquals(stringSchema, ModelUtils.unaliasSchema(openAPI, emailSchema, new HashMap<>()));
}

@Test
public void testOverrideAliasedSchemaDescription() {
Schema emailSchema = new Schema()
.$ref("#/components/schemas/Email")
.type("string")
.description("description of the reference");
StringSchema stringSchema = new StringSchema();
stringSchema.setDescription("description of Email component");

HashMap<String, String> schemaMappings = new HashMap<>();
schemaMappings.put("Email", "foo.bar.Email");

OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("Email", stringSchema);

var unaliasSchema = ModelUtils.unaliasSchema(openAPI, emailSchema, schemaMappings);
Assert.assertEquals(unaliasSchema.getDescription(), "description of the reference");
}

/**
* Issue https://github.com/OpenAPITools/openapi-generator/issues/1624.
* ModelUtils.isFreeFormObject() should not throw an NPE when passed an empty
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
openapi: 3.1.0
info:
description: test order parameters
version: 1.0.0
title: Test order parameters
license:
name: Apache-2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'

paths:
/pets:
get:
tags:
- default
summary: Finds Pets
deprecated: true
description: Find all pets
operationId: findPets
parameters:
- name: type
in: query
description: type of pet
style: form
explode: false
schema:
type: string
default: available
- name: name
in: query
description: name of pet
required: true
schema:
type: string
- name: age
in: query
description: age of pet
schema:
type: number
format: int32
responses:
'200':
description: successful operation
'400':
description: Invalid status value

patch:
tags:
- default
summary: Update a Pet
description: Partially update an existing pet
operationId: updatePet
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/PetUpdateRequest'
responses:
'200':
description: Pet updated successfully
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid input
'404':
description: Pet not found

components:
schemas:
PetUpdateRequest:
type: object
description: Payload for updating a pet
properties:
name:
type: string
description: New name for the pet
age:
type: integer
format: int32
description: Updated age
type:
type: string
description: Type of pet
date:
$ref: "#/components/schemas/Date"
description: Reference description of Date schema
required:
- name

Pet:
type: object
description: Pet object
properties:
id:
type: integer
format: int64
name:
type: string
age:
type: integer
format: int32
type:
type: string

Date:
type: string
format: date
description: Component description of Date schema

Loading