Skip to content

Commit

Permalink
Merge pull request #292 from ulitol97/master
Browse files Browse the repository at this point in the history
v0.2.2: API Docs with Rho
  • Loading branch information
ulitol97 authored Mar 3, 2022
2 parents 26e9a10 + cf51dd7 commit 06fa350
Show file tree
Hide file tree
Showing 85 changed files with 3,115 additions and 2,908 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ENV SSL_FIX="-Djdk.tls.client.protocols=TLSv1.2"

# Define commands to launch RDFShape
ENV HTTPS_CLI_ARG="--https"
ENV RDFSHAPE_CMD_HTTP="rdfshape $SSL_FIX --port $PORT"
ENV RDFSHAPE_CMD_HTTP="rdfshape $SSL_FIX --port $PORT -s"
ENV RDFSHAPE_CMD_HTTPS="$RDFSHAPE_CMD_HTTP $HTTPS_CLI_ARG"

CMD bash -c "if [[ ! -z '$USE_HTTPS' ]]; then $RDFSHAPE_CMD_HTTPS; else $RDFSHAPE_CMD_HTTP; fi"
20 changes: 15 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ lazy val mdocSettings = Seq(
"CLIENT_NAME" -> "RDFShape Client",
"CLIENT_REPO" -> "https://github.com/weso/rdfshape-client/",
"CLIENT_URL" -> "https://rdfshape.weso.es/",
"WESOLOCAL_URL" -> "https://github.com/weso/wesolocal/wiki/RDFShape"
"WESOLOCAL_URL" -> "https://github.com/weso/wesolocal/wiki/RDFShape",
"API-DOCS_URL" -> "https://app.swaggerhub.com/apis-docs/weso/RDFShape"
),
mdocExtraArguments := Seq("--no-link-hygiene"),
/* When creating/publishing the docusaurus site, update the dynamic mdoc and
Expand Down Expand Up @@ -262,6 +263,7 @@ lazy val server = project
http4sBlazeClient,
http4sEmberClient,
http4sCirce,
rho_swagger,
umlShaclex,
shexs,
shaclex,
Expand All @@ -274,7 +276,8 @@ lazy val server = project
scalaj,
wesoUtils % Test,
munitEffect % Test,
mongodb
mongo4catsCore,
mongo4catsCirce
)
)

Expand Down Expand Up @@ -302,9 +305,11 @@ lazy val docs = project
lazy val MUnitFramework = new TestFramework("munit.Framework")
/* DEPENDENCY versions */
lazy val http4sVersion = "1.0.0-M30"
lazy val rhoVersion = "0.23.0-M1"
lazy val catsVersion = "2.7.0"
/* ------------------------------------------------------------------------- */
lazy val mongodbVersion = "4.4.0"
lazy val mongodbVersion = "4.4.1"
lazy val mongo4catsVersion = "0.4.5"
lazy val any23Version = "2.4"
lazy val rdf4jVersion = "3.7.4"
lazy val graphvizJavaVersion = "0.18.1"
Expand All @@ -328,11 +333,16 @@ lazy val http4sBlazeClient =
lazy val http4sEmberClient =
"org.http4s" %% "http4s-ember-client" % http4sVersion
lazy val http4sCirce = "org.http4s" %% "http4s-circe" % http4sVersion
lazy val rho_swagger = "org.http4s" %% "rho-swagger" % rhoVersion
lazy val catsCore = "org.typelevel" %% "cats-core" % catsVersion
lazy val catsKernel = "org.typelevel" %% "cats-kernel" % catsVersion
lazy val mongodb = "org.mongodb.scala" %% "mongo-scala-driver" % mongodbVersion
lazy val any23_core = "org.apache.any23" % "apache-any23-core" % any23Version
lazy val any23_api = "org.apache.any23" % "apache-any23-api" % any23Version
lazy val mongo4catsCore =
"io.github.kirill5k" %% "mongo4cats-core" % mongo4catsVersion
lazy val mongo4catsCirce =
"io.github.kirill5k" %% "mongo4cats-circe" % mongo4catsVersion
lazy val any23_core = "org.apache.any23" % "apache-any23-core" % any23Version
lazy val any23_api = "org.apache.any23" % "apache-any23-api" % any23Version
lazy val any23_scraper =
"org.apache.any23.plugins" % "apache-any23-html-scraper" % "2.3"
lazy val rdf4j_runtime = "org.eclipse.rdf4j" % "rdf4j-runtime" % rdf4jVersion
Expand Down
8 changes: 4 additions & 4 deletions docs/api-usage/usage_cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ title: Command Line Interface

@APP_NAME@'s CLI currently supports the following launch-arguments:

