diff --git a/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/mixin/DateSchemaMixin.java b/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/mixin/DateSchemaMixin.java index ee859cc240..d0ae9c61bf 100644 --- a/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/mixin/DateSchemaMixin.java +++ b/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/mixin/DateSchemaMixin.java @@ -10,6 +10,12 @@ public abstract class DateSchemaMixin { @JsonFormat (shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") public abstract Object getExample(); + @JsonFormat (shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") + public abstract Object getDefault(); + + @JsonFormat (shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") + public abstract Object getEnum(); + @JsonIgnore public abstract Object getJsonSchemaImpl(); diff --git a/modules/swagger-core/src/test/java/io/swagger/v3/core/deserialization/JsonDeserializationTest.java b/modules/swagger-core/src/test/java/io/swagger/v3/core/deserialization/JsonDeserializationTest.java index a31e16362f..3b38d0a97b 100644 --- a/modules/swagger-core/src/test/java/io/swagger/v3/core/deserialization/JsonDeserializationTest.java +++ b/modules/swagger-core/src/test/java/io/swagger/v3/core/deserialization/JsonDeserializationTest.java @@ -542,4 +542,46 @@ public void testExampleDeserializationOnMediaType() throws Exception { assertTrue(openAPI.getPaths().get("/pet").getPost().getRequestBody().getContent().get("application/json").getExampleSetFlag()); } + @Test + public void testDateSchemaSerialization() throws Exception { + String content = FileUtils.readFileToString(new File("src/test/resources/dateSchema.yaml"), "UTF-8"); + OpenAPI openAPI = Yaml.mapper().readValue(content, OpenAPI.class); + Yaml.prettyPrint(openAPI); + SerializationMatchers.assertEqualsToYaml(openAPI, "openapi: 3.0.3\n" + + "info:\n" + + " title: Simple Inventory API\n" + + " version: 1.0.0\n" + + "paths:\n" + + " /inventory:\n" + + " get:\n" + + " operationId: searchInventory\n" + + " parameters:\n" + + " - name: test\n" + + " in: header\n" + + " schema:\n" + + " type: string\n" + + " format: date\n" + + " enum:\n" + + " - 2023-12-12\n" + + " default: 2023-12-12\n" + + " responses:\n" + + " \"200\":\n" + + " description: search results matching criteria\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: \"#/components/schemas/InventoryItem\"\n" + + "components:\n" + + " schemas:\n" + + " InventoryItem:\n" + + " type: object\n" + + " properties:\n" + + " releaseDate:\n" + + " type: string\n" + + " format: date-time\n" + + " example: 2016-08-29T09:12:33.001Z"); + } + } diff --git a/modules/swagger-core/src/test/resources/dateSchema.yaml b/modules/swagger-core/src/test/resources/dateSchema.yaml new file mode 100644 index 0000000000..b456e8d791 --- /dev/null +++ b/modules/swagger-core/src/test/resources/dateSchema.yaml @@ -0,0 +1,35 @@ +openapi: 3.0.3 +info: + version: "1.0.0" + title: Simple Inventory API +paths: + /inventory: + get: + operationId: searchInventory + parameters: + - in: header + name: test + schema: + type: string + format: date + enum: + - 2023-12-12 + default: 2023-12-12 + responses: + '200': + description: search results matching criteria + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/InventoryItem' +components: + schemas: + InventoryItem: + type: object + properties: + releaseDate: + type: string + format: date-time + example: '2016-08-29T09:12:33.001Z'