Skip to content

Check exclude filter when parsing spring controller methods #721

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

Conversation

jpstratman
Copy link
Contributor

@jpstratman jpstratman commented Sep 28, 2021

We're running into a scenario where some mock controller methods are being included that we'd rather exclude. Currently there doesn't seem to be a way to exclude individual controller methods (or even individual controllers?) via the excludeClassPattern setting, so this is an attempt to add that functionality.

Just let me know if this functionality already exists in some form or if this is the wrong approach and I can make any needed changes 😄

@vojtechhabarta
Copy link
Owner

Excluding individual controllers is possible using excludeClassPatterns. (If your controller is nested class you just need to use $ character.)

Unfortunately excluding individual methods in Spring controller is not possible. In JAX-RS resource it is possible to use Swagger annotation @ApiOperation with hidden set to true.


Would it be interesting for you to add support for such annotation also for Spring controllers?

Or maybe we could introduce parameter excludeMethodAnnotations that would allow to use custom annotations for excluding controller methods (similarly to excludePropertyAnnotations) parameter for properties.

I am suggesting different ways because reusing class exclusion parameters for methods doesn't seem good to me.

@jpstratman
Copy link
Contributor Author

Excluding individual controllers is possible using excludeClassPatterns. (If your controller is nested class you just need to use $ character.)

Unfortunately excluding individual methods in Spring controller is not possible. In JAX-RS resource it is possible to use Swagger annotation @ApiOperation with hidden set to true.

Would it be interesting for you to add support for such annotation also for Spring controllers?
Or maybe we could introduce parameter excludeMethodAnnotations that would allow to use custom annotations for excluding controller methods (similarly to excludePropertyAnnotations) parameter for properties.

I am suggesting different ways because reusing class exclusion parameters for methods doesn't seem good to me.

Thank you for your input, it's much appreciated! I found that the class exclusion does not work when scanSpringApplication is not set to true. I created a PR here to attempt to address that in case that is unintentional: #731. I can also take a look at that hidden annotation check you mentioned.

I think the above will cover our needs as far as exclusion go, but it does seem like we would need a way to rename controller method names in a similar way to the customTypeNaming setting. Is there currently any functionality like that, or would that be something that would require a new setting?

vojtechhabarta added a commit that referenced this pull request Oct 27, 2021
@vojtechhabarta
Copy link
Owner

I added possibility to exclude Spring controller method using Swagger annotation:

@io.swagger.annotations.ApiOperation(value = "", hidden = true)  // original Swagger
@io.swagger.v3.oas.annotations.Operation(hidden = true)  // Swagger V3

Maybe it could be also useful to introduce parameter excludeMethodAnnotations to allow usage of user-defined annotations.

@vojtechhabarta
Copy link
Owner

Support for Swagger annotations release in v2.33.956.

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 this pull request may close these issues.

2 participants