diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/Extensible.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/Extensible.java index 407204f5..2b7c4734 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/Extensible.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/Extensible.java @@ -76,4 +76,34 @@ default T extensions(Map extensions) { */ void setExtensions(Map extensions); + /** + * Checks whether an extension with the given name is present in this Extensible's map of extensions. + * + * @param name + * the key used to access the extension object. Always prefixed by "x-". + * @return {@code true} if an extension with the given name is present, otherwise {@code false} + */ + default boolean hasExtension(String name) { + Map map = getExtensions(); + if (map == null) { + return false; + } + return map.containsKey(name); + } + + /** + * Returns the extension object with the given name from this Extensible's map of extensions. + * + * @param name + * the key used to access the extension object. Always prefixed by "x-". + * @return the corresponding extension object, or {@code null} if no extension with the given name is present + */ + default Object getExtension(String name) { + Map map = getExtensions(); + if (map == null) { + return null; + } + return map.get(name); + } + } diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/callbacks/package-info.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/callbacks/package-info.java index cc8a571d..fe052715 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/callbacks/package-info.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/callbacks/package-info.java @@ -17,6 +17,6 @@ * The behaviour of methods inherited from java.lang.Object are undefined by the MicroProfile OpenAPI specification. */ -@org.osgi.annotation.versioning.Version("2.0") +@org.osgi.annotation.versioning.Version("2.1") @org.osgi.annotation.versioning.ProviderType package org.eclipse.microprofile.openapi.models.callbacks; \ No newline at end of file diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/examples/package-info.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/examples/package-info.java index 2956c679..d1d6898d 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/examples/package-info.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/examples/package-info.java @@ -31,6 +31,6 @@ * */ -@org.osgi.annotation.versioning.Version("1.0") +@org.osgi.annotation.versioning.Version("1.1") @org.osgi.annotation.versioning.ProviderType package org.eclipse.microprofile.openapi.models.examples; \ No newline at end of file diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/headers/package-info.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/headers/package-info.java index 3d3da47b..4eb3a27c 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/headers/package-info.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/headers/package-info.java @@ -35,6 +35,6 @@ * */ -@org.osgi.annotation.versioning.Version("1.0") +@org.osgi.annotation.versioning.Version("1.1") @org.osgi.annotation.versioning.ProviderType package org.eclipse.microprofile.openapi.models.headers; \ No newline at end of file diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/info/package-info.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/info/package-info.java index 6ec0a09f..1671c9d4 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/info/package-info.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/info/package-info.java @@ -40,6 +40,6 @@ * */ -@org.osgi.annotation.versioning.Version("1.1") +@org.osgi.annotation.versioning.Version("1.2") @org.osgi.annotation.versioning.ProviderType package org.eclipse.microprofile.openapi.models.info; \ No newline at end of file diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/links/package-info.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/links/package-info.java index 0b6e8227..e28730ae 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/links/package-info.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/links/package-info.java @@ -29,6 +29,6 @@ * */ -@org.osgi.annotation.versioning.Version("1.0") +@org.osgi.annotation.versioning.Version("1.1") @org.osgi.annotation.versioning.ProviderType package org.eclipse.microprofile.openapi.models.links; \ No newline at end of file diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/media/package-info.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/media/package-info.java index 3e143df6..a1fb925b 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/media/package-info.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/media/package-info.java @@ -30,6 +30,6 @@ * */ -@org.osgi.annotation.versioning.Version("3.0") +@org.osgi.annotation.versioning.Version("3.1") @org.osgi.annotation.versioning.ProviderType package org.eclipse.microprofile.openapi.models.media; \ No newline at end of file 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/api/src/main/java/org/eclipse/microprofile/openapi/models/parameters/package-info.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/parameters/package-info.java index bf390ff1..fefc7389 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/parameters/package-info.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/parameters/package-info.java @@ -32,6 +32,6 @@ * */ -@org.osgi.annotation.versioning.Version("1.0") +@org.osgi.annotation.versioning.Version("1.1") @org.osgi.annotation.versioning.ProviderType package org.eclipse.microprofile.openapi.models.parameters; \ No newline at end of file diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/responses/package-info.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/responses/package-info.java index 41b9c374..89554224 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/responses/package-info.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/responses/package-info.java @@ -34,6 +34,6 @@ * */ -@org.osgi.annotation.versioning.Version("2.0") +@org.osgi.annotation.versioning.Version("2.1") @org.osgi.annotation.versioning.ProviderType package org.eclipse.microprofile.openapi.models.responses; \ No newline at end of file diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/security/package-info.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/security/package-info.java index b9380d43..0eb28a45 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/security/package-info.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/security/package-info.java @@ -28,6 +28,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.security; \ No newline at end of file diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/servers/package-info.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/servers/package-info.java index 8a0f9314..167a61a8 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/servers/package-info.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/servers/package-info.java @@ -35,6 +35,6 @@ * */ -@org.osgi.annotation.versioning.Version("2.0") +@org.osgi.annotation.versioning.Version("2.1") @org.osgi.annotation.versioning.ProviderType package org.eclipse.microprofile.openapi.models.servers; \ No newline at end of file diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/tags/package-info.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/tags/package-info.java index 195d309a..12a8a578 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/tags/package-info.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/tags/package-info.java @@ -29,6 +29,6 @@ * */ -@org.osgi.annotation.versioning.Version("1.0") +@org.osgi.annotation.versioning.Version("1.1") @org.osgi.annotation.versioning.ProviderType package org.eclipse.microprofile.openapi.models.tags; \ No newline at end of file diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/ModelConstructionTest.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/ModelConstructionTest.java index 9482aab8..9481a999 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/ModelConstructionTest.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/ModelConstructionTest.java @@ -1781,16 +1781,28 @@ private void processExtensible(Extensible e) { assertEquals(map.size(), 2, "The extensions map is expected to contain two entries."); assertTrue(map.containsKey(extensionName1), "The extensions map is expected to contain the key: " + extensionName1); + assertTrue(e.hasExtension(extensionName1), + "hasExtension is expected to return true for the key: " + extensionName1); assertTrue(map.containsKey(extensionName2), "The extensions map is expected to contain the key: " + extensionName2); + assertTrue(e.hasExtension(extensionName2), + "hasExtension is expected to return true for the key: " + extensionName2); assertSame(map.get(extensionName1), obj1, "The value associated with the key: " + extensionName1 + " is expected to be the same one that was added."); + assertSame(e.getExtension(extensionName1), obj1, + "getExtension should return the same instance added for the key: " + extensionName1); assertSame(map.get(extensionName2), obj2, "The value associated with the key: " + extensionName2 + " is expected to be the same one that was added."); + assertSame(e.getExtension(extensionName2), obj2, + "getExtension should return the same instance added for the key: " + extensionName2); e.removeExtension(extensionName1); assertEquals(e.getExtensions().size(), 1, "The extensions map is expected to contain one entry."); + assertFalse(e.hasExtension(extensionName1), + "hasExtension is expected to return false for removed key: " + extensionName1); + assertNull(e.getExtension(extensionName1), + "getExtension is expected to return null for removed key: " + extensionName1); // Check that the extension map can be replaced with the setter and that it is returned by the getter. final Map newMap = new HashMap<>(); e.setExtensions(newMap);