use yaml directly for displaying open api spec
This commit is contained in:
parent
53720ff740
commit
9afb63c738
9 changed files with 5 additions and 37 deletions
1
.github/workflows/coverage.yml
vendored
1
.github/workflows/coverage.yml
vendored
|
@ -101,7 +101,6 @@ jobs:
|
|||
# execution so this value is required for preventing meta tests from
|
||||
# panicking
|
||||
GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61
|
||||
OPEN_API_DOCS: 8e77345f1597e40c2e266cb4e6dee74888918a61
|
||||
CACHE_BUSTER_FILE_MAP: '{"map":{"./static/bundle/main.js":"./prod/bundle/main.1417115E59909BE0A01040A45A398ADB09D928DF89CCF038FA44B14850442096.js"},"base_dir":"./prod"}'
|
||||
COMPILED_DATE: "2021-07-21"
|
||||
|
||||
|
|
1
.github/workflows/linux.yml
vendored
1
.github/workflows/linux.yml
vendored
|
@ -95,7 +95,6 @@ jobs:
|
|||
env:
|
||||
DATABASE_URL: postgres://postgres:password@localhost:5432/postgres
|
||||
GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61 # dummy value
|
||||
OPEN_API_DOCS: 8e77345f1597e40c2e266cb4e6dee74888918a61
|
||||
COMPILED_DATE: "2021-07-21"
|
||||
|
||||
- name: Deploy to GitHub Pages
|
||||
|
|
14
Cargo.lock
generated
14
Cargo.lock
generated
|
@ -1608,12 +1608,10 @@ dependencies = [
|
|||
"sailfish",
|
||||
"serde 1.0.127",
|
||||
"serde_json",
|
||||
"serde_yaml",
|
||||
"sqlx",
|
||||
"tokio",
|
||||
"url",
|
||||
"validator",
|
||||
"yaml-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2627,18 +2625,6 @@ dependencies = [
|
|||
"serde 1.0.127",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_yaml"
|
||||
version = "0.8.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "039ba818c784248423789eec090aab9fb566c7b94d6ebbfa1814a9fd52c8afb2"
|
||||
dependencies = [
|
||||
"dtoa",
|
||||
"linked-hash-map",
|
||||
"serde 1.0.127",
|
||||
"yaml-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha-1"
|
||||
version = "0.9.7"
|
||||
|
|
|
@ -55,7 +55,6 @@ derive_more = "0.99"
|
|||
|
||||
serde = "1"
|
||||
serde_json = "1"
|
||||
serde_yaml = "0.8.17"
|
||||
|
||||
url = "2.2"
|
||||
|
||||
|
@ -85,9 +84,7 @@ openssl = { version = "0.10.29", features = ["vendored"] }
|
|||
|
||||
|
||||
[build-dependencies]
|
||||
serde_yaml = "0.8.17"
|
||||
serde_json = "1"
|
||||
yaml-rust = "0.4.5"
|
||||
cache-buster = { version = "0.2.0", git = "https://github.com/realaravinth/cache-buster" }
|
||||
mime = "0.3.16"
|
||||
sqlx = { version = "0.5.5", features = [ "runtime-actix-rustls", "postgres", "time", "offline" ] }
|
||||
|
|
7
build.rs
7
build.rs
|
@ -28,13 +28,6 @@ fn main() {
|
|||
let git_hash = String::from_utf8(output.stdout).unwrap();
|
||||
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
|
||||
|
||||
let yml = include_str!("./openapi.yaml");
|
||||
let api_json: serde_json::Value = serde_yaml::from_str(yml).unwrap();
|
||||
println!(
|
||||
"cargo:rustc-env=OPEN_API_DOCS={}",
|
||||
serde_json::to_string(&api_json).unwrap()
|
||||
);
|
||||
|
||||
let now = OffsetDateTime::now_utc().format("%y-%m-%d");
|
||||
println!("cargo:rustc-env=COMPILED_DATE={}", &now);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ pub mod routes {
|
|||
pub const fn new() -> Self {
|
||||
Docs {
|
||||
home: "/docs/",
|
||||
spec: "/docs/openapi.json",
|
||||
spec: "/docs/openapi.yaml",
|
||||
assets: "/docs/{_:.*}",
|
||||
}
|
||||
}
|
||||
|
@ -73,12 +73,13 @@ pub fn handle_embedded_file(path: &str) -> HttpResponse {
|
|||
async fn dist(path: web::Path<String>) -> impl Responder {
|
||||
handle_embedded_file(&path)
|
||||
}
|
||||
const OPEN_API_SPEC: &str = include_str!("../openapi.yaml");
|
||||
|
||||
#[my_codegen::get(path = "DOCS.spec")]
|
||||
async fn spec() -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.content_type("appilcation/json")
|
||||
.body(&*crate::OPEN_API_DOC)
|
||||
.content_type("text/yaml")
|
||||
.body(OPEN_API_SPEC)
|
||||
}
|
||||
|
||||
#[my_codegen::get(path = "&DOCS.home[0..DOCS.home.len() -1]")]
|
||||
|
|
|
@ -86,7 +86,6 @@ lazy_static! {
|
|||
|
||||
}
|
||||
|
||||
pub const OPEN_API_DOC: &str = env!("OPEN_API_DOCS");
|
||||
pub const COMPILED_DATE: &str = env!("COMPILED_DATE");
|
||||
pub const GIT_COMMIT_HASH: &str = env!("GIT_HASH");
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
|
|
@ -59,12 +59,6 @@ fn build() {
|
|||
let git_hash = String::from_utf8(output.stdout).unwrap();
|
||||
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
|
||||
|
||||
let yml = include_str!("../openapi.yaml");
|
||||
let api_json: serde_json::Value = serde_yaml::from_str(yml).unwrap();
|
||||
println!(
|
||||
"cargo:rustc-env=OPEN_API_DOCS={}",
|
||||
serde_json::to_string(&api_json).unwrap()
|
||||
);
|
||||
cache_bust();
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
window.onload = function() {
|
||||
// Begin Swagger UI call region
|
||||
const ui = SwaggerUIBundle({
|
||||
url: "/docs/openapi.json",
|
||||
url: "/docs/openapi.yaml",
|
||||
dom_id: '#swagger-ui',
|
||||
deepLinking: true,
|
||||
presets: [
|
||||
|
|
Loading…
Reference in a new issue