-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Closed
Closed
Copy link
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
In response to #18302, simple fields no longer undergo validation, which includes enums as well. However, it seems that enum classes that are componentized are considered container types, and without setting isContainer, the @Valid
annotation does not get removed.
openapi-generator version
7.5.0
Steps to reproduce
This can be reproduced by implementing such an API definition.
components:
schemas:
StringEnum:
type: string
enum:
- foo
- bar
- baz
default: foo
IntegerEnum:
type: integer
enum:
- 1
- 2
- 3
default: 1
paths:
/tests/defaults:
get:
responses:
default:
description: response
content:
application/json:
schema:
type: object
properties:
stringEnum:
$ref: '#/components/schemas/StringEnum'
integerEnum:
$ref: '#/components/schemas/IntegerEnum'
stringEnumInline:
type: string
enum:
- foo
- bar
- baz
default: foo
integerEnumInline:
type: integer
enum:
- 1
- 2
- 3
default: 1
The @Valid
was missing for enum parameters defined inline.
However, enums described in components
still had @Valid
.
@javax.annotation.Nullable
@JsonProperty("stringEnum")
@ApiModelProperty(value = "")
@Valid
public StringEnum getStringEnum() {
return stringEnum;
}
...
@javax.annotation.Nullable
@JsonProperty("stringEnumInline")
@ApiModelProperty(value = "")
public StringEnumInlineEnum getStringEnumInline() {
return stringEnumInline;
}
Related issues/PRs
Suggest a fix
This part of the file
{{#required}}@NotNull {{/required}}{{^isPrimitiveType}}{{^isDate}}{{^isDateTime}}{{^isString}}{{^isFile}}@Valid {{/isFile}}{{/isString}}{{/isDateTime}}{{/isDate}}{{/isPrimitiveType}}{{>beanValidationCore}}
By modifying the file like this, @Valid
has been removed even for enum types defined in components
.
{{#required}}@NotNull {{/required}}{{#isContainer}}{{^isPrimitiveType}}{{^isDate}}{{^isDateTime}}{{^isString}}{{^isFile}}{{^isEnum}}@Valid {{/isEnum}}{{/isFile}}{{/isString}}{{/isDateTime}}{{/isDate}}{{/isPrimitiveType}}{{/isContainer}}{{>beanValidationCore}}