Skip to content

Commit 3e9db3c

Browse files
committed
fix DateSchema enum and default serialization
1 parent f188f7f commit 3e9db3c

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/mixin/DateSchemaMixin.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ public abstract class DateSchemaMixin {
1010
@JsonFormat (shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
1111
public abstract Object getExample();
1212

13+
@JsonFormat (shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
14+
public abstract Object getDefault();
15+
16+
@JsonFormat (shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
17+
public abstract Object getEnum();
18+
1319
@JsonIgnore
1420
public abstract Object getJsonSchemaImpl();
1521

modules/swagger-core/src/test/java/io/swagger/v3/core/deserialization/JsonDeserializationTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,4 +542,46 @@ public void testExampleDeserializationOnMediaType() throws Exception {
542542
assertTrue(openAPI.getPaths().get("/pet").getPost().getRequestBody().getContent().get("application/json").getExampleSetFlag());
543543
}
544544

545+
@Test
546+
public void testDateSchemaSerialization() throws Exception {
547+
String content = FileUtils.readFileToString(new File("src/test/resources/dateSchema.yaml"), "UTF-8");
548+
OpenAPI openAPI = Yaml.mapper().readValue(content, OpenAPI.class);
549+
Yaml.prettyPrint(openAPI);
550+
SerializationMatchers.assertEqualsToYaml(openAPI, "openapi: 3.0.3\n" +
551+
"info:\n" +
552+
" title: Simple Inventory API\n" +
553+
" version: 1.0.0\n" +
554+
"paths:\n" +
555+
" /inventory:\n" +
556+
" get:\n" +
557+
" operationId: searchInventory\n" +
558+
" parameters:\n" +
559+
" - name: test\n" +
560+
" in: header\n" +
561+
" schema:\n" +
562+
" type: string\n" +
563+
" format: date\n" +
564+
" enum:\n" +
565+
" - 2023-12-12\n" +
566+
" default: 2023-12-12\n" +
567+
" responses:\n" +
568+
" \"200\":\n" +
569+
" description: search results matching criteria\n" +
570+
" content:\n" +
571+
" application/json:\n" +
572+
" schema:\n" +
573+
" type: array\n" +
574+
" items:\n" +
575+
" $ref: \"#/components/schemas/InventoryItem\"\n" +
576+
"components:\n" +
577+
" schemas:\n" +
578+
" InventoryItem:\n" +
579+
" type: object\n" +
580+
" properties:\n" +
581+
" releaseDate:\n" +
582+
" type: string\n" +
583+
" format: date-time\n" +
584+
" example: 2016-08-29T09:12:33.001Z");
585+
}
586+
545587
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
openapi: 3.0.3
2+
info:
3+
version: "1.0.0"
4+
title: Simple Inventory API
5+
paths:
6+
/inventory:
7+
get:
8+
operationId: searchInventory
9+
parameters:
10+
- in: header
11+
name: test
12+
schema:
13+
type: string
14+
format: date
15+
enum:
16+
- 2023-12-12
17+
default: 2023-12-12
18+
responses:
19+
'200':
20+
description: search results matching criteria
21+
content:
22+
application/json:
23+
schema:
24+
type: array
25+
items:
26+
$ref: '#/components/schemas/InventoryItem'
27+
components:
28+
schemas:
29+
InventoryItem:
30+
type: object
31+
properties:
32+
releaseDate:
33+
type: string
34+
format: date-time
35+
example: '2016-08-29T09:12:33.001Z'

0 commit comments

Comments
 (0)