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

Custom annotations prevent method from showing in doc #6080

Open
sedax90 opened this issue Jan 24, 2025 · 1 comment
Open

Custom annotations prevent method from showing in doc #6080

sedax90 opened this issue Jan 24, 2025 · 1 comment
Labels
Milestone

Comments

@sedax90
Copy link

sedax90 commented Jan 24, 2025

Following the tutorial I created a custom annotation for permission management:

@DecoratorFactory(RequiresPermissionFactoryFunction.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface RequiresPermission {
    String value();
}

When I apply the annotation at the method, eg:

@Get("/list")
    @ProducesJson
    @RequiresPermission(Permissions.CUSTOMER_VIEW)
    public ResponseEntity<List<CustomerResponse>> getCustomers(final ServiceRequestContext ctx,
            final HttpRequest req) throws Exception

this is no longer displayed in the generated doc.

@jrhee17
Copy link
Contributor

jrhee17 commented Feb 3, 2025

Hi, sorry about the late follow-up.

This issue seems like an issue due to the unwrapping behavior of decorators.
DocService unwraps decorators to retrieve the innermost service which can then be parsed and exposed in our documentation service.

I think defining the unwrap behavior for your decorator can be a workaround:

return delegate -> new HttpService() {
    @Override
    public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception {
        return delegate.serve(ctx, req);
    }

    @Override
    public <T> @Nullable T as(Class<T> type) {
        return delegate.as(type);
    }

    @Override
    public Service<? extends Request, ? extends Response> unwrap() {
        return delegate.unwrap();
    }
};

or to be more concise:

return delegate -> new SimpleDecoratingHttpService(delegate) {
    @Override
    public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception {
        return delegate.serve(ctx, req);
    }
};

Regardless of the workaround above, we should probably fix our implementation so that we can unwrap decorators to retrieve the annotated service regardless of how users have defined their decorators.

@jrhee17 jrhee17 added the defect label Feb 3, 2025
@jrhee17 jrhee17 added this to the 1.32.0 milestone Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants