Skip to content

Commit

Permalink
fix DateSchema enum and default serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Jan 16, 2025
1 parent f188f7f commit fab142a
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

}
35 changes: 35 additions & 0 deletions modules/swagger-core/src/test/resources/dateSchema.yaml
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit fab142a

Please sign in to comment.