From a8c8ecada1724429bc8b31d3a950915fa4a13a49 Mon Sep 17 00:00:00 2001 From: Brian Laub Date: Tue, 1 Jul 2025 13:39:42 -0400 Subject: [PATCH 1/2] wip --- .../product/DialogueErrorEndpoints.java | 30 +++++++++++ .../com/palantir/product/ErrorService.java | 3 ++ .../palantir/product/ErrorServiceAsync.java | 26 ++++++++++ .../product/ErrorServiceBlocking.java | 25 +++++++++ .../product/ErrorServiceEndpoints.java | 51 +++++++++++++++++++ .../product/ErrorServiceEndpoints.java | 51 +++++++++++++++++++ .../product/UndertowErrorService.java | 3 ++ .../palantir/conjure/java/ErrorResource.java | 8 +++ .../conjure/java/UndertowServiceEteTest.java | 10 ++++ .../resources/example-endpoint-errors.yml | 5 ++ 10 files changed, 212 insertions(+) diff --git a/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/DialogueErrorEndpoints.java b/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/DialogueErrorEndpoints.java index 501f547c9..b28533a79 100644 --- a/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/DialogueErrorEndpoints.java +++ b/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/DialogueErrorEndpoints.java @@ -12,6 +12,36 @@ @Generated("com.palantir.conjure.java.services.dialogue.DialogueEndpointsGenerator") enum DialogueErrorEndpoints implements Endpoint { + testNonEndpointAssociatedError { + private final PathTemplate pathTemplate = + PathTemplate.builder().fixed("errors").fixed("nonEndpointError").build(); + + @Override + public void renderPath(ListMultimap params, UrlBuilder url) { + pathTemplate.fill(params, url); + } + + @Override + public HttpMethod httpMethod() { + return HttpMethod.POST; + } + + @Override + public String serviceName() { + return "ErrorService"; + } + + @Override + public String endpointName() { + return "testNonEndpointAssociatedError"; + } + + @Override + public String version() { + return VERSION; + } + }, + testBasicError { private final PathTemplate pathTemplate = PathTemplate.builder().fixed("errors").fixed("basic").build(); diff --git a/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorService.java b/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorService.java index 98ce72748..ca5892c4f 100644 --- a/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorService.java +++ b/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorService.java @@ -7,6 +7,9 @@ @Generated("com.palantir.conjure.java.services.UndertowServiceInterfaceGenerator") public interface ErrorService { + /** @apiNote {@code POST /errors/nonEndpointError} */ + String testNonEndpointAssociatedError(AuthHeader authHeader, boolean shouldThrowError); + /** * @apiNote {@code POST /errors/basic} * @throws TestServerErrors.InvalidArgument diff --git a/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorServiceAsync.java b/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorServiceAsync.java index 54ba9f710..0be94b251 100644 --- a/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorServiceAsync.java +++ b/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorServiceAsync.java @@ -36,6 +36,10 @@ @Generated("com.palantir.conjure.java.services.dialogue.DialogueInterfaceGenerator") @DialogueService(ErrorServiceAsync.Factory.class) public interface ErrorServiceAsync { + /** @apiNote {@code POST /errors/nonEndpointError} */ + @ClientEndpoint(method = "POST", path = "/errors/nonEndpointError") + ListenableFuture testNonEndpointAssociatedError(AuthHeader authHeader, boolean shouldThrowError); + /** @apiNote {@code POST /errors/basic} */ @ClientEndpoint(method = "POST", path = "/errors/basic") @CheckReturnValue @@ -73,6 +77,15 @@ static ErrorServiceAsync of(EndpointChannelFactory _endpointChannelFactory, Conj return new ErrorServiceAsync() { private final PlainSerDe _plainSerDe = _runtime.plainSerDe(); + private final Serializer testNonEndpointAssociatedErrorSerializer = + _runtime.bodySerDe().serializer(new TypeMarker() {}); + + private final EndpointChannel testNonEndpointAssociatedErrorChannel = + _endpointChannelFactory.endpoint(DialogueErrorEndpoints.testNonEndpointAssociatedError); + + private final Deserializer testNonEndpointAssociatedErrorDeserializer = + _runtime.bodySerDe().deserializer(new TypeMarker() {}); + private final Serializer testBasicErrorSerializer = _runtime.bodySerDe().serializer(new TypeMarker() {}); @@ -180,6 +193,19 @@ static ErrorServiceAsync of(EndpointChannelFactory _endpointChannelFactory, Conj new TypeMarker() {}) .build()); + @Override + public ListenableFuture testNonEndpointAssociatedError( + AuthHeader authHeader, boolean shouldThrowError) { + Request.Builder _request = Request.builder(); + _request.putHeaderParams("Authorization", authHeader.toString()); + _request.body(testNonEndpointAssociatedErrorSerializer.serialize(shouldThrowError)); + return _runtime.clients() + .call( + testNonEndpointAssociatedErrorChannel, + _request.build(), + testNonEndpointAssociatedErrorDeserializer); + } + @Override public ListenableFuture testBasicError( AuthHeader authHeader, boolean shouldThrowError) { diff --git a/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorServiceBlocking.java b/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorServiceBlocking.java index 3ca2dd684..2896bd527 100644 --- a/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorServiceBlocking.java +++ b/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorServiceBlocking.java @@ -35,6 +35,10 @@ @Generated("com.palantir.conjure.java.services.dialogue.DialogueInterfaceGenerator") @DialogueService(ErrorServiceBlocking.Factory.class) public interface ErrorServiceBlocking { + /** @apiNote {@code POST /errors/nonEndpointError} */ + @ClientEndpoint(method = "POST", path = "/errors/nonEndpointError") + String testNonEndpointAssociatedError(AuthHeader authHeader, boolean shouldThrowError); + /** @apiNote {@code POST /errors/basic} */ @ClientEndpoint(method = "POST", path = "/errors/basic") @CheckReturnValue @@ -71,6 +75,15 @@ static ErrorServiceBlocking of(EndpointChannelFactory _endpointChannelFactory, C return new ErrorServiceBlocking() { private final PlainSerDe _plainSerDe = _runtime.plainSerDe(); + private final Serializer testNonEndpointAssociatedErrorSerializer = + _runtime.bodySerDe().serializer(new TypeMarker() {}); + + private final EndpointChannel testNonEndpointAssociatedErrorChannel = + _endpointChannelFactory.endpoint(DialogueErrorEndpoints.testNonEndpointAssociatedError); + + private final Deserializer testNonEndpointAssociatedErrorDeserializer = + _runtime.bodySerDe().deserializer(new TypeMarker() {}); + private final Serializer testBasicErrorSerializer = _runtime.bodySerDe().serializer(new TypeMarker() {}); @@ -178,6 +191,18 @@ static ErrorServiceBlocking of(EndpointChannelFactory _endpointChannelFactory, C new TypeMarker() {}) .build()); + @Override + public String testNonEndpointAssociatedError(AuthHeader authHeader, boolean shouldThrowError) { + Request.Builder _request = Request.builder(); + _request.putHeaderParams("Authorization", authHeader.toString()); + _request.body(testNonEndpointAssociatedErrorSerializer.serialize(shouldThrowError)); + return _runtime.clients() + .callBlocking( + testNonEndpointAssociatedErrorChannel, + _request.build(), + testNonEndpointAssociatedErrorDeserializer); + } + @Override public TestBasicErrorResponse testBasicError(AuthHeader authHeader, boolean shouldThrowError) { Request.Builder _request = Request.builder(); diff --git a/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorServiceEndpoints.java b/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorServiceEndpoints.java index 709cf8f69..2dc8a416a 100644 --- a/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorServiceEndpoints.java +++ b/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/ErrorServiceEndpoints.java @@ -34,6 +34,7 @@ public static UndertowService of(ErrorService delegate) { @Override public List endpoints(UndertowRuntime runtime) { return ImmutableList.of( + new TestNonEndpointAssociatedErrorEndpoint(runtime, delegate), new TestBasicErrorEndpoint(runtime, delegate), new TestImportedErrorEndpoint(runtime, delegate), new TestMultipleErrorsAndPackagesEndpoint(runtime, delegate), @@ -42,6 +43,56 @@ public List endpoints(UndertowRuntime runtime) { new TestOptionalBinaryEndpoint(runtime, delegate)); } + private static final class TestNonEndpointAssociatedErrorEndpoint implements HttpHandler, Endpoint { + private final UndertowRuntime runtime; + + private final ErrorService delegate; + + private final Deserializer deserializer; + + private final Serializer serializer; + + TestNonEndpointAssociatedErrorEndpoint(UndertowRuntime runtime, ErrorService delegate) { + this.runtime = runtime; + this.delegate = delegate; + this.deserializer = runtime.bodySerDe().deserializer(new TypeMarker() {}, this); + this.serializer = runtime.bodySerDe().serializer(new TypeMarker() {}, this); + } + + @Override + public void handleRequest(HttpServerExchange exchange) throws IOException { + AuthHeader authHeader = runtime.auth().header(exchange); + Boolean shouldThrowError = deserializer.deserialize(exchange); + String result = delegate.testNonEndpointAssociatedError(authHeader, shouldThrowError); + serializer.serialize(result, exchange); + } + + @Override + public HttpString method() { + return Methods.POST; + } + + @Override + public String template() { + return "/errors/nonEndpointError"; + } + + @Override + public String serviceName() { + return "ErrorService"; + } + + @Override + public String name() { + return "testNonEndpointAssociatedError"; + } + + @Override + public HttpHandler handler() { + return this; + } + } + private static final class TestBasicErrorEndpoint implements HttpHandler, Endpoint { private final UndertowRuntime runtime; diff --git a/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/ErrorServiceEndpoints.java b/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/ErrorServiceEndpoints.java index 51863aa31..d864e7825 100644 --- a/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/ErrorServiceEndpoints.java +++ b/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/ErrorServiceEndpoints.java @@ -34,6 +34,7 @@ public static UndertowService of(UndertowErrorService delegate) { @Override public List endpoints(UndertowRuntime runtime) { return ImmutableList.of( + new TestNonEndpointAssociatedErrorEndpoint(runtime, delegate), new TestBasicErrorEndpoint(runtime, delegate), new TestImportedErrorEndpoint(runtime, delegate), new TestMultipleErrorsAndPackagesEndpoint(runtime, delegate), @@ -42,6 +43,56 @@ public List endpoints(UndertowRuntime runtime) { new TestOptionalBinaryEndpoint(runtime, delegate)); } + private static final class TestNonEndpointAssociatedErrorEndpoint implements HttpHandler, Endpoint { + private final UndertowRuntime runtime; + + private final UndertowErrorService delegate; + + private final Deserializer deserializer; + + private final Serializer serializer; + + TestNonEndpointAssociatedErrorEndpoint(UndertowRuntime runtime, UndertowErrorService delegate) { + this.runtime = runtime; + this.delegate = delegate; + this.deserializer = runtime.bodySerDe().deserializer(new TypeMarker() {}, this); + this.serializer = runtime.bodySerDe().serializer(new TypeMarker() {}, this); + } + + @Override + public void handleRequest(HttpServerExchange exchange) throws IOException { + AuthHeader authHeader = runtime.auth().header(exchange); + Boolean shouldThrowError = deserializer.deserialize(exchange); + String result = delegate.testNonEndpointAssociatedError(authHeader, shouldThrowError); + serializer.serialize(result, exchange); + } + + @Override + public HttpString method() { + return Methods.POST; + } + + @Override + public String template() { + return "/errors/nonEndpointError"; + } + + @Override + public String serviceName() { + return "ErrorService"; + } + + @Override + public String name() { + return "testNonEndpointAssociatedError"; + } + + @Override + public HttpHandler handler() { + return this; + } + } + private static final class TestBasicErrorEndpoint implements HttpHandler, Endpoint { private final UndertowRuntime runtime; diff --git a/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/UndertowErrorService.java b/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/UndertowErrorService.java index 827466ab0..90f9da699 100644 --- a/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/UndertowErrorService.java +++ b/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/UndertowErrorService.java @@ -7,6 +7,9 @@ @Generated("com.palantir.conjure.java.services.UndertowServiceInterfaceGenerator") public interface UndertowErrorService { + /** @apiNote {@code POST /errors/nonEndpointError} */ + String testNonEndpointAssociatedError(AuthHeader authHeader, boolean shouldThrowError); + /** * @apiNote {@code POST /errors/basic} * @throws TestServerErrors.InvalidArgument diff --git a/conjure-java-core/src/test/java/dialogueendpointresulttypes/com/palantir/conjure/java/ErrorResource.java b/conjure-java-core/src/test/java/dialogueendpointresulttypes/com/palantir/conjure/java/ErrorResource.java index 632f3d9be..4d979a202 100644 --- a/conjure-java-core/src/test/java/dialogueendpointresulttypes/com/palantir/conjure/java/ErrorResource.java +++ b/conjure-java-core/src/test/java/dialogueendpointresulttypes/com/palantir/conjure/java/ErrorResource.java @@ -39,6 +39,14 @@ interface ErrorResource { final class Impl implements ErrorService { public static final String SUCCESS = "success!"; + @Override + public String testNonEndpointAssociatedError(AuthHeader authHeader, boolean shouldThrowError) { + if (shouldThrowError) { + throw TestServerErrors.invalidArgument("field", "value"); + } + return SUCCESS; + } + @Override public String testBasicError(AuthHeader _authHeader, boolean shouldThrowError) throws InvalidArgument { if (shouldThrowError) { diff --git a/conjure-java-core/src/test/java/dialogueendpointresulttypes/com/palantir/conjure/java/UndertowServiceEteTest.java b/conjure-java-core/src/test/java/dialogueendpointresulttypes/com/palantir/conjure/java/UndertowServiceEteTest.java index 52db3987a..d5477ad5f 100644 --- a/conjure-java-core/src/test/java/dialogueendpointresulttypes/com/palantir/conjure/java/UndertowServiceEteTest.java +++ b/conjure-java-core/src/test/java/dialogueendpointresulttypes/com/palantir/conjure/java/UndertowServiceEteTest.java @@ -98,6 +98,16 @@ public void error_client_returns_basic_result() { .isEqualTo(ErrorResource.Impl.SUCCESS)); } + @Test + public void test_foo() { + try { + String result = errorServiceClient.testNonEndpointAssociatedError(AUTH_HEADER, true); + assertThat(result).isEqualTo("success!"); + } catch (Throwable t) { + assertThat(t).isInstanceOf(TestBasicErrorResponse.InvalidArgument.class); + } + } + @Test public void error_client_returns_basic_error() { TestBasicErrorResponse result = errorServiceClient.testBasicError(AUTH_HEADER, true); diff --git a/conjure-java-core/src/test/resources/example-endpoint-errors.yml b/conjure-java-core/src/test/resources/example-endpoint-errors.yml index c02a08807..a6cd96ae5 100644 --- a/conjure-java-core/src/test/resources/example-endpoint-errors.yml +++ b/conjure-java-core/src/test/resources/example-endpoint-errors.yml @@ -40,6 +40,11 @@ services: default-auth: header base-path: /errors endpoints: + testNonEndpointAssociatedError: + http: POST /nonEndpointError + args: + shouldThrowError: boolean + returns: string testBasicError: http: POST /basic args: From 6ddde088674e1131f146758f2389767ec9476317 Mon Sep 17 00:00:00 2001 From: Brandon Marc-Aurele Date: Fri, 4 Jul 2025 15:12:17 -0400 Subject: [PATCH 2/2] add an unassociated type, also use it for the hack test --- .../com/palantir/product/TestErrors.java | 42 ++++++++++++++++++ .../com/palantir/product/TestErrors.java | 43 +++++++++++++++++++ .../palantir/conjure/java/ErrorResource.java | 4 +- .../resources/example-endpoint-errors.yml | 5 +++ 4 files changed, 93 insertions(+), 1 deletion(-) diff --git a/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/TestErrors.java b/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/TestErrors.java index da9da0dfd..4f1998947 100644 --- a/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/TestErrors.java +++ b/conjure-java-core/src/integrationInput/java/dialogueendpointresulttypes/com/palantir/product/TestErrors.java @@ -3,10 +3,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.palantir.conjure.java.api.errors.ErrorType; import com.palantir.conjure.java.api.errors.RemoteException; +import com.palantir.conjure.java.api.errors.ServiceException; import com.palantir.logsafe.Preconditions; import com.palantir.logsafe.Safe; +import com.palantir.logsafe.SafeArg; import com.palantir.logsafe.Unsafe; import java.util.Map; +import javax.annotation.Nullable; import javax.annotation.processing.Generated; @Generated("com.palantir.conjure.java.types.ErrorGenerator") @@ -19,8 +22,36 @@ public final class TestErrors { public static final ErrorType NOT_FOUND = ErrorType.create(ErrorType.Code.NOT_FOUND, "Test:NotFound"); + public static final ErrorType UNASSOCIATED_COMPLICATED_PARAMETERS = + ErrorType.create(ErrorType.Code.INTERNAL, "Test:UnassociatedComplicatedParameters"); + private TestErrors() {} + public static ServiceException unassociatedComplicatedParameters( + @Safe Map complicatedObjectMap) { + return new ServiceException( + UNASSOCIATED_COMPLICATED_PARAMETERS, SafeArg.of("complicatedObjectMap", complicatedObjectMap)); + } + + public static ServiceException unassociatedComplicatedParameters( + @Nullable Throwable cause, @Safe Map complicatedObjectMap) { + return new ServiceException( + UNASSOCIATED_COMPLICATED_PARAMETERS, cause, SafeArg.of("complicatedObjectMap", complicatedObjectMap)); + } + + /** + * Throws a {@link ServiceException} of type UnassociatedComplicatedParameters when {@code shouldThrow} is true. + * + * @param shouldThrow Cause the method to throw when true + * @param complicatedObjectMap + */ + public static void throwIfUnassociatedComplicatedParameters( + boolean shouldThrow, @Safe Map complicatedObjectMap) { + if (shouldThrow) { + throw unassociatedComplicatedParameters(complicatedObjectMap); + } + } + /** Returns true if the {@link RemoteException} is named Test:ComplicatedParameters */ public static boolean isComplicatedParameters(RemoteException remoteException) { Preconditions.checkNotNull(remoteException, "remote exception must not be null"); @@ -39,6 +70,14 @@ public static boolean isNotFound(RemoteException remoteException) { return NOT_FOUND.name().equals(remoteException.getError().errorName()); } + /** Returns true if the {@link RemoteException} is named Test:UnassociatedComplicatedParameters */ + public static boolean isUnassociatedComplicatedParameters(RemoteException remoteException) { + Preconditions.checkNotNull(remoteException, "remote exception must not be null"); + return UNASSOCIATED_COMPLICATED_PARAMETERS + .name() + .equals(remoteException.getError().errorName()); + } + public static record ComplicatedParametersParameters( @JsonProperty("complicatedObjectMap") @Safe Map complicatedObjectMap) {} @@ -46,4 +85,7 @@ public static record InvalidArgumentParameters( @JsonProperty("field") @Safe String field, @JsonProperty("value") @Unsafe String value) {} public static record NotFoundParameters(@JsonProperty("resource") @Safe String resource) {} + + public static record UnassociatedComplicatedParametersParameters( + @JsonProperty("complicatedObjectMap") @Safe Map complicatedObjectMap) {} } diff --git a/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/TestErrors.java b/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/TestErrors.java index 9f5db9eae..1ceda8d10 100644 --- a/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/TestErrors.java +++ b/conjure-java-core/src/integrationInput/java/undertow/com/palantir/product/TestErrors.java @@ -2,8 +2,14 @@ import com.palantir.conjure.java.api.errors.ErrorType; import com.palantir.conjure.java.api.errors.RemoteException; +import com.palantir.conjure.java.api.errors.ServiceException; import com.palantir.logsafe.Preconditions; +import com.palantir.logsafe.Safe; +import com.palantir.logsafe.SafeArg; +import java.util.Map; +import javax.annotation.Nullable; import javax.annotation.processing.Generated; +import org.jetbrains.annotations.Contract; @Generated("com.palantir.conjure.java.types.ErrorGenerator") public final class TestErrors { @@ -15,8 +21,37 @@ public final class TestErrors { public static final ErrorType NOT_FOUND = ErrorType.create(ErrorType.Code.NOT_FOUND, "Test:NotFound"); + public static final ErrorType UNASSOCIATED_COMPLICATED_PARAMETERS = + ErrorType.create(ErrorType.Code.INTERNAL, "Test:UnassociatedComplicatedParameters"); + private TestErrors() {} + public static ServiceException unassociatedComplicatedParameters( + @Safe Map complicatedObjectMap) { + return new ServiceException( + UNASSOCIATED_COMPLICATED_PARAMETERS, SafeArg.of("complicatedObjectMap", complicatedObjectMap)); + } + + public static ServiceException unassociatedComplicatedParameters( + @Nullable Throwable cause, @Safe Map complicatedObjectMap) { + return new ServiceException( + UNASSOCIATED_COMPLICATED_PARAMETERS, cause, SafeArg.of("complicatedObjectMap", complicatedObjectMap)); + } + + /** + * Throws a {@link ServiceException} of type UnassociatedComplicatedParameters when {@code shouldThrow} is true. + * + * @param shouldThrow Cause the method to throw when true + * @param complicatedObjectMap + */ + @Contract("true, _ -> fail") + public static void throwIfUnassociatedComplicatedParameters( + boolean shouldThrow, @Safe Map complicatedObjectMap) { + if (shouldThrow) { + throw unassociatedComplicatedParameters(complicatedObjectMap); + } + } + /** Returns true if the {@link RemoteException} is named Test:ComplicatedParameters */ public static boolean isComplicatedParameters(RemoteException remoteException) { Preconditions.checkNotNull(remoteException, "remote exception must not be null"); @@ -34,4 +69,12 @@ public static boolean isNotFound(RemoteException remoteException) { Preconditions.checkNotNull(remoteException, "remote exception must not be null"); return NOT_FOUND.name().equals(remoteException.getError().errorName()); } + + /** Returns true if the {@link RemoteException} is named Test:UnassociatedComplicatedParameters */ + public static boolean isUnassociatedComplicatedParameters(RemoteException remoteException) { + Preconditions.checkNotNull(remoteException, "remote exception must not be null"); + return UNASSOCIATED_COMPLICATED_PARAMETERS + .name() + .equals(remoteException.getError().errorName()); + } } diff --git a/conjure-java-core/src/test/java/dialogueendpointresulttypes/com/palantir/conjure/java/ErrorResource.java b/conjure-java-core/src/test/java/dialogueendpointresulttypes/com/palantir/conjure/java/ErrorResource.java index 4d979a202..dea3489bb 100644 --- a/conjure-java-core/src/test/java/dialogueendpointresulttypes/com/palantir/conjure/java/ErrorResource.java +++ b/conjure-java-core/src/test/java/dialogueendpointresulttypes/com/palantir/conjure/java/ErrorResource.java @@ -26,6 +26,7 @@ import dialogueendpointresulttypes.com.palantir.product.ErrorService; import dialogueendpointresulttypes.com.palantir.product.OptionalBinaryResponseMode; import dialogueendpointresulttypes.com.palantir.product.StringAlias; +import dialogueendpointresulttypes.com.palantir.product.TestErrors; import dialogueendpointresulttypes.com.palantir.product.TestServerErrors; import dialogueendpointresulttypes.com.palantir.product.TestServerErrors.ComplicatedParameters; import dialogueendpointresulttypes.com.palantir.product.TestServerErrors.InvalidArgument; @@ -42,7 +43,8 @@ final class Impl implements ErrorService { @Override public String testNonEndpointAssociatedError(AuthHeader authHeader, boolean shouldThrowError) { if (shouldThrowError) { - throw TestServerErrors.invalidArgument("field", "value"); + throw TestErrors.unassociatedComplicatedParameters( + Map.of(1, ComplicatedObject.of(List.of("string"), StringAlias.of("alias")))); } return SUCCESS; } diff --git a/conjure-java-core/src/test/resources/example-endpoint-errors.yml b/conjure-java-core/src/test/resources/example-endpoint-errors.yml index a6cd96ae5..3bee45c3b 100644 --- a/conjure-java-core/src/test/resources/example-endpoint-errors.yml +++ b/conjure-java-core/src/test/resources/example-endpoint-errors.yml @@ -33,6 +33,11 @@ types: code: INTERNAL safe-args: complicatedObjectMap: map + UnassociatedComplicatedParameters: + namespace: Test + code: INTERNAL + safe-args: + complicatedObjectMap: map services: ErrorService: name: Error Service