Skip to content

Commit

Permalink
adding swagger docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Janis Erdmanis committed Mar 4, 2024
1 parent 61c1af7 commit f8e2f70
Show file tree
Hide file tree
Showing 7 changed files with 1,625 additions and 10 deletions.
6 changes: 4 additions & 2 deletions docs/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.0"
manifest_format = "2.0"
project_hash = "e6e288f80ff971aad6ad5ae367e9c3f13d5df3c8"
project_hash = "ce8a78da41862711080fb370a1c46c49f5736a0d"

[[deps.ANSIColoredPrinters]]
git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c"
Expand Down Expand Up @@ -74,7 +74,9 @@ version = "0.9.3"

[[deps.Documenter]]
deps = ["ANSIColoredPrinters", "AbstractTrees", "Base64", "CodecZlib", "Dates", "DocStringExtensions", "Downloads", "Git", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "MarkdownAST", "Pkg", "PrecompileTools", "REPL", "RegistryInstances", "SHA", "TOML", "Test", "Unicode"]
git-tree-sha1 = "4a40af50e8b24333b9ec6892546d9ca5724228eb"
git-tree-sha1 = "af68342f4801d8fac060b286d708983c51cae2f1"
repo-rev = "master"
repo-url = "https://github.com/JanisErdmanis/Documenter.jl"
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "1.3.0"

Expand Down
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
Oxygen = "df9a0d86-3283-4920-82dc-4555fc0d1d8b"

[compat]
Expand Down
710 changes: 710 additions & 0 deletions docs/assets/swagger-dark.css

Large diffs are not rendered by default.

34 changes: 32 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dirname(@__DIR__) in LOAD_PATH || Base.push!(LOAD_PATH, dirname(@__DIR__))

using Documenter
using PeaceFounder
using JSON3

function copy_if_changed(source, destination)

Expand All @@ -17,13 +18,25 @@ function copy_if_changed(source, destination)
end
end



#cp((@__DIR__) * "/../README.md", (@__DIR__) * "/src/index.md", force = true)
copy_if_changed((@__DIR__) * "/../README.md", (@__DIR__) * "/src/index.md")

Documenter.HTML(assets = [
asset("assets/swagger/[email protected]/swagger-ui-bundle.js", class=:js, islocal=true),
#asset(joinpath(@__DIR__, "src/assets/swagger/[email protected]/swagger-ui-bundle.js"), class=:js, islocal=true),
])


makedocs(
sitename = "PeaceFounder.jl",
repo = Documenter.Remotes.GitHub("PeaceFounder", "PeaceFounder.jl"),
format = Documenter.HTML(),
format = Documenter.HTML(
assets = [asset("https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.11.8/swagger-ui-bundle.js", class=:js),
asset("https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.11.8/swagger-ui.css", class=:css)]

),
modules = [PeaceFounder.Model, PeaceFounder.Client],
pages = [
"index.md",
Expand All @@ -32,14 +45,31 @@ makedocs(
"Client" => "client.md",
"Audit" => "audit.md",
"API" => [
"REST" => "schema.md",
"HTTP" => "schema.md",
"PeaceFounder.Model" => "model_api.md",
"PeaceFounder.AuditTools" => "audittools.md",
"PeaceFounder.Schedulers" => "schedulers.md"
]
],
)


# Adding a schema to assets directory after the build

SCHEMA_PATH = joinpath(@__DIR__, "build/assets/schema.json")
rm(SCHEMA_PATH, force=true)

open(SCHEMA_PATH, "w") do file
schema = PeaceFounder.Service.OxygenInstance.getschema()
JSON3.write(file, schema)
end

open(joinpath(@__DIR__, "build/assets/themes/documenter-dark.css"), "a") do file
contents = read(joinpath(@__DIR__, "assets/swagger-dark.css"))
write(file, contents)
end


# Documenter can also automatically deploy documentation to gh-pages.
# See "Hosting Documentation" and deploydocs() in the Documenter manual
# for more information.
Expand Down
829 changes: 829 additions & 0 deletions docs/src/assets/swagger-dark.css

Large diffs are not rendered by default.

30 changes: 28 additions & 2 deletions docs/src/schema.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
# REST API
# HTTP API


```@raw html
<style>
.swagger-ui .information-container {
display: none !important;
}
.swagger-ui #operations-tag-default {
display: none !important;
}
</style>
<div id="swagger-ui"></div>
<script>
window.onload = () => {
window.ui = SwaggerUIBundle({
url: window.location.origin + "/assets/schema.json",
dom_id: '#swagger-ui',
});
};
</script>
```


This is an approximate rest API for the PeaceFounder. In future, this will be properly generated and documented from the code.

```
GET /deme # returns a current manifest file
Expand Down
25 changes: 21 additions & 4 deletions src/Service.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ export serve
# GET /pollingstation/collectors # necessary to make a proposal



# I need to define @swagger


# const DOCS = []

# macro swagger_str(doc)
# m = @__MODULE__
# return esc(quote push!($m.DOCS, $doc) end)
# end

# macro swagger(doc)
# return esc(quote push!($DOCS, $doc) end)
# end



@get "/deme" function(req::Request)
return Response(200, marshal(Mapper.get_deme()))
end
Expand Down Expand Up @@ -243,12 +260,12 @@ end


# title and version are required
# info = Dict("title" => "PeaceFounder API", "version" => "0.4.0")
# openApi = OpenAPI("3.0", info)
# swagger_document = build(openApi)
info = Dict("title" => "PeaceFounder API", "version" => "0.4.0")
openApi = OpenAPI("3.0", info)
swagger_document = build(openApi)

# # merge the SwaggerMarkdown schema with the internal schema
# OxygenInstance.mergeschema(swagger_document)
OxygenInstance.mergeschema(swagger_document)


end

0 comments on commit f8e2f70

Please sign in to comment.