diff --git a/src/main/java/com/sebastian_daschner/jaxrs_analyzer/analysis/javadoc/JavaDocParserVisitor.java b/src/main/java/com/sebastian_daschner/jaxrs_analyzer/analysis/javadoc/JavaDocParserVisitor.java index d11c663..4c810d7 100644 --- a/src/main/java/com/sebastian_daschner/jaxrs_analyzer/analysis/javadoc/JavaDocParserVisitor.java +++ b/src/main/java/com/sebastian_daschner/jaxrs_analyzer/analysis/javadoc/JavaDocParserVisitor.java @@ -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; @@ -132,10 +134,21 @@ private MemberParameterTag createMemberParamTag(JavadocDescription javadocDescri Map 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 createResponseComments(Javadoc javadoc) { return javadoc.getBlockTags().stream() .filter(t -> ResponseCommentExtractor.RESPONSE_TAG_NAME.equalsIgnoreCase(t.getTagName())) diff --git a/src/test/java/com/sebastian_daschner/jaxrs_analyzer/analysis/ProjectAnalyzerTest.java b/src/test/java/com/sebastian_daschner/jaxrs_analyzer/analysis/ProjectAnalyzerTest.java index bfc0386..1d36bd1 100644 --- a/src/test/java/com/sebastian_daschner/jaxrs_analyzer/analysis/ProjectAnalyzerTest.java +++ b/src/test/java/com/sebastian_daschner/jaxrs_analyzer/analysis/ProjectAnalyzerTest.java @@ -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<>(); diff --git a/src/test/jaxrs-test/com/sebastian_daschner/jaxrs_test/ComplexResources.java b/src/test/jaxrs-test/com/sebastian_daschner/jaxrs_test/ComplexResources.java index cce5dbd..2ccf4e3 100644 --- a/src/test/jaxrs-test/com/sebastian_daschner/jaxrs_test/ComplexResources.java +++ b/src/test/jaxrs-test/com/sebastian_daschner/jaxrs_test/ComplexResources.java @@ -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. @@ -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(); + } + }