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

Support extensions as nested annotations for extensible models #513

Merged
merged 5 commits into from
Mar 7, 2022
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 @@ -22,6 +22,7 @@
import java.lang.annotation.Target;

import org.eclipse.microprofile.openapi.annotations.callbacks.Callback;
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
import org.eclipse.microprofile.openapi.annotations.headers.Header;
import org.eclipse.microprofile.openapi.annotations.links.Link;
import org.eclipse.microprofile.openapi.annotations.media.ExampleObject;
Expand Down Expand Up @@ -105,4 +106,15 @@
* @return the reusable Callback objects.
*/
Callback[] callbacks() default {};

/**
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.Components Components} model
* corresponding to the containing annotation.
*
* @return array of extensions
*
* @since 3.1
*/
Extension[] extensions() default {};

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.eclipse.microprofile.openapi.annotations.extensions.Extension;

/**
* This annotation allows referencing an external resource for extended documentation.
* <p>
Expand Down Expand Up @@ -56,4 +58,13 @@
**/
String url() default "";

/**
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.ExternalDocumentation
* ExternalDocumentation} model corresponding to the containing annotation.
*
* @return array of extensions
*
* @since 3.1
*/
Extension[] extensions() default {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
import org.eclipse.microprofile.openapi.annotations.info.Info;
import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement;
import org.eclipse.microprofile.openapi.annotations.servers.Server;
Expand Down Expand Up @@ -87,4 +88,14 @@
* @return the element with a set of reusable objects for different aspects of the OAS.
*/
Components components() default @Components;

/**
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.OpenAPI OpenAPI} model
* corresponding to the containing annotation.
*
* @return array of extensions
*
* @since 3.1
*/
Extension[] extensions() default {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.eclipse.microprofile.openapi.annotations.extensions.Extension;

/**
* Describes a single API operation on a path.
*
Expand Down Expand Up @@ -75,4 +77,14 @@
* @return whether or not this operation is hidden
*/
boolean hidden() default false;

/**
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.Operation Operation} model
* corresponding to the containing annotation.
*
* @return array of extensions
*
* @since 3.1
*/
Extension[] extensions() default {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.eclipse.microprofile.openapi.annotations.extensions.Extension;

/**
* This object represents a callback URL that will be invoked.
*
Expand Down Expand Up @@ -74,4 +76,14 @@
* @return reference to a callback object definition
**/
String ref() default "";

/**
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.callbacks.Callback Callback}
* model corresponding to the containing annotation.
*
* @return array of extensions
*
* @since 3.1
*/
Extension[] extensions() default {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@
SecurityRequirement[] security() default {};

/**
* The list of optional extensions.
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.Operation Operation} model
* corresponding to the containing annotation.
*
* @return an optional array of extensions
* @return array of extensions
*
* @since 3.1
*/
Extension[] extensions() default {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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.annotations.callbacks;
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,62 @@
import java.lang.annotation.Target;

/**
* A named extension that should be added to the OpenAPI definition.
* A named extension that should be added to the OpenAPI definition. The names of all extensions MUST begin with
* {@code x-} or else an invalid document will potentially be created.
*
* <p>
* Although this annotation may currently be placed directly on a Java language element target, application developers
* should instead utilize the {@code extensions} property of the particular annotation that corresponds to the model
* being extended. Use of the annotation directly on a Java element is often ambiguous and it may result in the
* extension being added to an incorrect location in the OpenAPI model. Future releases of MicroProfile OpenAPI may
* remove the capability of placing this annotation directly on a Java element.
*
* <p>
* When {@code @Extension} annotations are used both directly on a Java element as well as within another annotation
* that targets the same Java element, implementations will apply only the nested extensions to the resulting model.
*
* <p>
* Example of <em>preferred</em> use with {@code @Extension} nested within an {@code @Schema} annotation:
*
* <pre>
* class MyPojo {
*
* {@literal @}Schema(
* type = SchemaType.STRING,
* extensions = {@literal @}Extension(
* name = "x-custom-property",
* value = "custom-value")
* String property1;
*
* }
* </pre>
*
* <p>
* Example of <em>deprecated</em> use with {@code @Extension} placed directly on a field implied to be a schema
* property:
*
* <pre>
* class MyPojo {
*
* {@literal @}Extension(
* name = "x-custom-property",
* value = "custom-value")
* String property1;
*
* }
* </pre>
*
*/
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(Extensions.class)
public @interface Extension {

/**
* A name for the extension.
* A name for the extension. The names of all extensions MUST begin with {@code x-} or else an invalid document will
* potentially be created.
*
* @return an option name for these extensions - will be prefixed with "x-"
* @return an option name for these extensions - must be prefixed with {@code x-}
*/
String name();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
import org.eclipse.microprofile.openapi.annotations.media.Schema;

/**
Expand Down Expand Up @@ -92,4 +93,13 @@
**/
String ref() default "";

/**
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.headers.Header Header} model
* corresponding to the containing annotation.
*
* @return array of extensions
*
* @since 3.1
*/
Extension[] extensions() default {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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.annotations.headers;
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.eclipse.microprofile.openapi.annotations.extensions.Extension;

/**
* Contact information for the exposed API.
*
Expand Down Expand Up @@ -52,4 +54,13 @@
**/
String email() default "";

/**
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.info.Contact Contact} model
* corresponding to the containing annotation.
*
* @return array of extensions
*
* @since 3.1
*/
Extension[] extensions() default {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.eclipse.microprofile.openapi.annotations.extensions.Extension;

/**
* This annotation provides metadata about the API, and maps to the Info object in OpenAPI Specification 3.
*
Expand Down Expand Up @@ -73,4 +75,13 @@
**/
String version();

/**
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.info.Info Info} model
* corresponding to the containing annotation.
*
* @return array of extensions
*
* @since 3.1
*/
Extension[] extensions() default {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.eclipse.microprofile.openapi.annotations.extensions.Extension;

/**
* License information for the exposed API.
*
Expand All @@ -45,4 +47,13 @@
**/
String url() default "";

/**
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.info.License License} model
* corresponding to the containing annotation.
*
* @return array of extensions
*
* @since 3.1
*/
Extension[] extensions() default {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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.annotations.info;
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
import org.eclipse.microprofile.openapi.annotations.servers.Server;

/**
Expand Down Expand Up @@ -103,4 +104,13 @@
**/
String ref() default "";

/**
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.links.Link Link} model
* corresponding to the containing annotation.
*
* @return array of extensions
*
* @since 3.1
*/
Extension[] extensions() default {};
}
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.annotations.links;
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.eclipse.microprofile.openapi.annotations.extensions.Extension;

/**
* This object provides schema and examples for a particular media type.
*
Expand Down Expand Up @@ -72,4 +74,13 @@
*/
Encoding[] encoding() default {};

/**
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.media.MediaType MediaType}
* model corresponding to the containing annotation.
*
* @return array of extensions
*
* @since 3.1
*/
Extension[] extensions() default {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
import org.eclipse.microprofile.openapi.annotations.headers.Header;

/**
Expand Down Expand Up @@ -103,4 +104,13 @@
*/
Header[] headers() default {};

/**
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.media.Encoding Encoding}
* model corresponding to the containing annotation.
*
* @return array of extensions
*
* @since 3.1
*/
Extension[] extensions() default {};
}
Loading