Skip to content

Add support for required query parameters #540

Closed
@ferrazoli

Description

@ferrazoli

The documentation states that:

Query parameters are considered optional / nullable.

It would be useful if we could pass a boolean value to the @QueryParam annotation indicating that such query parameter is required, and that the request should fail if it's not present.

Something like @QueryParam(required = true) would be very useful.

This would prevent a lot of boilerplate code for checking that required params are present.

This:

@Post
public void doSomething(@QueryParam String foo) {
  if (foo == null) {
    throw new SomeException("Query parameter \"foo\" is required");
  }
  // do stuff
}

Becomes:

@Post
public void doSomething(@QueryParam(required = true) String foo) {
  // do stuff
}

Another example, with an explicit parameter name "my-foo".

@Post
public void doSomething(@QueryParam(value = "my-foo", required = true) String myFoo) {
  // do stuff
}

Edit: Updated the examples above because as the method parameter name matches ("foo" matches foo).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions