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 for managed JAX-RS sub resources #2168

Closed
BrianSetz opened this issue Jan 22, 2025 · 0 comments · Fixed by #2169
Closed

Support for managed JAX-RS sub resources #2168

BrianSetz opened this issue Jan 22, 2025 · 0 comments · Fixed by #2169

Comments

@BrianSetz
Copy link
Contributor

BrianSetz commented Jan 22, 2025

Smallrye Open API can handle normal JAX-RS sub resources:

@Path("resource")
class Resource {
    @Path("sub-resource")
    public SubResource subResource() {
        return new SubResource();
    }
}

class SubResource {
    @GET
    public String subResource() {
        return "GET sub resource";
    }
}

However, there is no support for managed sub resource locators.

@Path("resource")
class Resource {
    @Path("managed-sub-resource")
    public Class<ManagedSubResource> managedSubResource() {
        return ManagedSubResource.class;
    }
}

@RequestScoped
class ManagedSubResource {
    @Inject
    MyService myService;

    @GET
    public String managedSubResource() {
        return myService.callSomething();
    }
}

The key difference is that instead of returning a new instance of a class, only the class itself is returned. We use managed sub resources extensively so we don't have to inject at the parent resource and then pass the injected object to the sub resource constructor, and so we can let CDI manage the lifetime.

I know where to fix this and will submit a draft PR, but I will need some help with the correct implementation and the best place to introduce tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant