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

Whether an array is required or not should be controlled by ArraySchema.arraySchema.requiredMode instead of ArraySchema.schema.requiredMode #4341

Open
keigo-brook opened this issue Dec 31, 2022 · 1 comment

Comments

@keigo-brook
Copy link

After replaced the option required at @Schema annotation by requiredMode on #4286, it seems the issue #3438 is shown again.

According to the comments of ArraySchema annotation, ArraySchema.schema defines the model of the items within the array, while ArraySchema.arraySchema defines the model for the model of the array itself.

Example

In this example, I provide an almost same example at the #3438.

For the below DTO class:

public class Person {
    @ArraySchema(
        arraySchema = @Schema(requiredMode = RequiredMode.REQUIRED)
    )
    private List<String> addresses;
}

I expect the generated special to have (but it's not):

{
  "Person": {
    "required": [
      "addresses"
    ]
  }
}

And I need to work around this by:

public class Person {
    @ArraySchema(
        arraySchema = @Schema(description = "The person"),
        schema = @Schema(requiredMode = RequiredMode.REQUIRED)
    )
    private List<String> addresses;
}
@Calcimicium
Copy link

It seems this issue is still present (swagger-annotations v2.2.15).
Another possible workaround is to use the @Schema annotation instead of @ArraySchema.
I did not try it but I think it is possible to combine both of them :

public class Person {
    @Schema(requiredMode = RequiredMode.REQUIRED) // works
    @ArraySchema(arraySchema = @Schema(description = "The person"))
    // combination of @Schema and @ArraySchema not tried
    private List<String> addresses;
}

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

2 participants