Skip to content

Commit 24e87c5

Browse files
micrycfrantuma
authored andcommitted
refs-#4760-Fix enum type annotations processing
1 parent e8bb595 commit 24e87c5

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

Diff for: modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,9 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
368368
if (xml != null) {
369369
model.xml(xml);
370370
}
371-
applyBeanValidatorAnnotations(model, annotatedType.getCtxAnnotations(), null, false);
371+
if (!type.isEnumType()){
372+
applyBeanValidatorAnnotations(model, annotatedType.getCtxAnnotations(), null, false);
373+
}
372374
resolveSchemaMembers(model, annotatedType, context, next);
373375
if (resolvedArrayAnnotation != null) {
374376
ArraySchema schema = new ArraySchema();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package io.swagger.v3.core.resolving;
2+
3+
import io.swagger.v3.core.converter.ModelConverters;
4+
import io.swagger.v3.core.matchers.SerializationMatchers;
5+
import io.swagger.v3.oas.models.media.Schema;
6+
import org.testng.annotations.Test;
7+
8+
import javax.validation.constraints.Size;
9+
import java.util.List;
10+
import java.util.Map;
11+
12+
public class Ticket4760Test {
13+
14+
@Test
15+
public void testArraySchemaItemsValidation(){
16+
final Map<String, Schema> stringSchemaMap = ModelConverters.getInstance().readAll(ClassWithArraySchemaItemsValidation.class);
17+
final String expectedJson = "{\n" +
18+
" \"ClassWithArraySchemaItemsValidation\" : {\n" +
19+
" \"type\" : \"object\",\n" +
20+
" \"properties\" : {\n" +
21+
" \"setOfEnums\" : {\n" +
22+
" \"maxItems\" : 3,\n" +
23+
" \"minItems\" : 1,\n" +
24+
" \"type\" : \"array\",\n" +
25+
" \"items\" : {\n" +
26+
" \"type\" : \"string\",\n" +
27+
" \"enum\" : [ \"green\", \"blue\" ]\n" +
28+
" }\n" +
29+
" }\n" +
30+
" }\n" +
31+
" }\n" +
32+
"}";
33+
SerializationMatchers.assertEqualsToJson(stringSchemaMap, expectedJson);
34+
}
35+
36+
private static class ClassWithArraySchemaItemsValidation{
37+
38+
public enum MyEnum {
39+
red,
40+
green
41+
}
42+
43+
public enum MyOtherEnum {
44+
green,
45+
blue
46+
}
47+
48+
@io.swagger.v3.oas.annotations.media.ArraySchema(schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = MyOtherEnum.class))
49+
@Size(min = 1, max = 3)
50+
private List<MyEnum> setOfEnums;
51+
52+
public List<MyEnum> getSetOfEnums() {
53+
return setOfEnums;
54+
}
55+
56+
public void setSetOfEnums(List<MyEnum> setOfEnums) {
57+
this.setOfEnums = setOfEnums;
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)