OpenAPITools / OpenAPITools/openapi-generator

[BUG] OpenAPI failed to initialized variables while generating the code

Open
#16,393 0 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

Bug Report Checklist

Here is my spec file

    Portfolios:
      allOf:
        - $ref: '#/components/schemas/DlCollection'
        - type: object
          properties:
            items:
              type: array
              items:
                $ref: '#/components/schemas/Portfolio'

Open API 6.6.0 version generating code like below

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
public class Portfolios extends DlCollection implements Serializable {

  private static final long serialVersionUID = 1L;

  @JsonProperty("items")
  @Valid
  private List<Portfolio> items = null;

My expectation is

  @JsonProperty("items")
  @Valid
  private List<Portfolio> items = new ArrayList<>();

Is there any fix or workaround for this?

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 by reproducing Java SpringCodegen output with the supplied OpenAPI schema on version 6.6.0, then trace the generator path that initializes the Portfolios.items field. Compare the generated null initialization with the expected ArrayList initialization; done means the generated field uses the expected default without regressing related schemas.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, 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.