From 18b6ad4ee49ba0b0c7f3457199d8d678cf860fd7 Mon Sep 17 00:00:00 2001 From: Andrew Rouse Date: Tue, 3 Dec 2024 16:29:23 +0000 Subject: [PATCH] Add OpenAPI.jsonSchemaDefinition to the annotations Allows setting the default schema dialect for the OpenAPI document. The only value we can test here is the default one, since that's the only one that implementations must support. --- .../openapi/annotations/OpenAPIDefinition.java | 9 +++++++++ .../microprofile/openapi/annotations/package-info.java | 2 +- .../microprofile/openapi/apps/petstore/PetStoreApp.java | 3 ++- .../microprofile/openapi/tck/PetStoreAppTest.java | 6 ++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/annotations/OpenAPIDefinition.java b/api/src/main/java/org/eclipse/microprofile/openapi/annotations/OpenAPIDefinition.java index 9f2da51e..fdfb53ef 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/annotations/OpenAPIDefinition.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/annotations/OpenAPIDefinition.java @@ -102,6 +102,15 @@ */ PathItem[] webhooks() default {}; + /** + * The identifier of the default JSON schema dialect for schemas in this document. + * + * @return the identifier of the default JSON schema dialect for schemas in this document + * + * @since 4.1 + */ + String jsonSchemaDialect() default ""; + /** * An element to hold a set of reusable objects for different aspects of the OpenAPI Specification (OAS). * diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/annotations/package-info.java b/api/src/main/java/org/eclipse/microprofile/openapi/annotations/package-info.java index 6bbd7b54..0fc7a193 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/annotations/package-info.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/annotations/package-info.java @@ -34,5 +34,5 @@ * */ -@org.osgi.annotation.versioning.Version("1.2") +@org.osgi.annotation.versioning.Version("1.3") package org.eclipse.microprofile.openapi.annotations; \ No newline at end of file diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/apps/petstore/PetStoreApp.java b/tck/src/main/java/org/eclipse/microprofile/openapi/apps/petstore/PetStoreApp.java index 92792221..87da785c 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/apps/petstore/PetStoreApp.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/apps/petstore/PetStoreApp.java @@ -51,7 +51,8 @@ }, components = @Components(schemas = { @Schema(name = "Lizard", implementation = Lizard.class) - })) + }), + jsonSchemaDialect = "https://spec.openapis.org/oas/3.1/dialect/base") @Schema(externalDocs = @ExternalDocumentation(url = "http://swagger.io", description = "Find out more about our store")) public class PetStoreApp extends Application { @Override diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/PetStoreAppTest.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/PetStoreAppTest.java index 45816cd7..98882677 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/PetStoreAppTest.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/PetStoreAppTest.java @@ -303,4 +303,10 @@ public void testExtensionPlacement(String type) { vr.body(opPath + ".responses.'503'.content.'application/xml'", hasEntry(equalTo("x-notavailable-ext"), equalTo("true"))); } + + @Test(dataProvider = "formatProvider") + public void testSchemaDialect(String type) { + ValidatableResponse vr = callEndpoint(type); + vr.body("jsonSchemaDialect", equalTo("https://spec.openapis.org/oas/3.1/dialect/base")); + } }