-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1485 from adpi2/add-api-doc
Add API doc
- Loading branch information
Showing
13 changed files
with
169 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
modules/server/src/main/resources/lib/swagger-initializer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
window.onload = function() { | ||
window.ui = SwaggerUIBundle({ | ||
urls: [ | ||
{ name: "Scaladex API v1", url: "/api/v1/open-api.json" }, | ||
{ name: "Scaladex API v0", url: "/api/open-api.json" } | ||
], | ||
dom_id: '#swagger-ui', | ||
deepLinking: true, | ||
presets: [ | ||
SwaggerUIBundle.presets.apis, | ||
SwaggerUIStandalonePreset | ||
], | ||
plugins: [ | ||
SwaggerUIBundle.plugins.DownloadUrl | ||
], | ||
layout: "StandaloneLayout" | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 25 additions & 14 deletions
39
modules/server/src/main/scala/scaladex/server/route/api/DocumentationRoutes.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,36 @@ | ||
package scaladex.server.route.api | ||
|
||
import endpoints4s.openapi.model.OpenApi | ||
import endpoints4s.pekkohttp.server | ||
import endpoints4s.Encoder | ||
import org.apache.pekko.http.cors.scaladsl.CorsDirectives.cors | ||
import org.apache.pekko.http.scaladsl.server.Directives.concat | ||
import org.apache.pekko.http.scaladsl.marshalling.Marshaller | ||
import org.apache.pekko.http.scaladsl.marshalling.ToEntityMarshaller | ||
import org.apache.pekko.http.scaladsl.model.MediaTypes | ||
import org.apache.pekko.http.scaladsl.model.StatusCodes | ||
import org.apache.pekko.http.scaladsl.server.Directives._ | ||
import org.apache.pekko.http.scaladsl.server.Route | ||
|
||
/** | ||
* Akka-Http routes serving the documentation of the public HTTP API of Scaladex | ||
*/ | ||
object DocumentationRoute extends server.Endpoints with server.JsonEntitiesFromEncodersAndDecoders { | ||
object DocumentationRoute { | ||
implicit def marshallerFromEncoder[T](implicit encoder: Encoder[T, String]): ToEntityMarshaller[T] = | ||
Marshaller | ||
.stringMarshaller(MediaTypes.`application/json`) | ||
.compose(c => encoder.encode(c)) | ||
|
||
val route: Route = cors() { | ||
concat( | ||
endpoint( | ||
get(path / "api" / "open-api.json"), | ||
ok(jsonResponse[OpenApi]) | ||
).implementedBy(_ => ApiDocumentation.apiV0), | ||
endpoint( | ||
get(path / "api" / "v1" / "open-api.json"), | ||
ok(jsonResponse[OpenApi]) | ||
).implementedBy(_ => ApiDocumentation.apiV1) | ||
) | ||
get { | ||
concat( | ||
pathPrefix("api" / "doc")( | ||
pathEnd(redirect("/api/doc/", StatusCodes.PermanentRedirect)) ~ | ||
pathSingleSlash(getFromResource("lib/swagger-ui/index.html")) ~ | ||
// override default swagger-initializer | ||
path("swagger-initializer.js")(getFromResource("lib/swagger-initializer.js")) ~ | ||
getFromResourceDirectory("lib/swagger-ui") | ||
), | ||
path("api" / "open-api.json")(complete(StatusCodes.OK, ApiDocumentation.apiV0)), | ||
path("api" / "v1" / "open-api.json")(complete(StatusCodes.OK, ApiDocumentation.apiV1)) | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.