Skip to content

fix: calculate sibling properties based upon whether the schema is the array or the item in the array#5055

Merged
ewaostrowska merged 2 commits intoswagger-api:masterfrom
Mattias-Sehlstedt:array-list-schema-in-response-content
Feb 26, 2026
Merged

fix: calculate sibling properties based upon whether the schema is the array or the item in the array#5055
ewaostrowska merged 2 commits intoswagger-api:masterfrom
Mattias-Sehlstedt:array-list-schema-in-response-content

Conversation

@Mattias-Sehlstedt
Copy link
Copy Markdown
Contributor

Pull Request

Thank you for contributing to swagger-core!

Please fill out the following information to help us review your PR efficiently.


Description

Fixes: #5051

I have formalized the extra schema-annotation check that is done for a 3.1. specification. This check is done to properly add sibling properties (e.g., adding a description together with the #ref).

We now only expect one of the three different annotation scenarios to have an effect (being schemaAnnotation, schemaAnnotation within the arrayAnnotation, or the arrayAnnotation itself). The basis for this being that they are mutually exclusive. We either have a Schema-annotation or an ArraySchema-annotation. The second scenario was not handled before, but is now considered and supported.

This change prevents the data leakage that occurred before due to the arraySchema-annotation being applied to the object within the array.

We can also see that this fixed a data leakage issue that occurred in the test for ModelWithArrayOfSubclasses, where the list properties ("description", "minItems", "uniqueItems") where also placed on the list object too.

This:

"baseArray" : {
  "type" : "array",
  "description" : "Thingy",
    "items" : {
      "$ref" : "#/components/schemas/Base",
      "description" : "Thingy",
      "minItems" : 0,
      "uniqueItems" : true
    },
  "minItems" : 0,
  "uniqueItems" : true
}

Should be this

"baseArray" : {
  "type" : "array",
  "description" : "Thingy",
    "items" : {
      "$ref" : "#/components/schemas/Base"
    },
  "minItems" : 0,
  "uniqueItems" : true
}

Since the annotation is:

@ArraySchema(
  schema = @Schema(implementation = Base.class), 
  arraySchema = @Schema(
    type = "array", 
    description = "Thingy"), 
  minItems = 0, 
  uniqueItems = true
)
public Base[] getBaseArray() {

I also took the opportunity to adjust the test introduced with Mattias-Sehlstedt@0a5556a so that the expected json-definitions are placed in the resource folder like how it is with most tests.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor (non-breaking change)
  • 🧪 Tests
  • 📝 Documentation
  • 🧹 Chore (build or tooling)

Checklist

  • I have added/updated tests as needed
  • I have added/updated documentation where applicable
  • The PR title is descriptive
  • The code builds and passes tests locally
  • I have linked related issues (if any)

Screenshots / Additional Context

@ewaostrowska ewaostrowska force-pushed the array-list-schema-in-response-content branch 2 times, most recently from 51e248b to 0dd5d47 Compare February 26, 2026 14:50
@ewaostrowska ewaostrowska force-pushed the array-list-schema-in-response-content branch from 0dd5d47 to 099b8dd Compare February 26, 2026 14:50
@ewaostrowska
Copy link
Copy Markdown
Contributor

Hi @Mattias-Sehlstedt!
Thank you for investing your time in this topic here. We do appreciate it a lot. I have added tests to fully document the behavior and test the edge cases. but otherwise looks good :)

@ewaostrowska ewaostrowska merged commit 6143bee into swagger-api:master Feb 26, 2026
7 checks passed
@Mattias-Sehlstedt Mattias-Sehlstedt deleted the array-list-schema-in-response-content branch February 26, 2026 16:53
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

Successfully merging this pull request may close these issues.

[Bug]: Array schema description leaks into items

2 participants