feat(ext-openapi): a pattern says in words what its regex says in symbols
A schema's pattern is precise and unreadable. When the constraint declares a message, that message now goes in the property's description too, after whatever the property already said, so the document carries both the rule a machine checks and the sentence a person reads. Only @Pattern does this. Every other constraint has a keyword that already reads: required, maxLength, format: email. Repeating those as prose would be noise. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
5ece97ca7b
commit
5164f8c41f
@@ -128,6 +128,25 @@ Field-level exclusion: `@Schema(hidden = true)`, `@SchemaProperty(hidden = true)
|
||||
`@NotBlank`, `@NotEmpty`, `@Size`, `@Min`, `@Max`, `@Email`, `@Pattern`) become the schema's own
|
||||
bounds and required fields, so a rule is written once and documented for free.
|
||||
|
||||
A `@Pattern` that declares a message says it in the description too, after whatever the property
|
||||
already said: a regex is precise and unreadable, and both belong in the document.
|
||||
|
||||
```java
|
||||
@SchemaProperty(description = "Unique in the project.")
|
||||
@Pattern(regexp = "[a-z.]+", message = "uses lowercase letters and dots")
|
||||
String key
|
||||
```
|
||||
|
||||
```yaml
|
||||
key:
|
||||
type: string
|
||||
description: Unique in the project. Uses lowercase letters and dots.
|
||||
pattern: '[a-z.]+'
|
||||
```
|
||||
|
||||
No other constraint does this: `required`, `maxLength` and `format: email` are already readable,
|
||||
and repeating them as prose would be noise.
|
||||
|
||||
## Contributor API
|
||||
|
||||
OpenAPI is extension-agnostic. Other extensions contribute through `OpenApiContributor`, held in
|
||||
|
||||
Reference in New Issue
Block a user