Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
crizzis opened this issue Nov 15, 2024 · 1 comment

Comments

@crizzis
Copy link

crizzis commented Nov 15, 2024

@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.

@crizzis
Copy link
Author

crizzis commented Nov 15, 2024

Update: I found a workaround: apparently @SchemaProperty(name = "create", array = @ArraySchema(schema = @Schema(ref = "#/components/schemas/MyCustomDto"))) works just fine.

The problem only appears when using @Schema.implementation instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant