Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 830B217C39 for ; Thu, 5 Nov 2015 11:32:39 +0000 (UTC) Received: (qmail 1192 invoked by uid 500); 5 Nov 2015 11:32:39 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 1133 invoked by uid 500); 5 Nov 2015 11:32:39 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 1124 invoked by uid 99); 5 Nov 2015 11:32:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Nov 2015 11:32:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2717DE3915; Thu, 5 Nov 2015 11:32:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sergeyb@apache.org To: commits@cxf.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: cxf git commit: [CXF-6633] Normalized resource path in SwaggerSerializer Date: Thu, 5 Nov 2015 11:32:39 +0000 (UTC) Repository: cxf Updated Branches: refs/heads/3.0.x-fixes 9b0e4b5d9 -> de2acc903 [CXF-6633] Normalized resource path in SwaggerSerializer Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/de2acc90 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/de2acc90 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/de2acc90 Branch: refs/heads/3.0.x-fixes Commit: de2acc903c70db1950804c725bcf38ffbacf7826 Parents: 9b0e4b5 Author: Andrei Shakirin Authored: Wed Nov 4 20:25:32 2015 +0100 Committer: Sergey Beryozkin Committed: Thu Nov 5 11:32:19 2015 +0000 ---------------------------------------------------------------------- .../cxf/jaxrs/swagger/Swagger2Serializers.java | 39 +++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/de2acc90/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java ---------------------------------------------------------------------- diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java index c67ce85..71810d4 100644 --- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java +++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java @@ -33,7 +33,6 @@ import javax.ws.rs.core.MultivaluedMap; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; - import org.apache.cxf.jaxrs.ext.MessageContext; import org.apache.cxf.jaxrs.model.ClassResourceInfo; import org.apache.cxf.jaxrs.model.OperationResourceInfo; @@ -93,20 +92,11 @@ public class Swagger2Serializers extends SwaggerSerializers { new HashMap, OperationResourceInfo>(); for (ClassResourceInfo cri : cris) { for (OperationResourceInfo ori : cri.getMethodDispatcher().getOperationResourceInfos()) { - StringBuilder fullPath = new StringBuilder(). - append(cri.getURITemplate().getValue()). - append(ori.getURITemplate().getValue()); - if (fullPath.charAt(fullPath.length() - 1) == '/') { - fullPath.setLength(fullPath.length() - 1); - } - // Adapt to Swagger's path expression - if (fullPath.toString().endsWith(":.*}")) { - fullPath.setLength(fullPath.length() - 4); - fullPath.append('}'); - } + String normalizedPath = getNormalizedPath(cri.getURITemplate().getValue(), ori + .getURITemplate().getValue()); - operations.put(fullPath.toString(), cri); - methods.put(ImmutablePair.of(ori.getHttpMethod(), fullPath.toString()), ori); + operations.put(normalizedPath, cri); + methods.put(ImmutablePair.of(ori.getHttpMethod(), normalizedPath), ori); } } @@ -155,4 +145,25 @@ public class Swagger2Serializers extends SwaggerSerializers { super.writeTo(data, type, genericType, annotations, mediaType, headers, out); } + + private String getNormalizedPath(String classResourcePath, String operationResourcePath) { + StringBuilder path = new StringBuilder(). + append(classResourcePath). + append(operationResourcePath); + + StringBuilder normalizedPath = new StringBuilder(); + + String[] segments = StringUtils.split(path.toString(), "/"); + for (String segment : segments) { + if (!StringUtils.isEmpty(segment)) { + normalizedPath.append("/").append(segment); + } + } + // Adapt to Swagger's path expression + if (normalizedPath.toString().endsWith(":.*}")) { + normalizedPath.setLength(normalizedPath.length() - 4); + normalizedPath.append('}'); + } + return normalizedPath.toString(); + } }