Skip to content

Commit

Permalink
Merge pull request #143 from phenoscape/issue-132
Browse files Browse the repository at this point in the history
Serve swagger directly from the server.
  • Loading branch information
balhoff authored Aug 26, 2021
2 parents 85f90c5 + 5bc5225 commit 083b994
Show file tree
Hide file tree
Showing 14 changed files with 345 additions and 83 deletions.
Binary file added src/main/resources/docs/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/docs/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions src/main/resources/docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}

*,
*:before,
*:after
{
box-sizing: inherit;
}

body
{
margin:0;
background: #fafafa;
}
</style>
</head>

<body>
<div id="swagger-ui"></div>

<script src="./swagger-ui-bundle.js"> </script>
<script src="./swagger-ui-standalone-preset.js"> </script>
<script>
window.onload = function() {

// Build a system
const ui = SwaggerUIBundle({
url: "../docs/swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})

window.ui = ui
}
</script>
</body>
</html>
67 changes: 67 additions & 0 deletions src/main/resources/docs/oauth2-redirect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!doctype html>
<html lang="en-US">
<body onload="run()">
</body>
</html>
<script>
'use strict';
function run () {
var oauth2 = window.opener.swaggerUIRedirectOauth2;
var sentState = oauth2.state;
var redirectUrl = oauth2.redirectUrl;
var isValid, qp, arr;

if (/code|token|error/.test(window.location.hash)) {
qp = window.location.hash.substring(1);
} else {
qp = location.search.substring(1);
}

arr = qp.split("&")
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';})
qp = qp ? JSON.parse('{' + arr.join() + '}',
function (key, value) {
return key === "" ? value : decodeURIComponent(value)
}
) : {}

isValid = qp.state === sentState

if ((
oauth2.auth.schema.get("flow") === "accessCode"||
oauth2.auth.schema.get("flow") === "authorizationCode"
) && !oauth2.auth.code) {
if (!isValid) {
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "warning",
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
});
}

if (qp.code) {
delete oauth2.state;
oauth2.auth.code = qp.code;
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
} else {
let oauthErrorMsg
if (qp.error) {
oauthErrorMsg = "["+qp.error+"]: " +
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
(qp.error_uri ? "More info: "+qp.error_uri : "");
}

oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "error",
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
});
}
} else {
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
}
window.close();
}
</script>
104 changes: 104 additions & 0 deletions src/main/resources/docs/swagger-ui-bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/main/resources/docs/swagger-ui-bundle.js.map

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/main/resources/docs/swagger-ui-standalone-preset.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/main/resources/docs/swagger-ui.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/main/resources/docs/swagger-ui.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/main/resources/docs/swagger-ui.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/main/resources/docs/swagger-ui.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"openapi" : "3.0.0",
"servers" : [ {
"url" : "https://kb.phenoscape.org/owlery"
} ],
"info" : {
"description" : "Owlery provides a web API for an [OWL API](http://owlapi.sourceforge.net)-based reasoner containing a configurable set of ontologies (a \"knowledgebase\"). ",
"version" : "1.0.0",
Expand Down
163 changes: 83 additions & 80 deletions src/main/scala/org/phenoscape/owlery/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,112 +83,115 @@ object Main extends HttpApp with App {

def routes: Route = Route.seal {
cors() {
pathPrefix("kbs") {
pathPrefix(Segment) { kbName =>
Owlery.kb(kbName) match {
case None => reject
case Some(kb) =>
path("subclasses") {
objectAndPrefixParametersToClass { expression =>
parameters("direct".?(false), "includeEquivalent".?(false), "includeNothing".?(false), "includeDeprecated".?(true)) { (direct, includeEquivalent, includeNothing, includeDeprecated) =>
complete {
kb.querySubClasses(expression, direct, includeEquivalent, includeNothing, includeDeprecated)
}
}
}
} ~
path("superclasses") {
pathPrefix("docs") {
getFromResourceDirectory("docs")
} ~
pathPrefix("kbs") {
pathPrefix(Segment) { kbName =>
Owlery.kb(kbName) match {
case None => reject
case Some(kb) =>
path("subclasses") {
objectAndPrefixParametersToClass { expression =>
parameters("direct".?(false), "includeEquivalent".?(false), "includeThing".?(false), "includeDeprecated".?(true)) { (direct, includeEquivalent, includeThing, includeDeprecated) =>
parameters("direct".?(false), "includeEquivalent".?(false), "includeNothing".?(false), "includeDeprecated".?(true)) { (direct, includeEquivalent, includeNothing, includeDeprecated) =>
complete {
kb.querySuperClasses(expression, direct, includeEquivalent, includeThing, includeDeprecated)
kb.querySubClasses(expression, direct, includeEquivalent, includeNothing, includeDeprecated)
}
}
}
} ~
path("instances") {
objectAndPrefixParametersToClass { expression =>
parameters("direct".?(false), "includeDeprecated".?(true)) { (direct, includeDeprecated) =>
complete {
kb.queryInstances(expression, direct, includeDeprecated)
path("superclasses") {
objectAndPrefixParametersToClass { expression =>
parameters("direct".?(false), "includeEquivalent".?(false), "includeThing".?(false), "includeDeprecated".?(true)) { (direct, includeEquivalent, includeThing, includeDeprecated) =>
complete {
kb.querySuperClasses(expression, direct, includeEquivalent, includeThing, includeDeprecated)
}
}
}
}
} ~
path("equivalent") {
objectAndPrefixParametersToClass { expression =>
parameters("includeDeprecated".?(true)) { includeDeprecated =>
complete {
kb.queryEquivalentClasses(expression, includeDeprecated)
} ~
path("instances") {
objectAndPrefixParametersToClass { expression =>
parameters("direct".?(false), "includeDeprecated".?(true)) { (direct, includeDeprecated) =>
complete {
kb.queryInstances(expression, direct, includeDeprecated)
}
}
}
}
} ~
path("satisfiable") {
objectAndPrefixParametersToClass { expression =>
complete {
kb.isSatisfiable(expression)
} ~
path("equivalent") {
objectAndPrefixParametersToClass { expression =>
parameters("includeDeprecated".?(true)) { includeDeprecated =>
complete {
kb.queryEquivalentClasses(expression, includeDeprecated)
}
}
}
}
} ~
path("types") {
parameters("object", "prefixes".as[Map[String, String]].?(NoPrefixes)).as(PrefixedIndividualIRI) { preIRI =>
parameters("direct".?(true), "includeThing".?(false), "includeDeprecated".?(true)) { (direct, includeThing, includeDeprecated) =>
} ~
path("satisfiable") {
objectAndPrefixParametersToClass { expression =>
complete {
kb.queryTypes(factory.getOWLNamedIndividual(preIRI.iri), direct, includeThing, includeDeprecated)
kb.isSatisfiable(expression)
}
}
}
} ~
path("extract") {
post {
parameters("type".as[ModuleType].?(ModuleType.STAR), "ontologies".as[Seq[IRI]].?(Seq.empty[IRI])) { (moduleType, fromIRIs) =>
handleWith(kb.extractModuleForOntology(_, moduleType, fromIRIs.toSet))
}
}
} ~
path("sparql") {
get {
parameter("query".as[Query]) { query =>
complete {
kb.performSPARQLQuery(query)
} ~
path("types") {
parameters("object", "prefixes".as[Map[String, String]].?(NoPrefixes)).as(PrefixedIndividualIRI) { preIRI =>
parameters("direct".?(true), "includeThing".?(false), "includeDeprecated".?(true)) { (direct, includeThing, includeDeprecated) =>
complete {
kb.queryTypes(factory.getOWLNamedIndividual(preIRI.iri), direct, includeThing, includeDeprecated)
}
}
}
} ~
path("extract") {
post {
parameter("query".as[Query].?(NullQuery)) {
case NullQuery => handleWith(kb.performSPARQLQuery)
case query => complete {
parameters("type".as[ModuleType].?(ModuleType.STAR), "ontologies".as[Seq[IRI]].?(Seq.empty[IRI])) { (moduleType, fromIRIs) =>
handleWith(kb.extractModuleForOntology(_, moduleType, fromIRIs.toSet))
}
}
} ~
path("sparql") {
get {
parameter("query".as[Query]) { query =>
complete {
kb.performSPARQLQuery(query)
}
}
}
} ~
path("expand") {
get {
parameter("query".as[Query]) { query =>
complete {
kb.expandSPARQLQuery(query)
} ~
post {
parameter("query".as[Query].?(NullQuery)) {
case NullQuery => handleWith(kb.performSPARQLQuery)
case query => complete {
kb.performSPARQLQuery(query)
}
}
}
}
} ~
post {
handleWith(kb.expandSPARQLQuery)
path("expand") {
get {
parameter("query".as[Query]) { query =>
complete {
kb.expandSPARQLQuery(query)
}
}
} ~
post {
handleWith(kb.expandSPARQLQuery)
}
} ~
pathEnd {
complete {
kb.summary
}
} ~
pathEnd {
complete {
kb.summary
}
}
}
} ~
pathEnd {
complete {
Owlery
}
}
}
} ~
pathEnd {
complete {
Owlery
}
}
}
}
}

Expand Down

0 comments on commit 083b994

Please sign in to comment.