OpenAPITools / OpenAPITools/openapi-generator

[BUG] The `openapi` schema generator strips `type: array` from property definitions

Open
#21,391 1 comment 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
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The openapi schema generator removes the type: array from schema property definitions. If the generated schema is subsequently used to generate (for example) Java code using the spring generator, it generates these attribute types as Object rather than ArrayList<Type>.

It also strips out item type information when a $ref is not used ($ref item types are carried through).

openapi-generator version

7.6.8

OpenAPI declaration file content or url

This input:

 {
    “$schema”: “https://json-schema.org/draft/2020-12/schema”,
    “title”: “MySchema”,
    “type”: “object”,
    “properties”: {
       “myArray”: {
          “type”: “array”,
          “Items”: {
             “type”: “number”
           }
        }
    }
}      

Produces:

 {
    “$schema”: “https://json-schema.org/draft/2020-12/schema”,
    “title”: “MySchema”,
    “type”: “object”,
    “properties”: {
       “myArray”: {
          “Items” : {   }
        }
    }
}      

I expect the generator to retain the type: array in the myArray property and also retain the item type info.

Giving this to the spring generator generates a class containing:

private Object myArray = null;
Generation Details

openapi generator was used with no options.

I also tried using some of the inline-schema and normalizer options, but none appear to change this behaviour.

Steps to reproduce

Generate using the example above and the openapi generator.

Related issues/PRs

I believe this bug (since 2020) is related: https://github.com/OpenAPITools/openapi-generator/issues/7802

Suggest a fix

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 the supplied schema with the openapi generator version 7.6.8, then compare its output with the expected array and item type information. Verify the result by passing the generated schema to the spring generator and confirming that the array property receives the intended collection element type rather than Object.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.