OpenAPITools / OpenAPITools/openapi-generator
[BUG] Generator ignores description of schema properties that has a $ref
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
If a schema has a property that is defined using a $ref, any metadata for that property is ignored.
For example, if the property has a description in the specification, that description is ignored.
In the output, the file:
.\repro_openapi\src\main\java\org\openapitools\client\model\Struct1.java
Actual:
/**
* Get field1
* @return field1
**/
@javax.annotation.Nullable
public Struct2 getField1() {
return field1;
}
Expected:
/**
* F1
* @return field1
**/
@javax.annotation.Nullable
public Struct2 getField1() {
return field1;
}
openapi-generator version
7.0, 7.1.0-20230918.095628-1, 8.0.0-20231011.125706-1
OpenAPI declaration
openapi: 3.0.0
info:
title: Library
version: "1.0"
description: xxxx
paths:
'/api/content/struct1/{id}':
get:
responses:
'200':
description: The LibraryModel instance with the specified libraryId.
content:
application/json:
schema:
$ref: '#/components/schemas/Struct1'
summary: Returns a Struct1
operationId: GetStruct1
tags:
- Struct1
parameters:
- name: id
description: Identifier
in: path
required: true
schema:
type: string
security:
- api_key: []
components:
schemas:
Struct1:
description: A
properties:
field1:
description: F1
$ref: '#/components/schemas/Struct2'
Struct2:
description: B
properties:
field2:
description: F2
type: boolean
Generation Details
java -jar openapi-generator-cli-8.0.0-20231011.125706-1.jar generate -i repro-openapi-deserialization-issue.yaml -g java --additional-properties hideGenerationTimestamp:true -o .\repro_openapi
Steps to reproduce
- Run the above command
- Observe the contents of
src\main\java\org\openapitools\client\model\Struct1.java
Suggest a fix
I've tracked the issue to OpenAPIDeserializer.getSchema(ObjectNode node, String location, ParseResult result) where the code ignores all the own metadata of the property and takes the data from the $ref.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at OpenAPIDeserializer.getSchema(ObjectNode node, String location, ParseResult result), which the report identifies as dropping property metadata when $ref is present. Reproduce the issue with the supplied OpenAPI declaration and Java generator command, then inspect the generated Struct1.java. Done means the field1 accessor includes the specified F1 description instead of the fallback field name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100