- `--https` Attempt to serve the API via HTTPS (defaults to false), searching for certificates as specified in the
current environment.
- `-p, --port` Port in which the API will listen for requests. Values must be in range 1-65535 (defaults to 8080).
- `-v, --verbose` Show additional logging information (use cumulative times for additional info, like: `-vvv`)
- `--https` Attempt to serve the API via HTTPS (default is false), searching for certificates as specified in the current environment.
- `-p, --port` Port in which the API will listen for requests. Values must be in range 1-65535 (default is 8080).
- `-s, --silent` Enable silent mode in order not to log any output to console (default is false)
- `-v, --verbose` Show additional logging information (use cumulative times for additional info, like: `-vvv`)
- `--version` Print the version of the program
- `--help` Print the help menu

Expand Down
30 changes: 0 additions & 30 deletions docs/api-usage/usage_examples.md

This file was deleted.

53 changes: 0 additions & 53 deletions docs/api-usage/usage_tutorial.md

This file was deleted.

37 changes: 23 additions & 14 deletions modules/server/src/main/scala/es/weso/rdfshape/server/Server.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package es.weso.rdfshape.server

import cats.effect._
import cats.implicits._
import com.typesafe.scalalogging.LazyLogging
import es.weso.rdfshape.server.Server._
import es.weso.rdfshape.server.api.routes.api.service.APIService
import es.weso.rdfshape.server.api.definitions.ApiDefinitions.api
import es.weso.rdfshape.server.api.routes.api.service.BaseService
import es.weso.rdfshape.server.api.routes.data.service.DataService
import es.weso.rdfshape.server.api.routes.endpoint.service.EndpointService
import es.weso.rdfshape.server.api.routes.fetch.service.FetchService
import es.weso.rdfshape.server.api.routes.permalink.service.PermalinkService
import es.weso.rdfshape.server.api.routes.schema.service.SchemaService
import es.weso.rdfshape.server.api.routes.shapemap.service.ShapeMapService
import es.weso.rdfshape.server.api.routes.wikibase.service.WikibaseService
import es.weso.rdfshape.server.api.swagger.swaggerMiddleware
import es.weso.rdfshape.server.utils.error.exceptions.SSLContextCreationException
import es.weso.rdfshape.server.utils.error.{ExitCodes, SysUtils}
import es.weso.rdfshape.server.utils.secure.SSLHelper
Expand All @@ -20,6 +21,7 @@ import org.http4s.blaze.client.BlazeClientBuilder
import org.http4s.blaze.server.BlazeServerBuilder
import org.http4s.client.Client
import org.http4s.implicits.http4sKleisliResponseSyntaxOptionT
import org.http4s.server.Router
import org.http4s.server.middleware.{CORS, CORSPolicy, Logger}
import org.http4s.{HttpApp, HttpRoutes}

Expand Down Expand Up @@ -126,9 +128,11 @@ private class Server(
*
* @param client Http4s' client in charge of the application
* @return Http4s' application with the given client and a request-logging middleware
* @note All application services are mounted behind the "api/" prefix
*/
private def createApp(client: Client[IO]): HttpApp[IO] = {
val app = routesService(client).orNotFound
// Mount all routes behind "api/"
val app = Router(`api` -> routesService(client)).orNotFound
// Http4s logger middleware settings
Logger.httpApp(logHeaders = true, logBody = false)(app)
}
Expand Down Expand Up @@ -190,18 +194,23 @@ object Server {
s.main(Array.empty[String])
}

/** Configure the http4s application to use the specified sources as API routes
/** Application's global service composed of all routes and CORS configuration
*/
private def routesService(client: Client[IO]): HttpRoutes[IO] = {
corsConfiguration.apply(
APIService(client).routes <+>
DataService(client).routes <+>
SchemaService(client).routes <+>
ShapeMapService(client).routes <+>
WikibaseService(client).routes <+>
EndpointService(client).routes <+>
PermalinkService(client).routes <+>
FetchService(client).routes
)
corsConfiguration.apply(allRoutes(client))
}

/** All Rho route functions composed into one with swagger middleware
*/
private def allRoutes(client: Client[IO]): HttpRoutes[IO] =
(BaseService(client).routes and
DataService(client).routes and
SchemaService(client).routes and
ShapeMapService(client).routes and
WikibaseService(client).routes and
PermalinkService(client).routes and
EndpointService(client).routes and
FetchService(client).routes)
.toRoutes(swaggerMiddleware)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package es.weso.rdfshape.server.api

import io.circe.Decoder

/** This trait defines an operation performed by a route in a service
* and the way to decode the incoming data into the required object
*
* All errors occurred during object instantiation will be mapped to
* DecodingErrors
*
* @tparam C Type into which the client data will be decoded for usage in this route
*/
trait ServiceRouteOperation[C] {

/** Decoder in charge of converting the data sent by the client to a
* usable domain structure
*/
implicit val decoder: Decoder[C]
}
Loading

0 comments on commit 06fa350

Please sign in to comment.