-
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.
- Loading branch information
Showing
3 changed files
with
151 additions
and
1 deletion.
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
92 changes: 92 additions & 0 deletions
92
modules/swagger-core/src/test/java/io/swagger/v3/core/resolving/Ticket3311Test.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,92 @@ | ||
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.core.resolving.resources.HalBean; | ||
import io.swagger.v3.core.resolving.resources.TestObject2992; | ||
import io.swagger.v3.core.util.PrimitiveType; | ||
import io.swagger.v3.oas.models.media.Schema; | ||
import org.testng.annotations.Test; | ||
|
||
public class Ticket3311Test extends SwaggerTestBase { | ||
|
||
@Test | ||
public void testLocalTime() throws Exception { | ||
|
||
final ModelResolver modelResolver = new ModelResolver(mapper()); | ||
|
||
ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver); | ||
|
||
Schema model = context | ||
.resolve(new AnnotatedType(HalBean.class)); | ||
|
||
SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "LocalTime:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" hour:\n" + | ||
" type: integer\n" + | ||
" format: int32\n" + | ||
" minute:\n" + | ||
" type: integer\n" + | ||
" format: int32\n" + | ||
" second:\n" + | ||
" type: integer\n" + | ||
" format: int32\n" + | ||
" nano:\n" + | ||
" type: integer\n" + | ||
" format: int32\n" + | ||
"TestObject2992:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" name:\n" + | ||
" type: string\n" + | ||
" a:\n" + | ||
" $ref: '#/components/schemas/LocalTime'\n" + | ||
" b:\n" + | ||
" $ref: '#/components/schemas/LocalTime'\n" + | ||
" c:\n" + | ||
" $ref: '#/components/schemas/LocalTime'\n" + | ||
" d:\n" + | ||
" type: string\n" + | ||
" format: date-time\n" + | ||
" e:\n" + | ||
" type: string\n" + | ||
" format: date-time\n" + | ||
" f:\n" + | ||
" type: string\n" + | ||
" format: date-time"); | ||
|
||
PrimitiveType.enablePartialTime(); | ||
context = new ModelConverterContextImpl(modelResolver); | ||
|
||
context | ||
.resolve(new AnnotatedType(TestObject2992.class)); | ||
|
||
SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "TestObject2992:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" name:\n" + | ||
" type: string\n" + | ||
" a:\n" + | ||
" type: string\n" + | ||
" format: partial-time\n" + | ||
" b:\n" + | ||
" type: string\n" + | ||
" format: partial-time\n" + | ||
" c:\n" + | ||
" type: string\n" + | ||
" format: partial-time\n" + | ||
" d:\n" + | ||
" type: string\n" + | ||
" format: date-time\n" + | ||
" e:\n" + | ||
" type: string\n" + | ||
" format: date-time\n" + | ||
" f:\n" + | ||
" type: string\n" + | ||
" format: date-time"); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
modules/swagger-core/src/test/java/io/swagger/v3/core/resolving/resources/HalBean.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,58 @@ | ||
package io.swagger.v3.core.resolving.resources; | ||
|
||
//import mypackage.bean.ImmutableStyle; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonUnwrapped; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import io.swagger.v3.core.oas.models.Cat; | ||
//import io.swagger.annotations.ApiModel; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
//import org.immutables.value.Value; | ||
|
||
/** | ||
* The HateoasBean contains another Jackson-serializable bean plus links to other resources. | ||
* | ||
* It's done like this to not pollute all the JSON beans with _links entries. | ||
*/ | ||
//@ApiModel(value = "HALBean", description = "Root bean of all return values") | ||
//@Value.Immutable | ||
//@ImmutableStyle | ||
//@JsonSerialize(as = ImmutableHalBean.class) | ||
//@JsonDeserialize(as = ImmutableHalBean.class) | ||
public interface HalBean { //<T> { | ||
|
||
//@JsonProperty("_embedded") | ||
//Map<String, List<HalBean<T>>> getEmbedded(); | ||
//List<HalBean<T>> getEmbedded(); | ||
HalBean getEmbedded(); | ||
//Object getEmbedded(); | ||
|
||
@JsonUnwrapped | ||
Optional<Foo> getBean(); | ||
//Optional<T> getBean(); | ||
|
||
|
||
//@JsonProperty("_links") | ||
//Optional<Links> getLinks(); | ||
|
||
|
||
/* | ||
static <T> HalBean<T> of(final T bean, final Links links) { | ||
return null; | ||
//return ImmutableHalBean.<T>builder().setBean(bean).setLinks(links).build(); | ||
} | ||
static <T> HalBean<T> of(final Links links) { | ||
return null; | ||
//return ImmutableHalBean.<T>builder().setLinks(links).build(); | ||
} | ||
*/ | ||
|
||
public static class Foo{ | ||
public String bar; | ||
} | ||
} | ||
|