-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support custom annotation for containers
- Loading branch information
Showing
4 changed files
with
104 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...-core/src/test/java/io/swagger/v3/core/converting/override/CustomAnnotationConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.swagger.v3.core.converting.override; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.swagger.v3.core.converter.AnnotatedType; | ||
import io.swagger.v3.core.converter.ModelConverter; | ||
import io.swagger.v3.core.converter.ModelConverterContext; | ||
import io.swagger.v3.core.jackson.ModelResolver; | ||
import io.swagger.v3.core.resolving.resources.BidimensionalArray; | ||
import io.swagger.v3.core.util.AnnotationsUtils; | ||
import io.swagger.v3.oas.models.media.Schema; | ||
|
||
import java.util.Iterator; | ||
|
||
public class CustomAnnotationConverter extends ModelResolver { | ||
|
||
public CustomAnnotationConverter(ObjectMapper mapper) { | ||
super(mapper); | ||
} | ||
|
||
@Override | ||
public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) { | ||
Schema s = chain.next().resolve(type, context, chain); | ||
if (s != null) { | ||
if ("array".equals(s.getType()) && s.getItems() != null && "array".equals(s.getItems().getType())) { | ||
BidimensionalArray.MySizeAnnotation size = AnnotationsUtils.getAnnotation(BidimensionalArray.MySizeAnnotation.class, type.getCtxAnnotations()); | ||
if (size != null) { | ||
s.getItems().maxItems(size.maxItems()); | ||
} | ||
} | ||
return s; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...swagger-core/src/test/java/io/swagger/v3/core/resolving/resources/BidimensionalArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.swagger.v3.core.resolving.resources; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import io.swagger.v3.oas.annotations.media.ArraySchema; | ||
|
||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.util.List; | ||
|
||
public class BidimensionalArray { | ||
@ArraySchema(maxItems = 3) | ||
@MySizeAnnotation(maxItems = 2) | ||
public List<List<String>> withCustomAnnotation; | ||
|
||
@ArraySchema(maxItems = 3) | ||
public List<Foo<String>> withHelperClass; | ||
|
||
|
||
@ArraySchema(maxItems = 2) | ||
@JsonIgnoreProperties({"empty"}) | ||
public static interface Foo<T> extends List<T> { | ||
|
||
} | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Inherited | ||
public static @interface MySizeAnnotation { | ||
int maxItems() default Integer.MIN_VALUE; | ||
} | ||
} |