-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/package-compiler-compatibility (#128)
1.) added RelocatableFolders to make sure this package works with PackageCompiler.jl 2.) Now spawning cron tasks in any available thread of just the main thread 3.) added redoc docs option, but still default to swagger 4.) bumped version to 1.2
- Loading branch information
Showing
11 changed files
with
1,929 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
name = "Oxygen" | ||
uuid = "df9a0d86-3283-4920-82dc-4555fc0d1d8b" | ||
authors = ["Nathan Ortega <[email protected]>"] | ||
version = "1.1.11" | ||
version = "1.2" | ||
|
||
[deps] | ||
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" | ||
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" | ||
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" | ||
MIMEs = "6c6e2e6c-3030-632d-7369-2d6c69616d65" | ||
RelocatableFolders = "05181044-ff0b-4ac5-8273-598c1e38db00" | ||
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc" | ||
|
||
[compat] | ||
HTTP = "^1" | ||
JSON3 = "^1.9" | ||
MIMEs = "^0.1.4" | ||
julia = "^1.6.6" | ||
RelocatableFolders = "^1" | ||
julia = "^1.6" |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,16 +1,25 @@ | ||
module AutoDoc | ||
using HTTP | ||
using Dates | ||
using RelocatableFolders | ||
|
||
include("cron.jl"); using .Cron | ||
include("util.jl"); using .Util | ||
|
||
export registerschema, docspath, schemapath, getschema, | ||
swaggerhtml, configdocs, mergeschema, setschema, router, | ||
enabledocs, disabledocs, isdocsenabled, registermountedfolder, | ||
swaggerhtml, redochtml, getschemapath, configdocs, mergeschema, setschema, | ||
router, enabledocs, disabledocs, isdocsenabled, registermountedfolder, | ||
getrepeatasks, hasmiddleware, compose, resetstatevariables, | ||
@cron, stopcronjobs, startcronjobs, getcronjobs, resetcronstate | ||
|
||
const SWAGGER_VERSION = "[email protected]" | ||
const REDOC_VERSION = "[email protected]" | ||
|
||
# Generate a reliable path to our internal data folder that works when the | ||
# package is used with PackageCompiler.jl | ||
const DATA_PATH = @path abspath(joinpath(@__DIR__, "..", "data")) | ||
|
||
|
||
struct TaggedRoute | ||
httpmethods::Vector{String} | ||
tags::Vector{String} | ||
|
@@ -35,6 +44,10 @@ global cronjobs = [] | |
global schema = defaultSchema | ||
global const custommiddlware = Ref{Dict{String, Tuple}}(Dict()) | ||
|
||
function getschemapath()::String | ||
return "$docspath$schemapath" | ||
end | ||
|
||
function getrepeatasks() | ||
return repeattasks | ||
end | ||
|
@@ -46,7 +59,7 @@ end | |
function resetstatevariables() | ||
global enable_auto_docs = true | ||
global docspath = "/docs" | ||
global schemapath = "/docs/schema" | ||
global schemapath = "/schema" | ||
global mountedfolders = Set{String}() | ||
global taggedroutes = Dict{String, TaggedRoute}() | ||
global repeattasks = [] | ||
|
@@ -97,7 +110,7 @@ Configure the default docs and schema endpoints | |
""" | ||
function configdocs(docs_url::String = docspath, schema_url::String = schemapath) | ||
global docspath = docs_url | ||
global schemapath = "$docs_url$schema_url" | ||
global schemapath = schemapath | ||
end | ||
|
||
""" | ||
|
@@ -361,8 +374,8 @@ Used to generate & register schema related for a specific endpoint | |
""" | ||
function registerschema(path::String, httpmethod::String, parameters, returntype::Array) | ||
|
||
# skip docs & schema paths | ||
if path in [docspath, schemapath] | ||
# skip any doc related endpoints | ||
if startswith(path, docspath) | ||
return | ||
end | ||
|
||
|
@@ -422,30 +435,54 @@ end | |
Read in a static file from the /data folder | ||
""" | ||
function readstaticfile(filepath::String) :: String | ||
path = abspath(joinpath(@__DIR__, "..", "data", filepath)) | ||
path = joinpath(DATA_PATH, filepath) | ||
return read(open(path), String) | ||
end | ||
|
||
function redochtml() :: HTTP.Response | ||
redocjs = readstaticfile("$REDOC_VERSION/redoc.standalone.js") | ||
|
||
return html(""" | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Docs</title> | ||
<meta charset="utf-8"/> | ||
<meta name="description" content="Docs" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet"> | ||
</head> | ||
<body> | ||
<redoc spec-url="$(getschemapath())"></redoc> | ||
<script>$redocjs</script> | ||
</body> | ||
</html> | ||
""") | ||
end | ||
|
||
""" | ||
Return HTML page to render the autogenerated docs | ||
""" | ||
function swaggerhtml() :: HTTP.Response | ||
|
||
# load static content files | ||
swaggerjs = readstaticfile("[email protected]/swagger-ui-bundle.js") | ||
swaggerstyles = readstaticfile("[email protected]/swagger-ui.css") | ||
swaggerjs = readstaticfile("$SWAGGER_VERSION/swagger-ui-bundle.js") | ||
swaggerstyles = readstaticfile("$SWAGGER_VERSION/swagger-ui.css") | ||
|
||
return html(""" | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Docs</title> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="description" content="SwaggerUI" /> | ||
<meta name="description" content="Docs" /> | ||
<style>$swaggerstyles</style> | ||
<title>SwaggerUI</title> | ||
</head> | ||
<body> | ||
|
@@ -454,7 +491,7 @@ function swaggerhtml() :: HTTP.Response | |
<script> | ||
window.onload = () => { | ||
window.ui = SwaggerUIBundle({ | ||
url: window.location.origin + "$schemapath", | ||
url: window.location.origin + "$(getschemapath())", | ||
dom_id: '#swagger-ui', | ||
}); | ||
}; | ||
|
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
77a19dd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
77a19dd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/92368
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: