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

Add ability to annotate parameters by Hidden annotaion #4714

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;

/**
* Marks a given resource, class or bean type as hidden, skipping while reading / resolving
**/
@Target({METHOD, TYPE, FIELD, ANNOTATION_TYPE})
@Target({PARAMETER, METHOD, TYPE, FIELD, ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Hidden {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ public static Parameter applyAnnotations(
}

for (Annotation annotation : annotations) {
if (annotation instanceof io.swagger.v3.oas.annotations.Hidden) {
return null;
}
if (annotation instanceof io.swagger.v3.oas.annotations.Parameter) {
io.swagger.v3.oas.annotations.Parameter p = (io.swagger.v3.oas.annotations.Parameter) annotation;
if (p.hidden()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public ResolvedParameter extractParameters(List<Annotation> annotations,
pp.setIn(COOKIE_PARAM);
pp.setName(param.value());
parameter = pp;
} else if (annotation instanceof io.swagger.v3.oas.annotations.Hidden) {
return new ResolvedParameter();
} else if (annotation instanceof io.swagger.v3.oas.annotations.Parameter) {
if (((io.swagger.v3.oas.annotations.Parameter) annotation).hidden()) {
return new ResolvedParameter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,24 @@ public void testHiddenAnnotatedUserResource() throws IOException {
" content:\n" +
" 'application/json': {}\n" +
" 'application/xml': {}\n" +
" /user/3:\n" +
" get:\n" +
" summary: Select user\n" +
" operationId: selectUser\n" +
" parameters:\n" +
" - name: id\n" +
" in: query\n" +
" description: User id\n" +
" required: true\n" +
" schema:\n" +
" type: integer\n" +
" format: int32\n" +
" responses:\n" +
" default:\n" +
" description: default response\n" +
" content:\n" +
" 'application/json': {}\n" +
" 'application/xml': {}\n" +
"components:\n" +
" schemas:\n" +
" UserResourceBean:\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

@Path("/user")
Expand Down Expand Up @@ -50,6 +52,17 @@ public Response createUserWithHiddenBeanProperty(
@Parameter(description = "Created user object", required = true) UserResourceBean user) {
return Response.ok().entity("").build();
}

@GET
@Operation(summary = "Select user")
@Path("/3")
public Response selectUser(
@QueryParam("id") @Parameter(description = "User id", required = true) Integer id,
@QueryParam("name") @Parameter(hidden = true) String name,
@QueryParam("secondName") @Hidden String secondName
) {
return Response.ok().entity("").build();
}
}

public class UserResourceBean {
Expand Down