Skip to content

Commit

Permalink
refs-#4760-Fix enum type annotations processing
Browse files Browse the repository at this point in the history
  • Loading branch information
micryc authored and frantuma committed Nov 18, 2024
1 parent e8bb595 commit 24e87c5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,9 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
if (xml != null) {
model.xml(xml);
}
applyBeanValidatorAnnotations(model, annotatedType.getCtxAnnotations(), null, false);
if (!type.isEnumType()){
applyBeanValidatorAnnotations(model, annotatedType.getCtxAnnotations(), null, false);
}
resolveSchemaMembers(model, annotatedType, context, next);
if (resolvedArrayAnnotation != null) {
ArraySchema schema = new ArraySchema();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package io.swagger.v3.core.resolving;

import io.swagger.v3.core.converter.ModelConverters;
import io.swagger.v3.core.matchers.SerializationMatchers;
import io.swagger.v3.oas.models.media.Schema;
import org.testng.annotations.Test;

import javax.validation.constraints.Size;
import java.util.List;
import java.util.Map;

public class Ticket4760Test {

@Test
public void testArraySchemaItemsValidation(){
final Map<String, Schema> stringSchemaMap = ModelConverters.getInstance().readAll(ClassWithArraySchemaItemsValidation.class);
final String expectedJson = "{\n" +
" \"ClassWithArraySchemaItemsValidation\" : {\n" +
" \"type\" : \"object\",\n" +
" \"properties\" : {\n" +
" \"setOfEnums\" : {\n" +
" \"maxItems\" : 3,\n" +
" \"minItems\" : 1,\n" +
" \"type\" : \"array\",\n" +
" \"items\" : {\n" +
" \"type\" : \"string\",\n" +
" \"enum\" : [ \"green\", \"blue\" ]\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
SerializationMatchers.assertEqualsToJson(stringSchemaMap, expectedJson);
}

private static class ClassWithArraySchemaItemsValidation{

public enum MyEnum {
red,
green
}

public enum MyOtherEnum {
green,
blue
}

@io.swagger.v3.oas.annotations.media.ArraySchema(schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = MyOtherEnum.class))
@Size(min = 1, max = 3)
private List<MyEnum> setOfEnums;

public List<MyEnum> getSetOfEnums() {
return setOfEnums;
}

public void setSetOfEnums(List<MyEnum> setOfEnums) {
this.setOfEnums = setOfEnums;
}
}
}

0 comments on commit 24e87c5

Please sign in to comment.