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

@NotEmpty is being ignored in 2.8.6 and does not create required attribute #2946

Open
adgan opened this issue Mar 24, 2025 · 5 comments
Open
Labels
bug Something isn't working

Comments

@adgan
Copy link

adgan commented Mar 24, 2025

Describe the bug

After updating to version 2.8.6 of [Framework/Library Name], the @NotEmpty annotation on request DTOs no longer generates the required attribute in the OpenAPI file. This behavior worked as expected in the previous version 2.8.5.

To Reproduce
Steps to reproduce the behavior:

  1. using @NotEmpty
  2. generating OpenAPI yml file
  3. looking at the required list
  • What version of spring-boot you are using?
    3.4.4
  • What modules and versions of springdoc-openapi are you using?
    springdoc-openapi-starter-webmvc-ui @ 2.8.6
  • What is the actual and the expected result using OpenAPI Description (yml or json)? yml
  • Provide with a sample code (HelloController) or Test that reproduces the problem
public class ExampleRequestDto {
  @Schema(
      name = „test“,
      description = „test“,
      example = „test“,
  )
  @NotEmpty
  private final String test;
}

Expected behavior

Sample code should add a

      required:
      - test
@bnasslahsen
Copy link
Collaborator

@adgan,

This looks to be a regression in swagger-core v2.2.29 and there is an existing issue for it: swagger-api/swagger-core#4862.

As a workaround, you can downgrade the swagger-core version to 2.2.28, until this is fixed.

	<dependency>
		<groupId>org.springdoc</groupId>
		<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
		<version>2.8.6</version>
		<exclusions>
			<exclusion>
				<groupId>io.swagger.core.v3</groupId>
				<artifactId>swagger-core-jakarta</artifactId>
			</exclusion>
		</exclusions>
	</dependency>
	<dependency>
		<groupId>io.swagger.core.v3</groupId>
		<artifactId>swagger-core-jakarta</artifactId>
		<version>2.2.28</version>
	</dependency>

@bnasslahsen bnasslahsen added invalid This doesn't seem right bug Something isn't working and removed invalid This doesn't seem right labels Mar 24, 2025
@bnasslahsen bnasslahsen reopened this Mar 24, 2025
@adgan
Copy link
Author

adgan commented Mar 24, 2025

Hey @bnasslahsen,

Thanks for the info! I also found the workaround to add requiredMode = Schema.RequiredMode.REQUIRED to the @Schema to include it in the OpenAPI file.

@ksiczek
Copy link

ksiczek commented Mar 25, 2025

And for Gradle aficionados:

dependencies {

    constraints {
        implementation("io.swagger.core.v3:swagger-core-jakarta") {
            version {
                strictly("2.2.28")
            }
            because("NotEmpty not treated as required https://github.com/swagger-api/swagger-core/issues/4862")
        }
    }
...
}

@MinSang22Kim
Copy link

I also encountered the same issue in a Gradle environment.
Downgrading swagger-core-jakarta to version 2.2.28, as suggested above, worked as a temporary workaround for now.
Thanks for the helpful feedback!

@aconrad
Copy link

aconrad commented Apr 1, 2025

I can confirm that, as a client / consumer of the open api spec in JSON format, "required" fields aren't honored as they used to after upgrading from 2.8.5 to 2.8.6. We annotate required fields with javax.validation.constraints.NotNull;.

Here is a sample generated JSON diff from 2.8.5 to 2.8.6:

             ],
             "type": "string"
           }
-        },
-        "required": [
-          "make",
-          "model"
-        ]
+        }
       },
       "Phone": {
         "properties": {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants