mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
use yaml directly for displaying open api spec
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user