Skip to content

Commit 524c0d9

Browse files
Carter Kozakvelo
authored andcommitted
@path("") annotations are equivalent to @path("/") (OpenFeign#631)
The documentation suggests that all paths are relative: https://docs.oracle.com/javaee/6/api/javax/ws/rs/Path.html
1 parent 982ee99 commit 524c0d9

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

jaxrs/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ server interface behavior.
1111
## Currently Supported Annotation Processing
1212
Feign only supports processing java interfaces (not abstract or concrete classes).
1313

14-
ISE is raised when any annotation's value is empty or null. Ex. `Path("")` raises an ISE.
15-
1614
Here are a list of behaviors currently supported.
1715
### Type Annotations
1816
#### `@Path`

jaxrs/src/main/java/feign/jaxrs/JAXRSContract.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ protected MethodMetadata parseAndValidateMetadata(Class<?> targetType, Method me
5252
@Override
5353
protected void processAnnotationOnClass(MethodMetadata data, Class<?> clz) {
5454
Path path = clz.getAnnotation(Path.class);
55-
if (path != null) {
56-
String pathValue = emptyToNull(path.value());
57-
checkState(pathValue != null, "Path.value() was empty on type %s", clz.getName());
55+
if (path != null && !path.value().isEmpty()) {
56+
String pathValue = path.value();
5857
if (!pathValue.startsWith("/")) {
5958
pathValue = "/" + pathValue;
6059
}
@@ -86,7 +85,9 @@ protected void processAnnotationOnMethod(MethodMetadata data, Annotation methodA
8685
data.template().method(http.value());
8786
} else if (annotationType == Path.class) {
8887
String pathValue = emptyToNull(Path.class.cast(methodAnnotation).value());
89-
checkState(pathValue != null, "Path.value() was empty on method %s", method.getName());
88+
if (pathValue == null) {
89+
return;
90+
}
9091
String methodAnnotationValue = Path.class.cast(methodAnnotation).value();
9192
if (!methodAnnotationValue.startsWith("/") && !data.template().url().endsWith("/")) {
9293
methodAnnotationValue = "/" + methodAnnotationValue;

jaxrs/src/test/java/feign/jaxrs/JAXRSContractTest.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,14 @@ public void tooManyBodies() throws Exception {
192192

193193
@Test
194194
public void emptyPathOnType() throws Exception {
195-
thrown.expect(IllegalStateException.class);
196-
thrown.expectMessage("Path.value() was empty on type ");
195+
assertThat(parseAndValidateMetadata(EmptyPathOnType.class, "base").template())
196+
.hasUrl("");
197+
}
197198

198-
parseAndValidateMetadata(EmptyPathOnType.class, "base");
199+
@Test
200+
public void emptyPathOnTypeSpecific() throws Exception {
201+
assertThat(parseAndValidateMetadata(EmptyPathOnType.class, "get").template())
202+
.hasUrl("/specific");
199203
}
200204

201205
@Test
@@ -209,10 +213,8 @@ public void parsePathMethod() throws Exception {
209213

210214
@Test
211215
public void emptyPathOnMethod() throws Exception {
212-
thrown.expect(IllegalStateException.class);
213-
thrown.expectMessage("Path.value() was empty on method emptyPath");
214-
215-
parseAndValidateMetadata(PathOnType.class,"emptyPath");
216+
assertThat(parseAndValidateMetadata(PathOnType.class,"emptyPath").template())
217+
.hasUrl("/base");
216218
}
217219

218220
@Test
@@ -462,6 +464,10 @@ interface EmptyPathOnType {
462464

463465
@GET
464466
Response base();
467+
468+
@GET
469+
@Path("/specific")
470+
Response get();
465471
}
466472

467473
@Path("/base")

0 commit comments

Comments
 (0)