-
-
Notifications
You must be signed in to change notification settings - Fork 562
Open
Description
First off, thank you very much for your continued effort in maintaining spring-doc!
The following minor defect popped up for us during the recent round of upgrades.
Consider the following Java type:
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
@Valid
public record StringConstraintsJsr380(
@NotEmpty
String nonEmpty,
@NotBlank
String notBlank) {
}and a controller that accepts it as a POST payload body:
@RestController
@RequestMapping("/v1/types")
@Validated
public class SomeController {
@PostMapping("string/jsr380")
void doStringConstraintsJsr380(@Valid @RequestBody StringConstraintsJsr380 payload) {
}
...
}Discovered schema for SpringConstraintsJsr380 is as follows:
{
...
"components": {
"schemas": {
"StringConstraintsJsr380": {
"type": "object",
"properties": {
"nonEmpty": {
"type": "string"
},
"notBlank": {
"type": "string"
}
},
"required": [
"nonEmpty",
"notBlank"
]
}
}
}
}This schema permits values of nonEmpty = "" and nonBlank = " ", while Java validation does not permit these values.
Per Jakarta, validation API:
- NotEmpty applied to
CharacterSequencerequires at least one character, hence thenonEmptymust haveminLength: 1 - NotBlank requires at least one non-whitespace character, which probably is best expressed with
pattern: "[^\\s]+".
To Reproduce
Steps to reproduce the behavior:
spring-bootversion 3.5.7springdoc-openapi-starter-common2.8.14- actual JSON - see above
- expected JSON:
{
...
"components": {
"schemas": {
"StringConstraintsJsr380": {
"type": "object",
"properties": {
"nonEmpty": {
"type": "string",
"minLength": 1
},
"notBlank": {
"type": "string",
"pattern": "[^\\s]+" // Better options?
}
},
"required": [
"nonEmpty",
"notBlank"
]
}
}
}
}Thank you in advance for looking into this!
Metadata
Metadata
Assignees
Labels
No labels