Skip to content

Commit

Permalink
[ATL-1808] feat(castor): update http server for new OAS (#35)
Browse files Browse the repository at this point in the history
* fix(castor): update http controller interface for new OAS

* feat(castor): add all serializers / deserializers for new OAS models

* feat(castor): add mock responses for all endpoints

* feat(castor): patch broken generated models

* feat(castor): rename api-server to just server
  • Loading branch information
patlo-iog authored Sep 22, 2022
1 parent 6e388b3 commit 6f25f4c
Show file tree
Hide file tree
Showing 37 changed files with 278 additions and 234 deletions.
11 changes: 3 additions & 8 deletions castor/service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@ __Running Castor service locally for development__

```bash
docker-compose -f docker/docker-compose-local.yaml up -d
sbt api-server/run
sbt server/run
```

---

## Known limitations

### OpenAPI codegen
### Castor `worker` process embedded inside `server`

The usage of `oneOf` / `anyOf` in OpenAPI specification doesn't map nicely to scala code using default template.
This has to be eventually addressed by customizing `mustache` template.

### Castor `worker` process embedded inside `api-server`

Castor worker process which is responsible for async comminucation with other components is temporarily embedded inside `api-server`.
Castor worker process which is responsible for async comminucation with other components is temporarily embedded inside `server`.
This impose some restrictions on scalability as it requires some coordination of between `worker` instances.
It should be addressed going forward.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 7 additions & 4 deletions castor/service/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ThisBuild / apiBaseDirectory := baseDirectory.value / "../api"
// Project definitions
lazy val root = project
.in(file("."))
.aggregate(core, sql, `api-server`)
.aggregate(core, sql, server)

lazy val core = project
.in(file("core"))
Expand All @@ -28,15 +28,18 @@ lazy val sql = project
)
.dependsOn(core)

lazy val `api-server` = project
.in(file("api-server"))
lazy val server = project
.in(file("server"))
.settings(
name := "castor-api-server",
name := "castor-server",
libraryDependencies ++= apiServerDependencies,
// OpenAPI settings
Compile / sourceGenerators += openApiGenerateClasses,
openApiGeneratorSpec := apiBaseDirectory.value / "http/castor-openapi-spec.yaml",
openApiGeneratorConfig := baseDirectory.value / "openapi/generator-config/config.yaml",
openApiGeneratorImportMapping := Seq("DidType", "DidOperationType", "DidOperationStatus")
.map(model => (model, s"io.iohk.atala.castor.server.http.OASModelPatches.$model"))
.toMap,
// gRPC settings
Compile / PB.targets := Seq(scalapb.gen() -> (Compile / sourceManaged).value / "scalapb"),
Compile / PB.protoSources := Seq(apiBaseDirectory.value / "grpc")
Expand Down
2 changes: 2 additions & 0 deletions castor/service/project/OpenApiGeneratorPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ object OpenApiGeneratorPlugin extends AutoPlugin {
val openApiGeneratorSpec = settingKey[File]("The OpenAPI specification file.")
val openApiGeneratorConfig = settingKey[File]("The generator config file.")
val openApiGenerateClasses = taskKey[Seq[File]]("Generate API & model classes.")
val openApiGeneratorImportMapping = settingKey[Map[String, String]]("The generator custom import mapping.")
}

import autoImport._
Expand All @@ -21,6 +22,7 @@ object OpenApiGeneratorPlugin extends AutoPlugin {
configurator.setInputSpec(openApiGeneratorSpec.value.getPath)
configurator.setOutputDir(((Compile / sourceManaged).value / "openapi").getPath)
configurator.setValidateSpec(true)
configurator.setImportMappings(openApiGeneratorImportMapping.value.asJava)
val gen = new DefaultGenerator()
gen.opts(configurator.toClientOptInput)
gen.generate().asScala
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The folder where templates can be found
templateDir: "api-server/openapi/generator-config/scala-akka-http-server"
templateDir: "server/openapi/generator-config/scala-akka-http-server"

# Only generate output for templates registered with the 'Apis' or 'Models' types
globalProperties:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.iohk.atala.castor.apiserver
package io.iohk.atala.castor.server

import zio.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.iohk.atala.castor.apiserver
package io.iohk.atala.castor.server

import akka.actor.BootstrapSetup
import akka.actor.setup.ActorSystemSetup
import akka.actor.typed.ActorSystem
import akka.actor.typed.scaladsl.Behaviors
import akka.http.scaladsl.server.Route
import doobie.util.transactor.Transactor
import io.iohk.atala.castor.apiserver.grpc.service.DIDServiceGrpcImpl
import io.iohk.atala.castor.apiserver.grpc.{GrpcServer, GrpcServices}
import io.iohk.atala.castor.apiserver.http.{HttpRoutes, HttpServer}
import io.iohk.atala.castor.server.grpc.service.DIDServiceGrpcImpl
import io.iohk.atala.castor.server.grpc.{GrpcServer, GrpcServices}
import io.iohk.atala.castor.server.http.{HttpRoutes, HttpServer}
import io.iohk.atala.castor.core.service.{
DIDAuthenticationService,
DIDOperationService,
Expand All @@ -18,12 +18,12 @@ import io.iohk.atala.castor.core.service.{
MockDIDService,
MockIrisNotificationService
}
import io.iohk.atala.castor.apiserver.http.marshaller.{
import io.iohk.atala.castor.server.http.marshaller.{
DIDApiMarshallerImpl,
DIDAuthenticationApiMarshallerImpl,
DIDOperationsApiMarshallerImpl
}
import io.iohk.atala.castor.apiserver.http.service.{
import io.iohk.atala.castor.server.http.service.{
DIDApiServiceImpl,
DIDAuthenticationApiServiceImpl,
DIDOperationsApiServiceImpl
Expand All @@ -41,7 +41,7 @@ import io.iohk.atala.castor.sql.repository.{JdbcDIDOperationRepository, Transact
import zio.*
import zio.interop.catz.*
import cats.effect.std.Dispatcher
import io.iohk.atala.castor.apiserver.worker.{EventConsumer, WorkerApp}
import io.iohk.atala.castor.server.worker.{EventConsumer, WorkerApp}
import io.iohk.atala.castor.core.model.IrisNotification
import zio.stream.ZStream

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.iohk.atala.castor.apiserver.grpc
package io.iohk.atala.castor.server.grpc

import io.grpc.{ServerBuilder, ServerServiceDefinition}
import io.grpc.protobuf.services.ProtoReflectionService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.iohk.atala.castor.apiserver.grpc
package io.iohk.atala.castor.server.grpc

import akka.actor.typed.ActorSystem
import io.grpc.ServerServiceDefinition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.iohk.atala.castor.apiserver.grpc.service
package io.iohk.atala.castor.server.grpc.service

import io.iohk.atala.castor.core.service.DIDService
import io.iohk.atala.castor.proto.castor_api.{DIDServiceGrpc, Ping, Pong}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.iohk.atala.castor.apiserver.http
package io.iohk.atala.castor.server.http

import akka.http.scaladsl.server.Route
import akka.http.scaladsl.server.Directives.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.iohk.atala.castor.apiserver.http
package io.iohk.atala.castor.server.http

import akka.actor.typed.ActorSystem
import akka.http.scaladsl.Http
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.iohk.atala.castor.server.http

object OASModelPatches {

type DidType = String
type DidOperationType = String
type DidOperationStatus = String

}
Loading

0 comments on commit 6f25f4c

Please sign in to comment.