-
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.
refs #4474 - fix NPE while resolving container types
- Loading branch information
Showing
3 changed files
with
177 additions
and
8 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
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
164 changes: 164 additions & 0 deletions
164
modules/swagger-core/src/test/java/io/swagger/v3/core/resolving/Ticket4474Test.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,164 @@ | ||
package io.swagger.v3.core.resolving; | ||
|
||
import io.swagger.v3.core.converter.AnnotatedType; | ||
import io.swagger.v3.core.converter.ModelConverterContextImpl; | ||
import io.swagger.v3.core.jackson.ModelResolver; | ||
import io.swagger.v3.core.matchers.SerializationMatchers; | ||
import io.swagger.v3.oas.models.media.Schema; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class Ticket4474Test extends SwaggerTestBase { | ||
|
||
@AfterMethod | ||
public void afterTest() { | ||
ModelResolver.enumsAsRef = false; | ||
} | ||
|
||
@Test | ||
public void testAnyOf() throws Exception { | ||
ModelResolver.enumsAsRef = true; | ||
|
||
final ModelResolver modelResolver = new ModelResolver(mapper()); | ||
|
||
final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver); | ||
|
||
final Schema model = context | ||
.resolve(new AnnotatedType(Document.class)); | ||
|
||
SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "Document:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" data:\n" + | ||
" type: object\n" + | ||
" additionalProperties:\n" + | ||
" type: object\n" + | ||
" anyOf:\n" + | ||
" - type: array\n" + | ||
" items:\n" + | ||
" type: boolean\n" + | ||
" - type: array\n" + | ||
" items:\n" + | ||
" type: integer\n" + | ||
" format: int32\n" + | ||
" - type: array\n" + | ||
" items:\n" + | ||
" type: integer\n" + | ||
" format: int64\n" + | ||
" - type: array\n" + | ||
" items:\n" + | ||
" type: number\n" + | ||
" format: double\n" + | ||
" - type: array\n" + | ||
" items:\n" + | ||
" type: string\n" + | ||
" - type: boolean\n" + | ||
" - type: integer\n" + | ||
" format: int32\n" + | ||
" - type: integer\n" + | ||
" format: int64\n" + | ||
" listData:\n" + | ||
" type: array\n" + | ||
" items:\n" + | ||
" type: object\n" + | ||
" anyOf:\n" + | ||
" - type: array\n" + | ||
" items:\n" + | ||
" type: boolean\n" + | ||
" - type: array\n" + | ||
" items:\n" + | ||
" type: integer\n" + | ||
" format: int32\n" + | ||
" - type: array\n" + | ||
" items:\n" + | ||
" type: integer\n" + | ||
" format: int64\n" + | ||
" - type: array\n" + | ||
" items:\n" + | ||
" type: number\n" + | ||
" format: double\n" + | ||
" - type: array\n" + | ||
" items:\n" + | ||
" type: string\n" + | ||
" - type: boolean\n" + | ||
" - type: integer\n" + | ||
" format: int32\n" + | ||
" - type: integer\n" + | ||
" format: int64\n" + | ||
" itemData:\n" + | ||
" type: object\n" + | ||
" anyOf:\n" + | ||
" - type: array\n" + | ||
" items:\n" + | ||
" type: boolean\n" + | ||
" - type: array\n" + | ||
" items:\n" + | ||
" type: integer\n" + | ||
" format: int32\n" + | ||
" - type: array\n" + | ||
" items:\n" + | ||
" type: integer\n" + | ||
" format: int64\n" + | ||
" - type: array\n" + | ||
" items:\n" + | ||
" type: number\n" + | ||
" format: double\n" + | ||
" - type: array\n" + | ||
" items:\n" + | ||
" type: string\n" + | ||
" - type: boolean\n" + | ||
" - type: integer\n" + | ||
" format: int32\n" + | ||
" - type: integer\n" + | ||
" format: int64"); | ||
} | ||
|
||
static class Document { | ||
@io.swagger.v3.oas.annotations.media.Schema( | ||
anyOf = { | ||
Boolean[].class, | ||
Integer[].class, | ||
Long[].class, | ||
Double[].class, | ||
String[].class, | ||
Boolean.class, | ||
Integer.class, | ||
Long.class, | ||
Map.class, | ||
}) | ||
public Map<String, Object> data = new HashMap<>(); | ||
|
||
@io.swagger.v3.oas.annotations.media.Schema( | ||
anyOf = { | ||
Boolean[].class, | ||
Integer[].class, | ||
Long[].class, | ||
Double[].class, | ||
String[].class, | ||
Boolean.class, | ||
Integer.class, | ||
Long.class, | ||
Map.class, | ||
}) | ||
public List<Object> listData = new ArrayList<>(); | ||
|
||
@io.swagger.v3.oas.annotations.media.Schema( | ||
anyOf = { | ||
Boolean[].class, | ||
Integer[].class, | ||
Long[].class, | ||
Double[].class, | ||
String[].class, | ||
Boolean.class, | ||
Integer.class, | ||
Long.class, | ||
Map.class, | ||
}) | ||
public Object itemData = new Object(); | ||
} | ||
} |