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

Sharing @ApiImplicitParams across resources #2591

Open
pavlos163 opened this issue Dec 18, 2017 · 2 comments
Open

Sharing @ApiImplicitParams across resources #2591

pavlos163 opened this issue Dec 18, 2017 · 2 comments

Comments

@pavlos163
Copy link

Q A
Bug or feature request? Bug
Which Swagger-Core version? 1.5.17
Which Java version? 1.8.0_131
Which JAX-RS framework & version? 1.19

Almost all of my endpoints include a @Context RequestContext requestContext parameter like the above. That object includes common path parameters such as language and country.

public interface MyResource {

    @GET
    @Path("mypath")
    Response anExampleEndpoint(@Context RequestContext requestContext,
                               @PathParam("something") Something something);

    ...
}

What I can do for this specific interface is add a ApiImplicitParams above the interface name, and that works fine.

@ApiImplicitParams({
        @ApiImplicitParam(name = "language", value = "Caller's language", required = true, dataType = "string", paramType = "path"),
        @ApiImplicitParam(name = "country", value = "Caller's country", required = true, dataType = "string", paramType = "path"),
        ...
})

However, I don't want to do that for every one of my resources, as they are many and nearly all of them have a RequestContext object inside their methods.

What are the solutions available here? I tried adding the @ApiImplicitParams in the RequestContext class like this:

@ApiImplicitParams({
		@ApiImplicitParam(name = "language", value = "Caller's language", required = true, dataType = "string", paramType = "path"),
		@ApiImplicitParam(name = "country", value = "Caller's country", required = true, dataType = "string", paramType = "path"),
                ...
})
public class RequestContext {
...
}

But it didn't read them.

Can it be done by overriding the Swagger reader? Or by using inheritance somehow? Or any other way?

Thanks.

@pavlos163
Copy link
Author

Solved with extending a common interface and adding @ApiImplicitParams there.

@pavlos163 pavlos163 reopened this Dec 18, 2017
@pavlos163
Copy link
Author

As a follow-up, would it be possible to automatically read that from a @Context object without having to maintain that list of @ApiImplicitParams?

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

No branches or pull requests

1 participant