Skip to content

Commit

Permalink
Propagate schemas in EndpointManifest
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper committed Nov 14, 2024
1 parent 2fb2b6a commit ccfe207
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
49 changes: 36 additions & 13 deletions sdk-core/src/main/java/dev/restate/sdk/core/EndpointManifest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import static dev.restate.sdk.core.ServiceProtocol.*;

import dev.restate.sdk.common.HandlerType;
import dev.restate.sdk.common.RichSerde;
import dev.restate.sdk.common.ServiceType;
import dev.restate.sdk.common.syscalls.HandlerDefinition;
import dev.restate.sdk.common.syscalls.HandlerSpecification;
import dev.restate.sdk.common.syscalls.ServiceDefinition;
import dev.restate.sdk.core.manifest.*;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -68,24 +70,45 @@ private static Service.Ty convertServiceType(ServiceType serviceType) {

private static Handler convertHandler(HandlerDefinition<?, ?, ?> handler) {
HandlerSpecification<?, ?> spec = handler.getSpec();
return new Handler()
.withName(spec.getName())
.withTy(convertHandlerType(spec.getHandlerType()))
.withInput(convertHandlerInput(spec))
.withOutput(convertHandlerOutput(spec));
}

private static Input convertHandlerInput(HandlerSpecification<?, ?> spec) {
String acceptContentType =
spec.getAcceptContentType() != null
? spec.getAcceptContentType()
: spec.getRequestSerde().contentType();

return new Handler()
.withName(spec.getName())
.withTy(convertHandlerType(spec.getHandlerType()))
.withInput(
acceptContentType == null
? EMPTY_INPUT
: new Input().withRequired(true).withContentType(acceptContentType))
.withOutput(
spec.getResponseSerde().contentType() == null
? EMPTY_OUTPUT
: new Output()
.withContentType(spec.getResponseSerde().contentType())
.withSetContentTypeIfEmpty(false));
Input input =
acceptContentType == null
? EMPTY_INPUT
: new Input().withRequired(true).withContentType(acceptContentType);

if (spec.getRequestSerde() instanceof RichSerde) {
input.setJsonSchema(
Objects.requireNonNull(((RichSerde<?>) spec.getRequestSerde()).jsonSchema()));
}
return input;
}

private static Output convertHandlerOutput(HandlerSpecification<?, ?> spec) {
Output output =
spec.getResponseSerde().contentType() == null
? EMPTY_OUTPUT
: new Output()
.withContentType(spec.getResponseSerde().contentType())
.withSetContentTypeIfEmpty(false);

if (spec.getResponseSerde() instanceof RichSerde) {
output.setJsonSchema(
Objects.requireNonNull(((RichSerde<?>) spec.getResponseSerde()).jsonSchema()));
}

return output;
}

private static Handler.Ty convertHandlerType(HandlerType handlerType) {
Expand Down
5 changes: 5 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ dependencyResolutionManagement {
.withoutVersion()
library("jackson-jdk8", "com.fasterxml.jackson.datatype", "jackson-datatype-jdk8")
.withoutVersion()
library(
"jackson-parameter-names",
"com.fasterxml.jackson.module",
"jackson-module-parameter-names")
.withoutVersion()
}
create("kotlinLibs") {
library("kotlinx-coroutines", "org.jetbrains.kotlinx", "kotlinx-coroutines-core")
Expand Down

0 comments on commit ccfe207

Please sign in to comment.