From 277ed2cea826b0868f6b48ae65645bc73e3d3e49 Mon Sep 17 00:00:00 2001 From: charlietsai Date: Wed, 3 Jun 2020 17:20:17 +0900 Subject: [PATCH] Make server codegen more deterministic by ensuring service methods ordering #988 --- codegen/src/main/scala/akka/grpc/gen/javadsl/Service.scala | 2 +- codegen/src/main/scala/akka/grpc/gen/scaladsl/Service.scala | 2 +- .../main/twirl/templates/JavaClient/GenMethodImports.scala.txt | 2 +- codegen/src/main/twirl/templates/ScalaClient/Client.scala.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/codegen/src/main/scala/akka/grpc/gen/javadsl/Service.scala b/codegen/src/main/scala/akka/grpc/gen/javadsl/Service.scala index 2e2950217..1b6a5ce65 100644 --- a/codegen/src/main/scala/akka/grpc/gen/javadsl/Service.scala +++ b/codegen/src/main/scala/akka/grpc/gen/javadsl/Service.scala @@ -20,7 +20,7 @@ final case class Service( serverPowerApi: Boolean, usePlayActions: Boolean, comment: Option[String] = None) { - def serializers: Set[Serializer] = (methods.map(_.deserializer) ++ methods.map(_.serializer)).toSet + def serializers: Seq[Serializer] = (methods.map(_.deserializer) ++ methods.map(_.serializer)).distinct def packageDir = packageName.replace('.', '/') } diff --git a/codegen/src/main/scala/akka/grpc/gen/scaladsl/Service.scala b/codegen/src/main/scala/akka/grpc/gen/scaladsl/Service.scala index 93a31a6c2..3e6d6cf90 100644 --- a/codegen/src/main/scala/akka/grpc/gen/scaladsl/Service.scala +++ b/codegen/src/main/scala/akka/grpc/gen/scaladsl/Service.scala @@ -19,7 +19,7 @@ case class Service( serverPowerApi: Boolean, usePlayActions: Boolean, comment: Option[String] = None) { - def serializers: Set[Serializer] = (methods.map(_.deserializer) ++ methods.map(_.serializer)).toSet + def serializers: Seq[Serializer] = (methods.map(_.deserializer) ++ methods.map(_.serializer)).distinct def packageDir = packageName.replace('.', '/') } diff --git a/codegen/src/main/twirl/templates/JavaClient/GenMethodImports.scala.txt b/codegen/src/main/twirl/templates/JavaClient/GenMethodImports.scala.txt index e25b6930b..066025725 100644 --- a/codegen/src/main/twirl/templates/JavaClient/GenMethodImports.scala.txt +++ b/codegen/src/main/twirl/templates/JavaClient/GenMethodImports.scala.txt @@ -12,5 +12,5 @@ case akka.grpc.gen.ClientStreaming => singleResponse case akka.grpc.gen.ServerStreaming => streamResponse case akka.grpc.gen.BidiStreaming => streamResponse - }.toSet.mkString("\n") + }.distinct.mkString("\n") } diff --git a/codegen/src/main/twirl/templates/ScalaClient/Client.scala.txt b/codegen/src/main/twirl/templates/ScalaClient/Client.scala.txt index 1bcaf6cf4..ba15b3918 100644 --- a/codegen/src/main/twirl/templates/ScalaClient/Client.scala.txt +++ b/codegen/src/main/twirl/templates/ScalaClient/Client.scala.txt @@ -24,7 +24,7 @@ import akka.grpc.internal.ClientState @{ def withSingleResponse(stmt: String) = Set("import akka.grpc.scaladsl.SingleResponseRequestBuilder", stmt) def withStreamResponse(stmt: String) = Set("import akka.grpc.scaladsl.StreamResponseRequestBuilder", stmt) - service.methods.toSet.flatMap { method: akka.grpc.gen.scaladsl.Method => + service.methods.distinct.flatMap { method: akka.grpc.gen.scaladsl.Method => val statements = method.methodType match { case akka.grpc.gen.Unary => withSingleResponse("import akka.grpc.internal.ScalaUnaryRequestBuilder")