openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

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

Open drpump opened this issue 7 months ago • 1 comments

Bug Report Checklist

  • [ ] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator?
  • [ ] Have you tested with the latest master to confirm the issue still exists?
  • [x] Have you searched for related issues/PRs?
  • [x] 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

drpump avatar Jun 06 '25 07:06 drpump

I need to replace the example above with a better one: the error appears to be limited to cases where anyOf is used.

drpump avatar Jun 09 '25 22:06 drpump