-
Notifications
You must be signed in to change notification settings - Fork 83
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
Possibility to put all related Microprofile-Annotations into Bundles #672
Comments
This would be similar to how you can compose Jakarta interceptor bindings: https://jakarta.ee/specifications/interceptors/2.2/jakarta-interceptors-spec-2.2#interceptor_binding_types_with_additional_interceptor_bindings |
@Azquelt For an example of such a "composed Jakarta interceptor binding" see the accepted answer in following Stackoverflow: |
We discussed this issue on this week's call and did consider the following alternatives:
We also had the following concerns:
|
i quote you:
is the "define it once as a component" possible in the java-world (via annotation and/or classes) ? What i had in mind was:
For example:
Annotate each of the methods with the class. I would like to profit from the Typesafety of the Java-World and i find the Syntax of the Open-API Specification File itself to be hard to read or manage. But maybe i will try the hybrid approach sometimes, because with too many annotations the REST-Endpoints become hard to manage. But i understand your concerns of merging annotations, and there are also non-openapi-specific annotations that are still relevant for the openapi-docs. |
Yes, you would do it like this: @OpenAPIDefinition(components = @Components(
@APIResponse(
name="getProductResponse"
responseCode = "200",
description = "Product information",
@Content(
mediaType="application/json",
Schema = @Schema(implementation = Product.class),
)
)
)) and then reference it from your operation method: @APIResponse(ref = "getProductResponse")
// ... any other annotations
public Product getProduct(@PathParam("id") String id) {
// ...
}
Hmm, I guess it doesn't really work for that because it's designed for the finer-grained parts which are reused throughout your application (e.g. a common error response structure) and as such there's no support for storing operations within a component. Wanting to use annotations but keep them separate from the code they relate to isn't really something I'd considered, though it's understandable as they can get quite long. In most cases, I'd expected that most of the detail for the operation could be inferred from the method itself and its the Jakarta REST annotations, or from other related objects, such as the return type or any registered exception handlers. I guess if you need to add longer descriptions and examples to each one then that will add up to quite a lot of space. At the moment, I think the hybrid approach is likely to work best for you. We need to think more about whether we should enable storing annotations away from the code they relate to. On the one hand, that is not generally how annotations work, they store a relatively small amount of data close to the code that it relates to. On the other hand, part of the problem here is that we're storing so much information in the annotation and they're not really suited to that task (we already run into issues expressing certain structures because an annotation cannot refer to another instance of itself, whereas OpenAPI Schemas can have other schemas within them). |
As seen in the following Stackoverflow-Question the Annotations could become very big and make it hard to see the REST-Endpoint-.Code:
For this reason (amon other reasons) it would be helpful to let the developer create "Bundles" where he can collect all relevant Annotations.
For many Annotations this is already possible. For example: The
APIResponse
andParameter
Annotation can be bundled together in a Meta-Annotation, that the developer creates himself for his project / his requirements. For example:For following Annotations this is not possible though, which makes this approach not good enough to be fully usable (for all cases):
@Operation
@RequestBody
The text was updated successfully, but these errors were encountered: