diff --git a/src/main/java/org/restdoc/server/impl/annotations/RestDoc.java b/src/main/java/org/restdoc/annotations/RestDoc.java similarity index 96% rename from src/main/java/org/restdoc/server/impl/annotations/RestDoc.java rename to src/main/java/org/restdoc/annotations/RestDoc.java index fc7fe47..ebaabb3 100644 --- a/src/main/java/org/restdoc/server/impl/annotations/RestDoc.java +++ b/src/main/java/org/restdoc/annotations/RestDoc.java @@ -1,4 +1,4 @@ -package org.restdoc.server.impl.annotations; +package org.restdoc.annotations; /* * #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you diff --git a/src/main/java/org/restdoc/server/impl/annotations/RestDocAccept.java b/src/main/java/org/restdoc/annotations/RestDocAccept.java similarity index 95% rename from src/main/java/org/restdoc/server/impl/annotations/RestDocAccept.java rename to src/main/java/org/restdoc/annotations/RestDocAccept.java index 7a55757..cc5310d 100644 --- a/src/main/java/org/restdoc/server/impl/annotations/RestDocAccept.java +++ b/src/main/java/org/restdoc/annotations/RestDocAccept.java @@ -1,4 +1,4 @@ -package org.restdoc.server.impl.annotations; +package org.restdoc.annotations; /* * #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you diff --git a/src/main/java/org/restdoc/server/impl/annotations/RestDocHeader.java b/src/main/java/org/restdoc/annotations/RestDocHeader.java similarity index 96% rename from src/main/java/org/restdoc/server/impl/annotations/RestDocHeader.java rename to src/main/java/org/restdoc/annotations/RestDocHeader.java index 82db94b..54468fb 100644 --- a/src/main/java/org/restdoc/server/impl/annotations/RestDocHeader.java +++ b/src/main/java/org/restdoc/annotations/RestDocHeader.java @@ -1,4 +1,4 @@ -package org.restdoc.server.impl.annotations; +package org.restdoc.annotations; /* * #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you diff --git a/src/main/java/org/restdoc/server/impl/annotations/RestDocIgnore.java b/src/main/java/org/restdoc/annotations/RestDocIgnore.java similarity index 95% rename from src/main/java/org/restdoc/server/impl/annotations/RestDocIgnore.java rename to src/main/java/org/restdoc/annotations/RestDocIgnore.java index 8694aff..93bde51 100644 --- a/src/main/java/org/restdoc/server/impl/annotations/RestDocIgnore.java +++ b/src/main/java/org/restdoc/annotations/RestDocIgnore.java @@ -1,4 +1,4 @@ -package org.restdoc.server.impl.annotations; +package org.restdoc.annotations; /* * #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you diff --git a/src/main/java/org/restdoc/server/impl/annotations/RestDocParam.java b/src/main/java/org/restdoc/annotations/RestDocParam.java similarity index 95% rename from src/main/java/org/restdoc/server/impl/annotations/RestDocParam.java rename to src/main/java/org/restdoc/annotations/RestDocParam.java index 37517e3..db8b420 100644 --- a/src/main/java/org/restdoc/server/impl/annotations/RestDocParam.java +++ b/src/main/java/org/restdoc/annotations/RestDocParam.java @@ -1,4 +1,4 @@ -package org.restdoc.server.impl.annotations; +package org.restdoc.annotations; /* * #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you diff --git a/src/main/java/org/restdoc/server/impl/annotations/RestDocResponse.java b/src/main/java/org/restdoc/annotations/RestDocResponse.java similarity index 95% rename from src/main/java/org/restdoc/server/impl/annotations/RestDocResponse.java rename to src/main/java/org/restdoc/annotations/RestDocResponse.java index ce63074..8f04bf8 100644 --- a/src/main/java/org/restdoc/server/impl/annotations/RestDocResponse.java +++ b/src/main/java/org/restdoc/annotations/RestDocResponse.java @@ -1,4 +1,4 @@ -package org.restdoc.server.impl.annotations; +package org.restdoc.annotations; /* * #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you diff --git a/src/main/java/org/restdoc/server/impl/annotations/RestDocReturnCode.java b/src/main/java/org/restdoc/annotations/RestDocReturnCode.java similarity index 95% rename from src/main/java/org/restdoc/server/impl/annotations/RestDocReturnCode.java rename to src/main/java/org/restdoc/annotations/RestDocReturnCode.java index c1c0a10..848f3dc 100644 --- a/src/main/java/org/restdoc/server/impl/annotations/RestDocReturnCode.java +++ b/src/main/java/org/restdoc/annotations/RestDocReturnCode.java @@ -1,4 +1,4 @@ -package org.restdoc.server.impl.annotations; +package org.restdoc.annotations; /* * #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you diff --git a/src/main/java/org/restdoc/server/impl/annotations/RestDocReturnCodes.java b/src/main/java/org/restdoc/annotations/RestDocReturnCodes.java similarity index 95% rename from src/main/java/org/restdoc/server/impl/annotations/RestDocReturnCodes.java rename to src/main/java/org/restdoc/annotations/RestDocReturnCodes.java index 3c8cdef..928e4d2 100644 --- a/src/main/java/org/restdoc/server/impl/annotations/RestDocReturnCodes.java +++ b/src/main/java/org/restdoc/annotations/RestDocReturnCodes.java @@ -1,4 +1,4 @@ -package org.restdoc.server.impl.annotations; +package org.restdoc.annotations; /* * #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you diff --git a/src/main/java/org/restdoc/server/impl/annotations/RestDocSchema.java b/src/main/java/org/restdoc/annotations/RestDocSchema.java similarity index 95% rename from src/main/java/org/restdoc/server/impl/annotations/RestDocSchema.java rename to src/main/java/org/restdoc/annotations/RestDocSchema.java index 162384c..0872d0e 100644 --- a/src/main/java/org/restdoc/server/impl/annotations/RestDocSchema.java +++ b/src/main/java/org/restdoc/annotations/RestDocSchema.java @@ -1,4 +1,4 @@ -package org.restdoc.server.impl.annotations; +package org.restdoc.annotations; /* * #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you diff --git a/src/main/java/org/restdoc/server/impl/annotations/RestDocType.java b/src/main/java/org/restdoc/annotations/RestDocType.java similarity index 96% rename from src/main/java/org/restdoc/server/impl/annotations/RestDocType.java rename to src/main/java/org/restdoc/annotations/RestDocType.java index 0eb4977..e5691b5 100644 --- a/src/main/java/org/restdoc/server/impl/annotations/RestDocType.java +++ b/src/main/java/org/restdoc/annotations/RestDocType.java @@ -1,4 +1,4 @@ -package org.restdoc.server.impl.annotations; +package org.restdoc.annotations; /* * #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you diff --git a/src/main/java/org/restdoc/server/impl/annotations/RestDocValidation.java b/src/main/java/org/restdoc/annotations/RestDocValidation.java similarity index 95% rename from src/main/java/org/restdoc/server/impl/annotations/RestDocValidation.java rename to src/main/java/org/restdoc/annotations/RestDocValidation.java index be09618..ae74774 100644 --- a/src/main/java/org/restdoc/server/impl/annotations/RestDocValidation.java +++ b/src/main/java/org/restdoc/annotations/RestDocValidation.java @@ -1,4 +1,4 @@ -package org.restdoc.server.impl.annotations; +package org.restdoc.annotations; /* * #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you diff --git a/src/main/java/org/restdoc/server/impl/RestDocGenerator.java b/src/main/java/org/restdoc/server/impl/RestDocGenerator.java index 25a65d2..001d708 100644 --- a/src/main/java/org/restdoc/server/impl/RestDocGenerator.java +++ b/src/main/java/org/restdoc/server/impl/RestDocGenerator.java @@ -12,12 +12,14 @@ */ import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.lang.reflect.Type; import java.math.BigDecimal; import java.math.BigInteger; import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; @@ -28,16 +30,21 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; import javax.ws.rs.HttpMethod; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; +import org.restdoc.annotations.RestDocAccept; +import org.restdoc.annotations.RestDocHeader; +import org.restdoc.annotations.RestDocIgnore; +import org.restdoc.annotations.RestDocParam; +import org.restdoc.annotations.RestDocResponse; +import org.restdoc.annotations.RestDocReturnCode; +import org.restdoc.annotations.RestDocReturnCodes; +import org.restdoc.annotations.RestDocType; +import org.restdoc.annotations.RestDocValidation; import org.restdoc.api.GlobalHeader; import org.restdoc.api.HeaderDefinition; import org.restdoc.api.MethodDefinition; @@ -49,15 +56,6 @@ import org.restdoc.api.RestResource; import org.restdoc.api.Schema; import org.restdoc.api.util.RestDocParser; -import org.restdoc.server.impl.annotations.RestDocAccept; -import org.restdoc.server.impl.annotations.RestDocHeader; -import org.restdoc.server.impl.annotations.RestDocIgnore; -import org.restdoc.server.impl.annotations.RestDocParam; -import org.restdoc.server.impl.annotations.RestDocResponse; -import org.restdoc.server.impl.annotations.RestDocReturnCode; -import org.restdoc.server.impl.annotations.RestDocReturnCodes; -import org.restdoc.server.impl.annotations.RestDocType; -import org.restdoc.server.impl.annotations.RestDocValidation; import org.restdoc.server.impl.util.MediaTypeResolver; import org.restdoc.server.impl.util.SchemaResolver; import org.slf4j.Logger; @@ -157,11 +155,7 @@ private void addResourcesOfClass(final Class apiClass, final String baseURI) // find methods final Method[] methods = apiClass.getMethods(); for (final Method method : methods) { - if (method.isAnnotationPresent(Path.class) || // - method.isAnnotationPresent(GET.class) || // - method.isAnnotationPresent(POST.class) || // - method.isAnnotationPresent(PUT.class) || // - method.isAnnotationPresent(DELETE.class)) { + if (method.isAnnotationPresent(Path.class) || (RestDocGenerator.getHTTPVerb(method) != null)) { this.logger.debug("Generating RestDoc of method: " + method.toString()); this.addResourceMethod(basepath, method); } @@ -176,7 +170,7 @@ private void addResourceMethod(final String basepath, final Method method) { // get needed annotations from method final String methodType = RestDocGenerator.getHTTPVerb(method); - final org.restdoc.server.impl.annotations.RestDoc docAnnotation = method.getAnnotation(org.restdoc.server.impl.annotations.RestDoc.class); + final org.restdoc.annotations.RestDoc docAnnotation = method.getAnnotation(org.restdoc.annotations.RestDoc.class); final Path pathAnnotation = method.getAnnotation(Path.class); String path = basepath; @@ -205,24 +199,11 @@ private void addResourceMethod(final String basepath, final Method method) { path += "{?" + string + "}"; } - String id; + final String id; if ((docAnnotation != null) && (docAnnotation.id() != null) && !docAnnotation.id().isEmpty()) { id = docAnnotation.id(); } else { - try { - MessageDigest md = MessageDigest.getInstance("MD5"); - byte[] digest = md.digest(path.getBytes("UTF-8")); - BigInteger bigInt = new BigInteger(1, digest); - String hashtext = bigInt.toString(16); - // Now we need to zero pad it if you actually want the full 32 chars. - while (hashtext.length() < 32) { - hashtext = "0" + hashtext; - } - id = hashtext; - } catch (Exception e) { - this.logger.warn("Failed to generate MD5 sum", e); - id = method.getName(); - } + id = this.getDefaultResourceId(method, path); } final String resourceDescription = (docAnnotation != null) ? docAnnotation.resourceDescription() : null; @@ -261,6 +242,25 @@ private void addResourceMethod(final String basepath, final Method method) { this.ext.newMethod(restResource, def, method); } + private String getDefaultResourceId(final Method method, String path) { + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] digest = md.digest(path.getBytes("UTF-8")); + BigInteger bigInt = new BigInteger(1, digest); + String hashtext = bigInt.toString(16); + // Now we need to zero pad it if you actually want the full 32 chars. + while (hashtext.length() < 32) { + hashtext = "0" + hashtext; + } + return hashtext; + } catch (NoSuchAlgorithmException e) { + this.logger.warn("Failed to generate MD5 sum", e); + } catch (UnsupportedEncodingException e) { + this.logger.warn("Failed to generate MD5 sum", e); + } + return method.getName(); + } + /** * @param queryParams * @param methodRequestHeader diff --git a/src/main/java/org/restdoc/server/impl/util/SchemaResolver.java b/src/main/java/org/restdoc/server/impl/util/SchemaResolver.java index 0864478..0e800a5 100644 --- a/src/main/java/org/restdoc/server/impl/util/SchemaResolver.java +++ b/src/main/java/org/restdoc/server/impl/util/SchemaResolver.java @@ -6,11 +6,11 @@ import java.util.Collection; import java.util.Map; +import org.restdoc.annotations.RestDocSchema; import org.restdoc.api.Schema; import org.restdoc.api.util.RestDocParser; import org.restdoc.server.impl.IRestDocGeneratorExtension; import org.restdoc.server.impl.RestDocException; -import org.restdoc.server.impl.annotations.RestDocSchema; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/src/test/java/org/restdoc/server/impl/Msg.java b/src/test/java/org/restdoc/server/impl/Msg.java index bc34c78..af54a9a 100644 --- a/src/test/java/org/restdoc/server/impl/Msg.java +++ b/src/test/java/org/restdoc/server/impl/Msg.java @@ -11,7 +11,7 @@ * and limitations under the License. #L% */ -import org.restdoc.server.impl.annotations.RestDocSchema; +import org.restdoc.annotations.RestDocSchema; /** * diff --git a/src/test/java/org/restdoc/server/impl/MyDeepRes.java b/src/test/java/org/restdoc/server/impl/MyDeepRes.java index 537ca87..3289d1b 100644 --- a/src/test/java/org/restdoc/server/impl/MyDeepRes.java +++ b/src/test/java/org/restdoc/server/impl/MyDeepRes.java @@ -7,9 +7,9 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import org.restdoc.server.impl.annotations.RestDocIgnore; -import org.restdoc.server.impl.annotations.RestDocReturnCode; -import org.restdoc.server.impl.annotations.RestDocReturnCodes; +import org.restdoc.annotations.RestDocIgnore; +import org.restdoc.annotations.RestDocReturnCode; +import org.restdoc.annotations.RestDocReturnCodes; @Produces("text/plain") @Consumes("text/plain") diff --git a/src/test/java/org/restdoc/server/impl/MyRSBean.java b/src/test/java/org/restdoc/server/impl/MyRSBean.java index 22b17b3..00b7571 100644 --- a/src/test/java/org/restdoc/server/impl/MyRSBean.java +++ b/src/test/java/org/restdoc/server/impl/MyRSBean.java @@ -26,13 +26,13 @@ import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response.Status; +import org.restdoc.annotations.RestDoc; +import org.restdoc.annotations.RestDocHeader; +import org.restdoc.annotations.RestDocParam; +import org.restdoc.annotations.RestDocResponse; +import org.restdoc.annotations.RestDocReturnCode; +import org.restdoc.annotations.RestDocReturnCodes; import org.restdoc.server.ext.oauth2.Scopes; -import org.restdoc.server.impl.annotations.RestDoc; -import org.restdoc.server.impl.annotations.RestDocHeader; -import org.restdoc.server.impl.annotations.RestDocParam; -import org.restdoc.server.impl.annotations.RestDocResponse; -import org.restdoc.server.impl.annotations.RestDocReturnCode; -import org.restdoc.server.impl.annotations.RestDocReturnCodes; import com.google.common.collect.Maps;