OpenAPITools / OpenAPITools/openapi-generator

[BUG] Generator ignores description of schema properties that has a $ref

Open
#16,794 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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
  1. Run the above command
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.