Skip to content

Commit b0d4c74

Browse files
committed
update swagger documentation generation
1 parent 3890732 commit b0d4c74

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ThisBuild / organization := "app.softnetwork"
3030

3131
name := "generic-persistence-api"
3232

33-
ThisBuild / version := "0.3.1.2"
33+
ThisBuild / version := "0.3.1.3"
3434

3535
ThisBuild / scalaVersion := "2.12.11"
3636

server/src/main/resources/softnetwork-api-server.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ akka{
1313

1414
softnetwork{
1515
api{
16+
name = ""
17+
name = ${?APP}
18+
version = ""
19+
version = ${?VERSION}
1620
server{
1721
interface = "0.0.0.0"
1822
interface = ${?HTTP_SERVER_INTERFACE}

server/src/main/scala/app/softnetwork/api/server/ApiEndpoint.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package app.softnetwork.api.server
22

33
import akka.http.scaladsl.server.Route
4-
import app.softnetwork.persistence.{appName, version}
4+
import app.softnetwork.api.server.config.ServerSettings
55
import sttp.capabilities.WebSockets
66
import sttp.capabilities.akka.AkkaStreams
77
import sttp.tapir.server.ServerEndpoint
@@ -15,10 +15,14 @@ trait ApiEndpoint {
1515

1616
import ApiEndpoint._
1717

18+
val applicationName: String = ServerSettings.ApplicationName
19+
20+
val applicationVersion: String = ServerSettings.ApplicationVersion
21+
1822
def endpoints: List[ServerEndpoint[AkkaStreams with WebSockets, Future]]
1923

2024
def swaggerEndpoints: List[ServerEndpoint[AkkaStreams with WebSockets, Future]] =
21-
endpointsToSwaggerEndpoints(endpoints)
25+
endpointsToSwaggerEndpoints(endpoints, applicationName, applicationVersion)
2226

2327
def swaggerRoute(implicit ec: ExecutionContext): Route = swaggerEndpoints
2428

@@ -29,12 +33,14 @@ trait ApiEndpoint {
2933
object ApiEndpoint {
3034

3135
def endpointsToSwaggerEndpoints(
32-
endpoints: List[ServerEndpoint[AkkaStreams with WebSockets, Future]]
36+
endpoints: List[ServerEndpoint[AkkaStreams with WebSockets, Future]],
37+
applicationName: String,
38+
applicationVersion: String
3339
): List[ServerEndpoint[AkkaStreams with WebSockets, Future]] =
3440
SwaggerInterpreter().fromEndpoints[Future](
3541
endpoints.map(_.endpoint.prependIn(config.ServerSettings.RootPath)),
36-
appName,
37-
version
42+
applicationName,
43+
applicationVersion
3844
)
3945

4046
implicit def endpointsToRoute(

server/src/main/scala/app/softnetwork/api/server/ApiEndpoints.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package app.softnetwork.api.server
22

33
import akka.actor.typed.ActorSystem
44
import akka.http.scaladsl.server.Route
5+
import app.softnetwork.api.server.config.ServerSettings
56
import sttp.capabilities.WebSockets
67
import sttp.capabilities.akka.AkkaStreams
78
import sttp.tapir.server.ServerEndpoint
@@ -12,12 +13,14 @@ trait ApiEndpoints extends ApiRoutes {
1213

1314
import ApiEndpoint._
1415

16+
val applicationName: String = ServerSettings.ApplicationName
17+
1518
def endpoints: ActorSystem[_] => List[ServerEndpoint[AkkaStreams with WebSockets, Future]]
1619

1720
override def apiRoutes(system: ActorSystem[_]): Route = {
1821
implicit def ec: ExecutionContext = system.executionContext
1922
val eps = endpoints(system)
20-
eps ++ endpointsToSwaggerEndpoints(eps)
23+
eps ++ endpointsToSwaggerEndpoints(eps, applicationName, applicationVersion)
2124
}
2225

2326
}

server/src/main/scala/app/softnetwork/api/server/ApiRoutes.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import akka.actor.typed.ActorSystem
55
import akka.http.scaladsl.model.headers.RawHeader
66
import akka.http.scaladsl.model.{HttpResponse, StatusCodes}
77
import akka.http.scaladsl.server.{Directives, ExceptionHandler, Route}
8-
import app.softnetwork.persistence.version
8+
import app.softnetwork.api.server.config.ServerSettings
99
import org.json4s.Formats
1010
import app.softnetwork.serialization._
1111
import org.slf4j.Logger
@@ -16,6 +16,8 @@ import scala.util.{Failure, Success, Try}
1616
*/
1717
trait ApiRoutes extends Directives with GrpcServices with DefaultComplete {
1818

19+
val applicationVersion: String = ServerSettings.ApplicationVersion
20+
1921
override implicit def formats: Formats = commonFormats
2022

2123
def log: Logger
@@ -36,7 +38,7 @@ trait ApiRoutes extends Directives with GrpcServices with DefaultComplete {
3638
logRequestResult("RestAll") {
3739
pathPrefix(config.ServerSettings.RootPath) {
3840
Try(
39-
respondWithHeaders(RawHeader("Api-Version", version)) {
41+
respondWithHeaders(RawHeader("Api-Version", applicationVersion)) {
4042
HealthCheckService.route ~ apiRoutes(system)
4143
}
4244
) match {

server/src/main/scala/app/softnetwork/api/server/config/ServerSettings.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ object ServerSettings {
1010
val Interface: String = config.getString("softnetwork.api.server.interface")
1111
val Port: Int = config.getInt("softnetwork.api.server.port")
1212
val RootPath: String = config.getString("softnetwork.api.server.root-path")
13+
14+
val ApplicationName: String = config.getString("softnetwork.api.name")
15+
val ApplicationVersion: String = config.getString("softnetwork.api.version")
1316
}

0 commit comments

Comments
 (0)