Skip to content

Commit

Permalink
Merge branch 'issue#180' of https://github.com/rmpestano/jaxrs-analyzer
Browse files Browse the repository at this point in the history
… into rmpestano-issue#180
  • Loading branch information
sdaschner committed Oct 13, 2018
2 parents 7e0f013 + 741f76d commit 8e0b8f2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.github.javaparser.ast.comments.Comment;
import com.github.javaparser.ast.expr.AnnotationExpr;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.NameExpr;
import com.github.javaparser.ast.expr.StringLiteralExpr;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import com.github.javaparser.javadoc.Javadoc;
import com.github.javaparser.javadoc.JavadocBlockTag;
Expand Down Expand Up @@ -132,10 +134,21 @@ private MemberParameterTag createMemberParamTag(JavadocDescription javadocDescri
Map<String, String> annotations = annotationStream
.filter(Expression::isSingleMemberAnnotationExpr)
.collect(Collectors.toMap(a -> a.getName().getIdentifier(),
a -> a.asSingleMemberAnnotationExpr().getMemberValue().asStringLiteralExpr().asString()));
a -> createMemberParamValue(a)));
return new MemberParameterTag(javadocDescription.toText(), annotations);
}

private String createMemberParamValue(AnnotationExpr a) {
Expression memberValue = a.asSingleMemberAnnotationExpr().getMemberValue();
if(memberValue.getClass().isAssignableFrom(StringLiteralExpr.class)) {
return memberValue.asStringLiteralExpr().asString();
} else if(memberValue.getClass().isAssignableFrom(NameExpr.class)) {
return memberValue.asNameExpr().getNameAsString();
}
throw new IllegalArgumentException(String.format("Javadoc param type (%s) not supported.",memberValue.toString()));

}

private Map<Integer, String> createResponseComments(Javadoc javadoc) {
return javadoc.getBlockTags().stream()
.filter(t -> ResponseCommentExtractor.RESPONSE_TAG_NAME.equalsIgnoreCase(t.getTagName()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ private static Resources getResources() {
.andResponse(200, ResponseBuilder.withResponseBody(stringIdentifier).build()).build();
addMethods(resources, "complex/anotherSubres/{name}", eleventhGet);

// complex/auth
ResourceMethod authGet = ResourceMethodBuilder.withMethod(HttpMethod.GET, "Creates an authorization endpoint.")
.andHeaderParam("Authorization", Types.STRING)
.andResponse(200, ResponseBuilder.withResponseBody(stringIdentifier).build()).build();
addMethods(resources, "complex/auth", authGet);

// json_tests
final TypeIdentifier firstIdentifier = TypeIdentifier.ofDynamic();
properties = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.HeaderParam;
import java.util.ArrayList;
import static javax.ws.rs.core.HttpHeaders.AUTHORIZATION;


/**
* These sources are solely used for test purposes and not meant for deployment.
Expand Down Expand Up @@ -84,4 +87,15 @@ public SomeSubResource anotherSubresResource() {
return rc.getResource(SubResources.class);
}

/**
* Creates an authorization endpoint.
*
* @param token auth token
*/
@GET
@Path("auth")
public Response get(@HeaderParam(AUTHORIZATION) String token) {
return Response.ok("Authorized").build();
}

}

0 comments on commit 8e0b8f2

Please sign in to comment.