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

@Size annotation on List<String> causes incorrect openapi spec to be generated. #4462

Closed
caspianb opened this issue Aug 8, 2023 · 7 comments

Comments

@caspianb
Copy link

caspianb commented Aug 8, 2023

Hopefully this is the correct library to handle this issue; I was referred here from springdoc/springdoc-openapi#2337 -- apologies if I got it wrong.

Using a simple DTO can reproduce this issue:

@Data
static class RequestDto {
    @Size(min = 1, max = 5)
    @Schema(description = "List of values.")
    private List<String> values;
}

The @Size validation is only (correctly) applied to the list size. However, the api spec itself is showing this:
image

Essentially, the API spec is stating that:

  1. the list must be between 1 and 5 elements (correct);
  2. the length of the string of each element must be between 1 and 5 characters (incorrect)

You can also see that the description is also being duplicated from the array down to the element as well. I am uncertain if this is intentional and or desirable so not sure if that should also be considered a bug as well.


Note that the actual runtime validation is only applied to point1 above (correct behavior IMO).
Point2 is not enforced by the validator at runtime even though the generated API spec is indicating that the string should be between 1 and 5 characters in length.

This also just started occurring when we updated springdoc-openapi-starter-webmvc-ui to 2.2.0 (from 2.1.0).

@Mattias-G
Copy link

It seems this bug was introduced in version 2.2.13 and still exists in 2.2.15 (currently latest version).

@WannabeSoftwareEngineer
Copy link

WannabeSoftwareEngineer commented Oct 20, 2023

the problematic part (introduced in #4429)

        if (annotatedType.getCtxAnnotations() != null) {
            strippedCtxAnnotations.addAll(Arrays.stream(
                    annotatedType.getCtxAnnotations()).filter(
                    ass -> !ass.annotationType().getName().startsWith("io.swagger")
            ).collect(Collectors.toList()));
        }

where annotatedType is, in this case, List<String> and when we try to resolve the schema for the value type of this collection, i.e., String, we are passing down the annotations applied to the container also to the value type.

@frantuma any suggestion how we can resolve this regression?

@frantuma
Copy link
Member

Thanks for reporting and analyzing this!

It has been addressed in #4500 by excluding also javax.validation annotations from "custom annotation processing".

@caspianb
Copy link
Author

Thank you! Quick question based on the PR: will this also work for jakarta.validation? javax.validation is effectively deprecated now I believe?

@frantuma
Copy link
Member

yes it will

@WannabeSoftwareEngineer

Do you know already when will the next release be?

@frantuma
Copy link
Member

no fixed ETA but should be next 1-2 days

ndwlocatieservices added a commit to ndwnu/nls-accessibility-map that referenced this issue Jun 28, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [nu.ndw.nls:routing-map-matcher-spring-boot](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | compile | patch | `7.6.0` -> `7.6.1` |
| [io.swagger.core.v3:swagger-annotations](https://github.com/swagger-api/swagger-core) | compile | patch | `2.2.17` -> `2.2.19` |
| [org.openapitools:openapi-generator-maven-plugin](https://github.com/openapitools/openapi-generator) | build | minor | `7.0.1` -> `7.1.0` |
| [org.keycloak:keycloak-authz-client](http://keycloak.org) ([source](https://github.com/keycloak/keycloak)) | test | patch | `22.0.4` -> `22.0.5` |

---

### Release Notes

<details>
<summary>swagger-api/swagger-core (io.swagger.core.v3:swagger-annotations)</summary>

### [`v2.2.19`](https://github.com/swagger-api/swagger-core/releases/tag/v2.2.19): Swagger-core 2.2.19 released!

[Compare Source](swagger-api/swagger-core@v2.2.18...v2.2.19)

-   give precedence to requiredMode annotation ([#&#8203;4533](swagger-api/swagger-core#4533))
-   update dependencies ([#&#8203;4521](swagger-api/swagger-core#4521))
-   Bump org.apache.maven.plugins:maven-source-plugin from 3.2.1 to 3.3.0 ([#&#8203;4513](swagger-api/swagger-core#4513))
-   add deps update CI ([#&#8203;4509](swagger-api/swagger-core#4509))

### [`v2.2.18`](https://github.com/swagger-api/swagger-core/releases/tag/v2.2.18): Swagger-core 2.2.18 released!

[Compare Source](swagger-api/swagger-core@v2.2.17...v2.2.18)

-   refs [#&#8203;4483](swagger-api/swagger-core#4483) - fix NullPointer for [@&#8203;ApiResponse](https://github.com/ApiResponse) missing description ([#&#8203;4501](swagger-api/swagger-core#4501))
-   refs [#&#8203;4462](swagger-api/swagger-core#4462) - exclude javax.validation annotations from container values processing ([#&#8203;4500](swagger-api/swagger-core#4500))
-   Update README.md versions list ([#&#8203;4493](swagger-api/swagger-core#4493))
-   feat: add getUseFqn to TypeNameResolver ([#&#8203;4484](swagger-api/swagger-core#4484))

</details>

<details>
<summary>openapitools/openapi-generator (org.openapitools:openapi-generator-maven-plugin)</summary>

### [`v7.1.0`](https://github.com/OpenAPITools/openapi-generator/releases/tag/v7.1.0): released

[Compare Source](OpenAPITools/openapi-generator@v7.0.1...v7.1.0)

v7.1.0 is the first release [with breaking changes (with fallback)](https://github.com/OpenAPITools/openapi-generator/pulls?q=is%3Amerged+is%3Apr+milestone%3A7.1.0+label%3A%22Breaking+change+%28with+fallback%29%22+) after the major release v7.0.0 in Aug 2023.

Breaking changes with f...
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

4 participants