Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Hidding query parameter from the controller method #206

Open
dsnkostic opened this issue Jun 19, 2019 · 1 comment
Open

Hidding query parameter from the controller method #206

dsnkostic opened this issue Jun 19, 2019 · 1 comment

Comments

@dsnkostic
Copy link

In our project we have need to pass Request object to our controller. This is the routes file
POST /check controllers.CheckConotroller.checkStatus(request: Request)
Swagger is generating this output for the parameters object:
"parameters": [ { "name": "request", "in": "query", "required": false, "type": "string" } ],

Is there any way to remove the request parameter from the swagger generation?

In swagger annotations document (https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X#apiparam), there is a reference to the @ApiParam annotation and hidden flag, but that does not work. With @ApiParam you can control what metadata you want to generate for the given query parameter, but as soon as you set hidden to true, all metadata are ignored and parameter is still in documentation.

An example
If you have controller method declaration like this:
public CompletionStage<Result> checkStatus(@ApiParam(required = true, type = "1", value = "something") Http.Request request)
then you get this in documentation:
"parameters": [ { "name": "request", "in": "query", "description": "something", "required": true, "type": "1" } ],
However, if you set hidden to true:
public CompletionStage<Result> checkStatus(@ApiParam(required = true, type = "1", value = "something", hidden = true) Http.Request request)
then all annotation metadata is ignored and parameter is reverted back (or it is indeed removed, but default one is added once again):
"parameters": [ { "name": "request", "in": "query", "required": false, "type": "string" } ],

Adding an implicit parameter with the same name,, just adds another parameter without affecting the existing one.

Using Play for Java version: 2.7.0
and swagger-play2 version: 1.6.1

@dsnkostic dsnkostic changed the title Hiding query parameter from the controller method Hidding query parameter from the controller method Jun 19, 2019
@Rendrik
Copy link

Rendrik commented Apr 17, 2020

We've come across this issue moving to play 2.7, where the HTTP Request really needs to be added to the route as a parameter.
Our solution is to intercept the request and just remove any route parameters with the name of "request".

      Map<String, Path> paths = swagger.getPaths();
      if(paths != null) {
        for(String key : paths.keySet()) {
          List<Operation> ops = paths.get(key).getOperations();
          for(Operation op : ops) {
            List<Parameter> params = op.getParameters();
            params.removeIf(f -> "request".equals(f.getName()));   
          }
        }
      }

This is an easy solution assuming that the route being added is always the same name, and that there aren't any real API parameters also named "route".

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

No branches or pull requests

2 participants