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

2.2.29 do not treat @NotBlank as mandatory, breaking change? #4862

Open
rikardhaggkvist opened this issue Mar 13, 2025 · 2 comments
Open

2.2.29 do not treat @NotBlank as mandatory, breaking change? #4862

rikardhaggkvist opened this issue Mar 13, 2025 · 2 comments
Labels

Comments

@rikardhaggkvist
Copy link

rikardhaggkvist commented Mar 13, 2025

In previous versions

public class Bar {
@NotBlank
private String foo;
}

generated to

export interface Bar {
  foo: string;
}

in 2.2.29 @NotBlank is generated to:

export interface Bar {
  foo?: string;
}

which in turn breaks the TypeSript code with error "Type 'string | undefined' is not assignable to type 'string'."

Now I need to add @NotNull to all the @NotBlank annotations in my Java code, it seems to apply to @NotEmpty also.

@ponelat
Copy link
Member

ponelat commented Mar 20, 2025

Hi @rikardhaggkvist
@notblank shouldn't impact the required/not-required types generated in TypeScript, could be related to a regression.
Would you mind sharing the OpenAPI file that's generated as an intermediate, to show if it's in the generator or the swagger-core that the issue lies in?

@rikardhaggkvist
Copy link
Author

rikardhaggkvist commented Mar 20, 2025

pom.xml

<plugin>
                <groupId>io.swagger.core.v3</groupId>
                <artifactId>swagger-maven-plugin-jakarta</artifactId>
                <version>2.2.29</version>
                <configuration>
                    <outputFileName>api</outputFileName>
                    <outputPath>${basedir}/target</outputPath>
                    <outputFormat>JSONANDYAML</outputFormat>
                    <resourcePackages>
                        <resourcePackage>bar.foo.service.api.rest</resourcePackage>
                    </resourcePackages>
                    <prettyPrint>true</prettyPrint>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>resolve</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

With @NotNull and @NotBlank api.json looks like:

      "MyClass" : {
        "required" : [ "myProp" ],
        "type" : "object",
        "properties" : {
          "myProp" : {
            "minLength" : 1,
            "type" : "string"
          },

If I remove @NotNull api.json looks like:

      "MyClass" : {
        "type" : "object",
        "properties" : {
          "myProp" : {
            "minLength" : 1,
            "type" : "string"
          },

If I now switch to swagger 2.2.28, not other changes and only got @NotBlank, api.json looks like:

      "MyClass" : {
        "required" : [ "myProp" ],
        "type" : "object",
        "properties" : {
          "myProp" : {
            "type" : "string"
          },

If I switch back to 2.2.29, no other changes:

      "MyClass" : {
        "type" : "object",
        "properties" : {
          "myProp" : {
            "minLength" : 1,
            "type" : "string"
          },

So for me it's obvious the behaviour changed in 2.2.29. @NotBlank and @NotEmpty are no longer required properties in the genereated apis. This should be mentioned in the release notes or be considered as a breaking change.

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

No branches or pull requests

2 participants