From f245695c97dd867171f86a919e4eb4e915e80995 Mon Sep 17 00:00:00 2001 From: Andrew Rouse Date: Tue, 3 Dec 2024 16:07:16 +0000 Subject: [PATCH 1/2] Add OpenAPI.jsonSchemaDialect to the model --- .../microprofile/openapi/models/OpenAPI.java | 30 +++++++++++++++++++ .../openapi/models/package-info.java | 2 +- .../openapi/reader/MyOASModelReaderImpl.java | 1 + .../openapi/tck/ModelReaderAppTest.java | 6 ++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/OpenAPI.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/OpenAPI.java index eed5b428..be8929fd 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/OpenAPI.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/OpenAPI.java @@ -327,6 +327,36 @@ default OpenAPI webhooks(Map webhooks) { */ void removeWebhook(String name); + /** + * Returns the default JSON Schema dialect for schemas in this document. + * + * @return the identifier of the default schema dialect for schemas in this document + * @since 4.1 + */ + String getJsonSchemaDialect(); + + /** + * Sets the default JSON Schema dialect for schemas in this document. + * + * @param jsonSchemaDialect + * the identifier of the default schema dialect for schemas in this document + * @since 4.1 + */ + void setJsonSchemaDialect(String jsonSchemaDialect); + + /** + * Sets the default JSON Schema dialect for schemas in this document. + * + * @param jsonSchemaDialect + * the identifier of the default schema dialect for schemas in this document + * @return the current OpenAPI object + * @since 4.1 + */ + default OpenAPI jsonSchemaDialect(String jsonSchemaDialect) { + setJsonSchemaDialect(jsonSchemaDialect); + return this; + } + /** * Returns the components property from an OpenAPI instance. * diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/package-info.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/package-info.java index f29b8077..929acdc4 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/package-info.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/package-info.java @@ -40,6 +40,6 @@ * */ -@org.osgi.annotation.versioning.Version("2.1") +@org.osgi.annotation.versioning.Version("2.2") @org.osgi.annotation.versioning.ProviderType package org.eclipse.microprofile.openapi.models; \ No newline at end of file diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/reader/MyOASModelReaderImpl.java b/tck/src/main/java/org/eclipse/microprofile/openapi/reader/MyOASModelReaderImpl.java index e94c0a7a..e26833ed 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/reader/MyOASModelReaderImpl.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/reader/MyOASModelReaderImpl.java @@ -308,6 +308,7 @@ public OpenAPI buildModel() { .externalDocs(OASFactory.createObject(ExternalDocumentation.class) .description("instructions for how to deploy this app") .url("https://github.com/microservices-api/oas3-airlines/blob/master/README.md")) + .jsonSchemaDialect("https://json-schema.org/draft/2020-12/schema") .addWebhook("bookingEvent", OASFactory.createPathItem() .PUT(OASFactory.createOperation() .summary("Notifies that a booking has been created") diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/ModelReaderAppTest.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/ModelReaderAppTest.java index 5d421f6f..a890c605 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/ModelReaderAppTest.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/ModelReaderAppTest.java @@ -427,4 +427,10 @@ public void testRequestBodyInOperations(String type) { vr.body("paths.'/zepplins'.delete.requestBody.content", notNullValue()); } + + @Test(dataProvider = "formatProvider") + public void testSchemaDialect(String type) { + ValidatableResponse vr = callEndpoint(type); + vr.body("jsonSchemaDialect", equalTo("https://json-schema.org/draft/2020-12/schema")); + } } From 18b6ad4ee49ba0b0c7f3457199d8d678cf860fd7 Mon Sep 17 00:00:00 2001 From: Andrew Rouse Date: Tue, 3 Dec 2024 16:29:23 +0000 Subject: [PATCH 2/2] 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")); + } }