OpenAPITools / OpenAPITools/openapi-generator

allOf in schema property results in generation of invalid Java methods "putXXXItem"

Open
#11,696 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Disclaimer: I face these issues when generating a Java SDK, I don't know whether it affects other languages too.

Problem: I'm currently using version 5.3.0 of the generator, and with this version it generates some invalid methods for a schema's class, if the schema contains a property with an allOf element.

yaml:

 MyType:
      required:
      - category
      type: object
      properties:
        category:
          type: object
          description: |-
            <strong>Type:</strong> Category<br/>
            The category
          allOf:
          - $ref: '#/components/schemas/Category'

The generated java class for MyType contains this method which doesn't compile:

  public MyType putCategoryItem(String key,  categoryItem) {
    this.category.put(key, categoryItem);
    return this;
  }

First of all, you can see that there's no type declaration for the "categoryItem" parameter. Also, "this.category" is not a map, but a reference to the Category class (which is correct).

This whole method doesn't make sense to me. The previous version of the generator that I used was version 5.0.1, and that version didn't contain these invalid "putXXXItem" methods.

Can you explain where this comes from, and how I would have to change my yaml file so that those methods are no longer created?

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

Use the supplied MyType schema as the reproduction input and inspect the Java SDK generator output for putCategoryItem. Done means the generated MyType compiles and the invalid method is absent; no source file or regression test is identified in the issue, so locating the relevant generator path is part of the work.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.