Skip to content

@RequestAttribute parameter appears in the UI #267

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

Closed
derlin opened this issue Dec 14, 2019 · 4 comments
Closed

@RequestAttribute parameter appears in the UI #267

derlin opened this issue Dec 14, 2019 · 4 comments
Labels
bug Something isn't working

Comments

@derlin
Copy link

derlin commented Dec 14, 2019

Context

I have a filter that adds attributes to the HTTP requests that are derived from headers and other things. In my controllers, I have endpoints that uses these attributes, like this:

@GetMapping("/{id}")
fun getById(
    @PathVariable(value = "id") id: Long,
    @RequestAttribute(value = "userid") userId: Int, /* <= set in a filter */
    @RequestParam(name = "writable", required = false) writable: Boolean = false
) { /* ... */ }

The generated UI is:

Screenshot 2019-12-14 at 17 47 17

Problem

I expect the @RequestAttribute to be ignored by OpenAPI, since it is an internal attribute that the client ignores. But it is still present in the interface (which is misleading) and marked as required (so the user cannot use try it out).

Questions

  1. Is this a normal behavior ?
  2. How can I mark a method parameter as hidden (and if possible globally, since the same attribute is used in many places) ?

versions

  • org.springframework.boot => 2.2.1.RELEASE
  • org.springdoc:springdoc-openapi-ui => 1.2.17
@f12998765
Copy link

I tested in 1.2.33, the parameters of RequestAttribute annotation were not ignored .

Looking at the modified source code, it was found that RequestAttribute should not be added to PARAM_TYPES_TO_IGNORE, it is an annotation.

Finally, I achieved my goal by customizing the RequestBuilder.

    @Bean
    @Primary
    RequestBuilder myRequestBuilder(GenericParameterBuilder parameterBuilder, RequestBodyBuilder requestBodyBuilder, OperationBuilder operationBuilder, Optional<List<OperationCustomizer>> customizers, Optional<List<ParameterCustomizer>> parameterCustomizers) {
        return new RequestBuilder(parameterBuilder, requestBodyBuilder, operationBuilder, customizers, parameterCustomizers) {
            @Override
            protected boolean isParamToIgnore(Parameter parameter) {
                if (parameter.isAnnotationPresent(RequestAttribute.class)) {
                    return true;
                }
                return super.isParamToIgnore(parameter);
            }
        };
    }

@ddeya
Copy link

ddeya commented May 28, 2020

This issue wasn't solved, can we re-open the issue, I can work on adding a "annotation based" ignore mechanism.

@bnasslahsen
Copy link
Collaborator

bnasslahsen commented May 28, 2020

@ddeya,

I have seen your comment on the commit. Its now fixed.

@ddeya
Copy link

ddeya commented May 30, 2020

Perfect, really fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants