You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zr...@apache.org on 2017/03/29 11:21:09 UTC
camel git commit: CAMEL-11091 REST Swagger handling of empty spec...
Repository: camel
Updated Branches:
refs/heads/master 112ef7851 -> 2212ca4ad
CAMEL-11091 REST Swagger handling of empty spec...
...ificationUri
The specificatonUri for endpoint URIs starting with `#` in the remaining
part of the URI (i.e. `rest-swagger:#getPetById`) now default to
`swagger.json`.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2212ca4a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2212ca4a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2212ca4a
Branch: refs/heads/master
Commit: 2212ca4ad54cf4f607bbdd7001a0f588a6d4db83
Parents: 112ef78
Author: Zoran Regvart <zr...@apache.org>
Authored: Wed Mar 29 13:21:04 2017 +0200
Committer: Zoran Regvart <zr...@apache.org>
Committed: Wed Mar 29 13:21:04 2017 +0200
----------------------------------------------------------------------
.../rest/swagger/RestSwaggerEndpoint.java | 3 +-
.../rest/swagger/RestSwaggerEndpointTest.java | 30 +++++++++++++-------
2 files changed, 22 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2212ca4a/components/camel-rest-swagger/src/main/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-rest-swagger/src/main/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpoint.java b/components/camel-rest-swagger/src/main/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpoint.java
index 6046a99..bfc9261 100644
--- a/components/camel-rest-swagger/src/main/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpoint.java
+++ b/components/camel-rest-swagger/src/main/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpoint.java
@@ -55,6 +55,7 @@ import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriPath;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.ResourceHelper;
+import org.apache.camel.util.StringHelper;
import static org.apache.camel.component.rest.swagger.RestSwaggerHelper.isHostParam;
import static org.apache.camel.component.rest.swagger.RestSwaggerHelper.isMediaRange;
@@ -134,7 +135,7 @@ public final class RestSwaggerEndpoint extends DefaultEndpoint {
final URI componentSpecificationUri = component.getSpecificationUri();
- specificationUri = ofNullable(before(remaining, "#")).map(URI::create)
+ specificationUri = before(remaining, "#", StringHelper::trimToNull).map(URI::create)
.orElse(ofNullable(componentSpecificationUri).orElse(RestSwaggerComponent.DEFAULT_SPECIFICATION_URI));
operationId = ofNullable(after(remaining, "#")).orElse(remaining);
http://git-wip-us.apache.org/repos/asf/camel/blob/2212ca4a/components/camel-rest-swagger/src/test/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-rest-swagger/src/test/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpointTest.java b/components/camel-rest-swagger/src/test/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpointTest.java
index e0ea5b4..d16cbee 100644
--- a/components/camel-rest-swagger/src/test/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpointTest.java
+++ b/components/camel-rest-swagger/src/test/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpointTest.java
@@ -247,16 +247,6 @@ public class RestSwaggerEndpointTest {
}
@Test
- public void shouldHaveADefaultSpecificationPathProperty() throws Exception {
- final RestSwaggerComponent component = new RestSwaggerComponent();
-
- final RestSwaggerEndpoint endpoint = new RestSwaggerEndpoint("rest-swagger:getPetById", "getPetById",
- component);
-
- assertThat(endpoint.getSpecificationUri()).isEqualTo(RestSwaggerComponent.DEFAULT_SPECIFICATION_URI);
- }
-
- @Test
public void shouldHonourComponentSpecificationPathProperty() throws Exception {
final RestSwaggerComponent component = new RestSwaggerComponent();
component.setSpecificationUri(componentJsonUri);
@@ -355,4 +345,24 @@ public class RestSwaggerEndpointTest {
RestSwaggerEndpoint.loadSpecificationFrom(camelContext, URI.create("non-existant.json"));
}
+ @Test
+ public void shouldUseDefaultSpecificationUri() throws Exception {
+ final RestSwaggerComponent component = new RestSwaggerComponent();
+
+ final RestSwaggerEndpoint endpoint = new RestSwaggerEndpoint("rest-swagger:getPetById", "getPetById",
+ component);
+
+ assertThat(endpoint.getSpecificationUri()).isEqualTo(RestSwaggerComponent.DEFAULT_SPECIFICATION_URI);
+ }
+
+ @Test
+ public void shouldUseDefaultSpecificationUriEvenIfHashIsPresent() throws Exception {
+ final RestSwaggerComponent component = new RestSwaggerComponent();
+
+ final RestSwaggerEndpoint endpoint = new RestSwaggerEndpoint("rest-swagger:#getPetById", "#getPetById",
+ component);
+
+ assertThat(endpoint.getSpecificationUri()).isEqualTo(RestSwaggerComponent.DEFAULT_SPECIFICATION_URI);
+ }
+
}