OpenAPITools / OpenAPITools/openapi-generator

[BUG] array schemas with single non-object allOf entry aren't resolved

Open
#23,837 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

Description

When an array schema contains an allOf definition with just a single element (that is not an object), it is not resolved, even though this can safely be unwrapped. This leads to type resolution errors in generated code. Other composed schemas such as oneOf are handled correctly.

openapi-generator version

v7.22.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Test
  version: 1.0.0
paths: {}
components:
  schemas:
    Data:
      type: object
      properties:
        outer:
          type: array
          items:
            allOf:
              - type: array
                items:
                  type: string

Generation Details

It happens with all generated outputs, many languages can't compile the generated code. E.g. go:

// Data struct for Data
type Data struct {
	Outer []Array `json:"outer,omitempty"`
}
Steps to reproduce

run openapi-generator with:
openapi-generator generate -i modules/openapi-generator/src/test/resources/3_0/array_allof_single_type.yaml -o out/ -g <anything>

Related issues/PRs

#23838

Suggest a fix

Basically needs analog handling to the object case:

https://github.com/OpenAPITools/openapi-generator/blob/0b1ac885fba00ee18b839e4e2f51459ce32acc27/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java#L328-L335

I'll open a PR

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 with InlineModelResolver.java around lines 328-335, then reproduce using modules/openapi-generator/src/test/resources/3_0/array_allof_single_type.yaml and the openapi-generator generate command. Compare the existing object handling with this single non-object allOf case. Done means the schema is resolved and generated outputs no longer contain the unresolved array type shown in the Go example.

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
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.