From 6b087ad3b0201c829189b378a97f6bd0fbd63515 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 25 Apr 2016 17:31:35 -0700 Subject: [PATCH] Fixing bug when service classes had no path specified (#50) Correct behavior is to default to the empty path --- .../palantir/code/ts/generator/ServiceClassParser.java | 2 +- .../code/ts/generator/ServiceClassParserTest.java | 9 +++++++++ .../com/palantir/code/ts/generator/utils/TestUtils.java | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/typescript-service-generator-core/src/main/java/com/palantir/code/ts/generator/ServiceClassParser.java b/typescript-service-generator-core/src/main/java/com/palantir/code/ts/generator/ServiceClassParser.java index 647a738..257498a 100644 --- a/typescript-service-generator-core/src/main/java/com/palantir/code/ts/generator/ServiceClassParser.java +++ b/typescript-service-generator-core/src/main/java/com/palantir/code/ts/generator/ServiceClassParser.java @@ -72,7 +72,7 @@ public ServiceModel parseServiceClass(Class mainServiceClass, TypescriptServi for (Class serviceClass : serviceClazzes) { ImmutableInnerServiceModel.Builder innerServiceModel = ImmutableInnerServiceModel.builder(); Path servicePathAnnotation = serviceClass.getAnnotation(Path.class); - innerServiceModel.servicePath(PathUtils.trimSlashes(servicePathAnnotation.value())); + innerServiceModel.servicePath(servicePathAnnotation == null ? "" : PathUtils.trimSlashes(servicePathAnnotation.value())); innerServiceModel.name(serviceClass.getSimpleName()); Set serviceMethods = getAllServiceMethods(serviceClass, settings.methodFilter()); diff --git a/typescript-service-generator-core/src/test/java/com/palantir/code/ts/generator/ServiceClassParserTest.java b/typescript-service-generator-core/src/test/java/com/palantir/code/ts/generator/ServiceClassParserTest.java index 76aa97e..8711dc0 100644 --- a/typescript-service-generator-core/src/test/java/com/palantir/code/ts/generator/ServiceClassParserTest.java +++ b/typescript-service-generator-core/src/test/java/com/palantir/code/ts/generator/ServiceClassParserTest.java @@ -35,6 +35,7 @@ import com.palantir.code.ts.generator.model.ServiceEndpointModel; import com.palantir.code.ts.generator.model.ServiceEndpointParameterModel; import com.palantir.code.ts.generator.model.ServiceModel; +import com.palantir.code.ts.generator.utils.TestUtils; import com.palantir.code.ts.generator.utils.TestUtils.DataObject; import com.palantir.code.ts.generator.utils.TestUtils.DuplicateMethodNamesService; import com.palantir.code.ts.generator.utils.TestUtils.GenericObject; @@ -290,4 +291,12 @@ public void plainTextTest() { assertEquals(expectedServiceModel, model); } + @Test + public void noServiceClassPathTest() { + ServiceModel model = serviceClassParser.parseServiceClass(TestUtils.NoPathService.class, settings); + + assertEquals(1, model.innerServiceModels().size()); + assertEquals(1, model.innerServiceModels().get(0).endpointModels().size()); + assertEquals("", model.innerServiceModels().get(0).servicePath()); + } } diff --git a/typescript-service-generator-core/src/test/java/com/palantir/code/ts/generator/utils/TestUtils.java b/typescript-service-generator-core/src/test/java/com/palantir/code/ts/generator/utils/TestUtils.java index a179884..9f48bfc 100644 --- a/typescript-service-generator-core/src/test/java/com/palantir/code/ts/generator/utils/TestUtils.java +++ b/typescript-service-generator-core/src/test/java/com/palantir/code/ts/generator/utils/TestUtils.java @@ -115,6 +115,13 @@ public interface PlainTextService { public String plainText(String dataBody); } + public interface NoPathService { + + @GET + @Path("foo") + public String foo(); + } + public enum MyEnum { VALUE1, VALUE2 }