swagger-api / swagger-api/swagger-core

Redundant nested array rendered when using @SchemaProperty(array = ...) with object schemas

Open
#4,778 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backlog
Dominant language
Java
Stars
7.5k
Forks
2.3k
Avg merge
18h 1m
Merged PRs (30d)
10

Description

@SchemaProperty(name = "create", array = @ArraySchema(schema = @Schema(implementation = String.class)))

renders as:

"create": {
            "type": "array",
            "items": {
              "type": "string"
            }
 }

@SchemaProperty(name = "create", schema = @Schema(implementation = MyCustomDto.class))

renders as:

"create": {
            "$ref": "#/components/schemas/MyCustomDto"
          }

All of the above to be expected.

However, @SchemaProperty(name = "create", array = @ArraySchema(schema = @Schema(implementation = MyCustomDto.class)))

renders as:

"create": {
            "type": "array",
            "items": {
              "type": "array",
              "items": {
                "$ref": "#/components/schemas/MyCustomDto"
              }
            }
          }

In other words, it would seem there is no way to obtain a flat array property with POJO elements, using @SchemaProperty. It's either a plain object schema or a nested array, no in-between.

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 tracing how @SchemaProperty combines with @ArraySchema and the MyCustomDto implementation in the OpenAPI schema generation path. Reproduce the reported annotation cases and compare the generated schemas; done means the POJO case produces one array whose items reference MyCustomDto rather than a nested array.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.