From 9db84b2e055ed9dd11fae024c0c7cf860efa71bc Mon Sep 17 00:00:00 2001 From: esword Date: Mon, 18 Mar 2024 16:44:39 -0400 Subject: [PATCH] do not attempt to generate a dialog service if no endpoints (#2237) Skips generating the Endpoints enum if no endpoints. --- changelog/@unreleased/pr-2237.v2.yml | 5 ++ .../dialogue/DialogueServiceGenerator.java | 12 +++-- .../src/test/resources/example-service.yml | 9 ++++ .../test/api/TestEmptyService.java.jersey | 14 +++++ .../api/TestEmptyService.java.jersey.jakarta | 14 +++++ .../api/TestEmptyService.java.jersey.prefix | 14 +++++ ...tEmptyService.java.jersey_require_not_null | 14 +++++ .../test/api/TestEmptyService.java.undertow | 7 +++ .../api/TestEmptyService.java.undertow.prefix | 7 +++ .../api/TestEmptyServiceAsync.java.dialogue | 53 +++++++++++++++++++ ...TestEmptyServiceAsync.java.dialogue.prefix | 53 +++++++++++++++++++ .../TestEmptyServiceBlocking.java.dialogue | 53 +++++++++++++++++++ ...tEmptyServiceBlocking.java.dialogue.prefix | 53 +++++++++++++++++++ .../TestEmptyServiceEndpoints.java.undertow | 26 +++++++++ ...EmptyServiceEndpoints.java.undertow.prefix | 26 +++++++++ 15 files changed, 356 insertions(+), 4 deletions(-) create mode 100644 changelog/@unreleased/pr-2237.v2.yml create mode 100644 conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey create mode 100644 conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey.jakarta create mode 100644 conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey.prefix create mode 100644 conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey_require_not_null create mode 100644 conjure-java-core/src/test/resources/test/api/TestEmptyService.java.undertow create mode 100644 conjure-java-core/src/test/resources/test/api/TestEmptyService.java.undertow.prefix create mode 100644 conjure-java-core/src/test/resources/test/api/TestEmptyServiceAsync.java.dialogue create mode 100644 conjure-java-core/src/test/resources/test/api/TestEmptyServiceAsync.java.dialogue.prefix create mode 100644 conjure-java-core/src/test/resources/test/api/TestEmptyServiceBlocking.java.dialogue create mode 100644 conjure-java-core/src/test/resources/test/api/TestEmptyServiceBlocking.java.dialogue.prefix create mode 100644 conjure-java-core/src/test/resources/test/api/TestEmptyServiceEndpoints.java.undertow create mode 100644 conjure-java-core/src/test/resources/test/api/TestEmptyServiceEndpoints.java.undertow.prefix diff --git a/changelog/@unreleased/pr-2237.v2.yml b/changelog/@unreleased/pr-2237.v2.yml new file mode 100644 index 000000000..dd2b79b2b --- /dev/null +++ b/changelog/@unreleased/pr-2237.v2.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: do not attempt to generate a dialog service if no endpoints + links: + - https://github.com/palantir/conjure-java/pull/2237 diff --git a/conjure-java-core/src/main/java/com/palantir/conjure/java/services/dialogue/DialogueServiceGenerator.java b/conjure-java-core/src/main/java/com/palantir/conjure/java/services/dialogue/DialogueServiceGenerator.java index 69ee79e61..22266e354 100644 --- a/conjure-java-core/src/main/java/com/palantir/conjure/java/services/dialogue/DialogueServiceGenerator.java +++ b/conjure-java-core/src/main/java/com/palantir/conjure/java/services/dialogue/DialogueServiceGenerator.java @@ -82,9 +82,13 @@ public Stream generate(ConjureDefinition conjureDefinition) { StaticFactoryMethodType.BLOCKING); return conjureDefinition.getServices().stream() - .flatMap(serviceDef -> Stream.of( - endpoints.endpointsClass(serviceDef), - interfaceGenerator.generateBlocking(serviceDef, blockingGenerator), - interfaceGenerator.generateAsync(serviceDef, asyncGenerator))); + .flatMap(serviceDef -> !serviceDef.getEndpoints().isEmpty() + ? Stream.of( + endpoints.endpointsClass(serviceDef), + interfaceGenerator.generateBlocking(serviceDef, blockingGenerator), + interfaceGenerator.generateAsync(serviceDef, asyncGenerator)) + : Stream.of( + interfaceGenerator.generateBlocking(serviceDef, blockingGenerator), + interfaceGenerator.generateAsync(serviceDef, asyncGenerator))); } } diff --git a/conjure-java-core/src/test/resources/example-service.yml b/conjure-java-core/src/test/resources/example-service.yml index c7d681481..1253730f2 100644 --- a/conjure-java-core/src/test/resources/example-service.yml +++ b/conjure-java-core/src/test/resources/example-service.yml @@ -278,3 +278,12 @@ services: strings: type: set param-type: query + TestEmptyService: + name: Empty Test Service + package: com.palantir.another + default-auth: header + base-path: /testEmptyService + docs: | + This service has no endpoints. + + endpoints: {} diff --git a/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey b/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey new file mode 100644 index 000000000..0c862fa29 --- /dev/null +++ b/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey @@ -0,0 +1,14 @@ +package com.palantir.another; + +import javax.annotation.processing.Generated; +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +/** This service has no endpoints. */ +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +@Path("/") +@Generated("com.palantir.conjure.java.services.JerseyServiceGenerator") +public interface TestEmptyService {} diff --git a/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey.jakarta b/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey.jakarta new file mode 100644 index 000000000..9e39c816a --- /dev/null +++ b/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey.jakarta @@ -0,0 +1,14 @@ +package com.palantir.another; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import javax.annotation.processing.Generated; + +/** This service has no endpoints. */ +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +@Path("/") +@Generated("com.palantir.conjure.java.services.JerseyServiceGenerator") +public interface TestEmptyService {} diff --git a/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey.prefix b/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey.prefix new file mode 100644 index 000000000..3b88b97ee --- /dev/null +++ b/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey.prefix @@ -0,0 +1,14 @@ +package test.prefix.com.palantir.another; + +import javax.annotation.processing.Generated; +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +/** This service has no endpoints. */ +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +@Path("/") +@Generated("com.palantir.conjure.java.services.JerseyServiceGenerator") +public interface TestEmptyService {} diff --git a/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey_require_not_null b/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey_require_not_null new file mode 100644 index 000000000..0c862fa29 --- /dev/null +++ b/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.jersey_require_not_null @@ -0,0 +1,14 @@ +package com.palantir.another; + +import javax.annotation.processing.Generated; +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +/** This service has no endpoints. */ +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +@Path("/") +@Generated("com.palantir.conjure.java.services.JerseyServiceGenerator") +public interface TestEmptyService {} diff --git a/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.undertow b/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.undertow new file mode 100644 index 000000000..a881ef674 --- /dev/null +++ b/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.undertow @@ -0,0 +1,7 @@ +package com.palantir.another; + +import javax.annotation.processing.Generated; + +/** This service has no endpoints. */ +@Generated("com.palantir.conjure.java.services.UndertowServiceInterfaceGenerator") +public interface TestEmptyService {} diff --git a/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.undertow.prefix b/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.undertow.prefix new file mode 100644 index 000000000..f237f653b --- /dev/null +++ b/conjure-java-core/src/test/resources/test/api/TestEmptyService.java.undertow.prefix @@ -0,0 +1,7 @@ +package test.prefix.com.palantir.another; + +import javax.annotation.processing.Generated; + +/** This service has no endpoints. */ +@Generated("com.palantir.conjure.java.services.UndertowServiceInterfaceGenerator") +public interface TestEmptyService {} diff --git a/conjure-java-core/src/test/resources/test/api/TestEmptyServiceAsync.java.dialogue b/conjure-java-core/src/test/resources/test/api/TestEmptyServiceAsync.java.dialogue new file mode 100644 index 000000000..3924a3a26 --- /dev/null +++ b/conjure-java-core/src/test/resources/test/api/TestEmptyServiceAsync.java.dialogue @@ -0,0 +1,53 @@ +package com.palantir.another; + +import com.palantir.dialogue.Channel; +import com.palantir.dialogue.ConjureRuntime; +import com.palantir.dialogue.DialogueService; +import com.palantir.dialogue.DialogueServiceFactory; +import com.palantir.dialogue.Endpoint; +import com.palantir.dialogue.EndpointChannel; +import com.palantir.dialogue.EndpointChannelFactory; +import com.palantir.dialogue.PlainSerDe; +import java.lang.Override; +import java.lang.String; +import javax.annotation.processing.Generated; + +/** This service has no endpoints. */ +@Generated("com.palantir.conjure.java.services.dialogue.DialogueInterfaceGenerator") +@DialogueService(TestEmptyServiceAsync.Factory.class) +public interface TestEmptyServiceAsync { + /** Creates an asynchronous/non-blocking client for a TestEmptyService service. */ + static TestEmptyServiceAsync of(EndpointChannelFactory _endpointChannelFactory, ConjureRuntime _runtime) { + return new TestEmptyServiceAsync() { + private final PlainSerDe _plainSerDe = _runtime.plainSerDe(); + + @Override + public String toString() { + return "TestEmptyServiceAsync{_endpointChannelFactory=" + _endpointChannelFactory + ", runtime=" + + _runtime + '}'; + } + }; + } + + /** Creates an asynchronous/non-blocking client for a TestEmptyService service. */ + static TestEmptyServiceAsync of(Channel _channel, ConjureRuntime _runtime) { + if (_channel instanceof EndpointChannelFactory) { + return of((EndpointChannelFactory) _channel, _runtime); + } + return of( + new EndpointChannelFactory() { + @Override + public EndpointChannel endpoint(Endpoint endpoint) { + return _runtime.clients().bind(_channel, endpoint); + } + }, + _runtime); + } + + final class Factory implements DialogueServiceFactory { + @Override + public TestEmptyServiceAsync create(EndpointChannelFactory endpointChannelFactory, ConjureRuntime runtime) { + return TestEmptyServiceAsync.of(endpointChannelFactory, runtime); + } + } +} diff --git a/conjure-java-core/src/test/resources/test/api/TestEmptyServiceAsync.java.dialogue.prefix b/conjure-java-core/src/test/resources/test/api/TestEmptyServiceAsync.java.dialogue.prefix new file mode 100644 index 000000000..e1a822ed9 --- /dev/null +++ b/conjure-java-core/src/test/resources/test/api/TestEmptyServiceAsync.java.dialogue.prefix @@ -0,0 +1,53 @@ +package test.prefix.com.palantir.another; + +import com.palantir.dialogue.Channel; +import com.palantir.dialogue.ConjureRuntime; +import com.palantir.dialogue.DialogueService; +import com.palantir.dialogue.DialogueServiceFactory; +import com.palantir.dialogue.Endpoint; +import com.palantir.dialogue.EndpointChannel; +import com.palantir.dialogue.EndpointChannelFactory; +import com.palantir.dialogue.PlainSerDe; +import java.lang.Override; +import java.lang.String; +import javax.annotation.processing.Generated; + +/** This service has no endpoints. */ +@Generated("com.palantir.conjure.java.services.dialogue.DialogueInterfaceGenerator") +@DialogueService(TestEmptyServiceAsync.Factory.class) +public interface TestEmptyServiceAsync { + /** Creates an asynchronous/non-blocking client for a TestEmptyService service. */ + static TestEmptyServiceAsync of(EndpointChannelFactory _endpointChannelFactory, ConjureRuntime _runtime) { + return new TestEmptyServiceAsync() { + private final PlainSerDe _plainSerDe = _runtime.plainSerDe(); + + @Override + public String toString() { + return "TestEmptyServiceAsync{_endpointChannelFactory=" + _endpointChannelFactory + ", runtime=" + + _runtime + '}'; + } + }; + } + + /** Creates an asynchronous/non-blocking client for a TestEmptyService service. */ + static TestEmptyServiceAsync of(Channel _channel, ConjureRuntime _runtime) { + if (_channel instanceof EndpointChannelFactory) { + return of((EndpointChannelFactory) _channel, _runtime); + } + return of( + new EndpointChannelFactory() { + @Override + public EndpointChannel endpoint(Endpoint endpoint) { + return _runtime.clients().bind(_channel, endpoint); + } + }, + _runtime); + } + + final class Factory implements DialogueServiceFactory { + @Override + public TestEmptyServiceAsync create(EndpointChannelFactory endpointChannelFactory, ConjureRuntime runtime) { + return TestEmptyServiceAsync.of(endpointChannelFactory, runtime); + } + } +} diff --git a/conjure-java-core/src/test/resources/test/api/TestEmptyServiceBlocking.java.dialogue b/conjure-java-core/src/test/resources/test/api/TestEmptyServiceBlocking.java.dialogue new file mode 100644 index 000000000..5f02af207 --- /dev/null +++ b/conjure-java-core/src/test/resources/test/api/TestEmptyServiceBlocking.java.dialogue @@ -0,0 +1,53 @@ +package com.palantir.another; + +import com.palantir.dialogue.Channel; +import com.palantir.dialogue.ConjureRuntime; +import com.palantir.dialogue.DialogueService; +import com.palantir.dialogue.DialogueServiceFactory; +import com.palantir.dialogue.Endpoint; +import com.palantir.dialogue.EndpointChannel; +import com.palantir.dialogue.EndpointChannelFactory; +import com.palantir.dialogue.PlainSerDe; +import java.lang.Override; +import java.lang.String; +import javax.annotation.processing.Generated; + +/** This service has no endpoints. */ +@Generated("com.palantir.conjure.java.services.dialogue.DialogueInterfaceGenerator") +@DialogueService(TestEmptyServiceBlocking.Factory.class) +public interface TestEmptyServiceBlocking { + /** Creates a synchronous/blocking client for a TestEmptyService service. */ + static TestEmptyServiceBlocking of(EndpointChannelFactory _endpointChannelFactory, ConjureRuntime _runtime) { + return new TestEmptyServiceBlocking() { + private final PlainSerDe _plainSerDe = _runtime.plainSerDe(); + + @Override + public String toString() { + return "TestEmptyServiceBlocking{_endpointChannelFactory=" + _endpointChannelFactory + ", runtime=" + + _runtime + '}'; + } + }; + } + + /** Creates an asynchronous/non-blocking client for a TestEmptyService service. */ + static TestEmptyServiceBlocking of(Channel _channel, ConjureRuntime _runtime) { + if (_channel instanceof EndpointChannelFactory) { + return of((EndpointChannelFactory) _channel, _runtime); + } + return of( + new EndpointChannelFactory() { + @Override + public EndpointChannel endpoint(Endpoint endpoint) { + return _runtime.clients().bind(_channel, endpoint); + } + }, + _runtime); + } + + final class Factory implements DialogueServiceFactory { + @Override + public TestEmptyServiceBlocking create(EndpointChannelFactory endpointChannelFactory, ConjureRuntime runtime) { + return TestEmptyServiceBlocking.of(endpointChannelFactory, runtime); + } + } +} diff --git a/conjure-java-core/src/test/resources/test/api/TestEmptyServiceBlocking.java.dialogue.prefix b/conjure-java-core/src/test/resources/test/api/TestEmptyServiceBlocking.java.dialogue.prefix new file mode 100644 index 000000000..f29acbc89 --- /dev/null +++ b/conjure-java-core/src/test/resources/test/api/TestEmptyServiceBlocking.java.dialogue.prefix @@ -0,0 +1,53 @@ +package test.prefix.com.palantir.another; + +import com.palantir.dialogue.Channel; +import com.palantir.dialogue.ConjureRuntime; +import com.palantir.dialogue.DialogueService; +import com.palantir.dialogue.DialogueServiceFactory; +import com.palantir.dialogue.Endpoint; +import com.palantir.dialogue.EndpointChannel; +import com.palantir.dialogue.EndpointChannelFactory; +import com.palantir.dialogue.PlainSerDe; +import java.lang.Override; +import java.lang.String; +import javax.annotation.processing.Generated; + +/** This service has no endpoints. */ +@Generated("com.palantir.conjure.java.services.dialogue.DialogueInterfaceGenerator") +@DialogueService(TestEmptyServiceBlocking.Factory.class) +public interface TestEmptyServiceBlocking { + /** Creates a synchronous/blocking client for a TestEmptyService service. */ + static TestEmptyServiceBlocking of(EndpointChannelFactory _endpointChannelFactory, ConjureRuntime _runtime) { + return new TestEmptyServiceBlocking() { + private final PlainSerDe _plainSerDe = _runtime.plainSerDe(); + + @Override + public String toString() { + return "TestEmptyServiceBlocking{_endpointChannelFactory=" + _endpointChannelFactory + ", runtime=" + + _runtime + '}'; + } + }; + } + + /** Creates an asynchronous/non-blocking client for a TestEmptyService service. */ + static TestEmptyServiceBlocking of(Channel _channel, ConjureRuntime _runtime) { + if (_channel instanceof EndpointChannelFactory) { + return of((EndpointChannelFactory) _channel, _runtime); + } + return of( + new EndpointChannelFactory() { + @Override + public EndpointChannel endpoint(Endpoint endpoint) { + return _runtime.clients().bind(_channel, endpoint); + } + }, + _runtime); + } + + final class Factory implements DialogueServiceFactory { + @Override + public TestEmptyServiceBlocking create(EndpointChannelFactory endpointChannelFactory, ConjureRuntime runtime) { + return TestEmptyServiceBlocking.of(endpointChannelFactory, runtime); + } + } +} diff --git a/conjure-java-core/src/test/resources/test/api/TestEmptyServiceEndpoints.java.undertow b/conjure-java-core/src/test/resources/test/api/TestEmptyServiceEndpoints.java.undertow new file mode 100644 index 000000000..137de96d4 --- /dev/null +++ b/conjure-java-core/src/test/resources/test/api/TestEmptyServiceEndpoints.java.undertow @@ -0,0 +1,26 @@ +package com.palantir.another; + +import com.google.common.collect.ImmutableList; +import com.palantir.conjure.java.undertow.lib.Endpoint; +import com.palantir.conjure.java.undertow.lib.UndertowRuntime; +import com.palantir.conjure.java.undertow.lib.UndertowService; +import java.util.List; +import javax.annotation.processing.Generated; + +@Generated("com.palantir.conjure.java.services.UndertowServiceHandlerGenerator") +public final class TestEmptyServiceEndpoints implements UndertowService { + private final TestEmptyService delegate; + + private TestEmptyServiceEndpoints(TestEmptyService delegate) { + this.delegate = delegate; + } + + public static UndertowService of(TestEmptyService delegate) { + return new TestEmptyServiceEndpoints(delegate); + } + + @Override + public List endpoints(UndertowRuntime runtime) { + return ImmutableList.of(); + } +} diff --git a/conjure-java-core/src/test/resources/test/api/TestEmptyServiceEndpoints.java.undertow.prefix b/conjure-java-core/src/test/resources/test/api/TestEmptyServiceEndpoints.java.undertow.prefix new file mode 100644 index 000000000..42501c2df --- /dev/null +++ b/conjure-java-core/src/test/resources/test/api/TestEmptyServiceEndpoints.java.undertow.prefix @@ -0,0 +1,26 @@ +package test.prefix.com.palantir.another; + +import com.google.common.collect.ImmutableList; +import com.palantir.conjure.java.undertow.lib.Endpoint; +import com.palantir.conjure.java.undertow.lib.UndertowRuntime; +import com.palantir.conjure.java.undertow.lib.UndertowService; +import java.util.List; +import javax.annotation.processing.Generated; + +@Generated("com.palantir.conjure.java.services.UndertowServiceHandlerGenerator") +public final class TestEmptyServiceEndpoints implements UndertowService { + private final TestEmptyService delegate; + + private TestEmptyServiceEndpoints(TestEmptyService delegate) { + this.delegate = delegate; + } + + public static UndertowService of(TestEmptyService delegate) { + return new TestEmptyServiceEndpoints(delegate); + } + + @Override + public List endpoints(UndertowRuntime runtime) { + return ImmutableList.of(); + } +}