Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Extensible.hasExtension and .getExtension #678

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,34 @@ default T extensions(Map<String, Object> extensions) {
*/
void setExtensions(Map<String, Object> 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<String, Object> 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<String, Object> map = getExtensions();
if (map == null) {
return null;
}
return map.get(name);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
* </pre>
*/

@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;
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
* </pre>
*/

@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;
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
* </pre>
*/

@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;
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
* </pre>
*/

@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;
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
* </pre>
*/

@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;
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
* </pre>
*/

@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;
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
* </pre>
*/

@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;
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
* </pre>
*/

@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;
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
* </pre>
*/

@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;
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
* </pre>
*/

@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;
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
* </pre>
*/

@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;
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> newMap = new HashMap<>();
e.setExtensions(newMap);
Expand Down
Loading