From 4ce300adb08f0550c81524f7274f2efd693c9b13 Mon Sep 17 00:00:00 2001 From: Andrew Rouse Date: Wed, 18 Dec 2024 14:28:14 +0000 Subject: [PATCH] Add missing tests for OpenAPI 3.1 new fields Test that new fields added for OpenAPI 3.1 are read and written correctly in 3.1 and 3.0 modes. --- .../io/OpenApiParserAndSerializerTest.java | 9 +++++++++ .../openapi/runtime/io/_everything.json | 14 ++++++++++++- .../openapi/runtime/io/_everything.yaml | 7 +++++++ .../smallrye/openapi/runtime/io/info30.json | 18 +++++++++++++++++ .../smallrye/openapi/runtime/io/info31.json | 20 +++++++++++++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 core/src/test/resources/io/smallrye/openapi/runtime/io/info30.json create mode 100644 core/src/test/resources/io/smallrye/openapi/runtime/io/info31.json diff --git a/core/src/test/java/io/smallrye/openapi/runtime/io/OpenApiParserAndSerializerTest.java b/core/src/test/java/io/smallrye/openapi/runtime/io/OpenApiParserAndSerializerTest.java index b12a20f49..6f3753258 100644 --- a/core/src/test/java/io/smallrye/openapi/runtime/io/OpenApiParserAndSerializerTest.java +++ b/core/src/test/java/io/smallrye/openapi/runtime/io/OpenApiParserAndSerializerTest.java @@ -223,6 +223,15 @@ void testParseInfo() throws IOException, JSONException { doTest("info.json", Format.JSON); } + /** + * Test 3.1 -> 3.0 conversion of info objects + */ + @Test + void testParseInfo30() throws IOException, JSONException { + doMultiVersionTest("info31.json", "info30.json", ConversionDirection.TO_30_ONLY); + doMultiVersionTest("info.json", "info30.json", ConversionDirection.BOTH_WAYS); + } + /** * Test method for {@link OpenApiParser#parse(java.net.URL)}. */ diff --git a/core/src/test/resources/io/smallrye/openapi/runtime/io/_everything.json b/core/src/test/resources/io/smallrye/openapi/runtime/io/_everything.json index 4b532c520..aff9351bd 100644 --- a/core/src/test/resources/io/smallrye/openapi/runtime/io/_everything.json +++ b/core/src/test/resources/io/smallrye/openapi/runtime/io/_everything.json @@ -417,7 +417,19 @@ } }, "links": {}, - "callbacks": {} + "callbacks": {}, + "pathItems": { + "eventNotify": { + "post": { + "description": "Event notification" + } + } + } + }, + "webhooks": { + "events": { + "$ref": "#/components/pathItems/eventNotify" + } }, "x-root-extension-1": "hello world", "x-root-extension-2": [ true, false ] diff --git a/core/src/test/resources/io/smallrye/openapi/runtime/io/_everything.yaml b/core/src/test/resources/io/smallrye/openapi/runtime/io/_everything.yaml index 0cc931d07..8e3d6cc1a 100644 --- a/core/src/test/resources/io/smallrye/openapi/runtime/io/_everything.yaml +++ b/core/src/test/resources/io/smallrye/openapi/runtime/io/_everything.yaml @@ -295,6 +295,13 @@ components: in: query links: {} callbacks: {} + pathItems: + eventNotify: + post: + description: Event notification +webhooks: + events: + $ref: "#/components/pathItems/eventNotify" x-root-extension-1: hello world x-root-extension-2: - true diff --git a/core/src/test/resources/io/smallrye/openapi/runtime/io/info30.json b/core/src/test/resources/io/smallrye/openapi/runtime/io/info30.json new file mode 100644 index 000000000..dfe6ddebe --- /dev/null +++ b/core/src/test/resources/io/smallrye/openapi/runtime/io/info30.json @@ -0,0 +1,18 @@ +{ + "openapi" : "3.0.3", + "info" : { + "title": "Sample Pet Store App", + "description": "This is a sample server for a pet store.", + "termsOfService": "http://example.com/terms/", + "contact": { + "name": "API Support", + "url": "http://www.example.com/support", + "email": "support@example.com" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version": "1.0.1" + } +} diff --git a/core/src/test/resources/io/smallrye/openapi/runtime/io/info31.json b/core/src/test/resources/io/smallrye/openapi/runtime/io/info31.json new file mode 100644 index 000000000..4e2a9b86c --- /dev/null +++ b/core/src/test/resources/io/smallrye/openapi/runtime/io/info31.json @@ -0,0 +1,20 @@ +{ + "openapi" : "3.1.0", + "info" : { + "title": "Sample Pet Store App", + "description": "This is a sample server for a pet store.", + "summary": "Test sample server", + "termsOfService": "http://example.com/terms/", + "contact": { + "name": "API Support", + "url": "http://www.example.com/support", + "email": "support@example.com" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html", + "identifier": "Apache-2.0" + }, + "version": "1.0.1" + } +}