Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refs-#4760-Fix enum type annotations processing #4780

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
Loading