Skip to content

Commit

Permalink
rebase + restucture
Browse files Browse the repository at this point in the history
  • Loading branch information
archeoss committed Sep 7, 2023
1 parent d159afe commit d042ef7
Show file tree
Hide file tree
Showing 7 changed files with 4,540 additions and 66 deletions.
17 changes: 0 additions & 17 deletions .cargo/bin/gen_openapi.rs

This file was deleted.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ required-features = [ "backend" ]

[[bin]]
name = "gen-openapi"
path = ".cargo/bin/gen_openapi.rs"
path = "backend/gen_openapi.rs"
required-features = [ "swagger" ]

[build-dependencies]
Expand All @@ -51,22 +51,24 @@ tracing-subscriber = { version = "0.3", optional = true }

## General
tokio = { version = "1.0", features = [], optional = true }
color-eyre = { version = "0.6.2", optional = true }

# CLI
cli = { path = "./cli", optional = true }

# Backend Lib
backend = { path = "./backend", optional = true }

color-eyre = {version = "0.6.2", optional = true }
# OpenAPI
utoipa = { version = "3.4", features = ["yaml", "axum_extras", "chrono", "openapi_extensions"], optional = true }

[workspace]
members = [ "cli", "backend" ]

[features]
default = [ "frontend", "backend", "swagger" ]
frontend = [ "tsync" ]
swagger = [ "backend/swagger" ]
swagger = [ "backend/swagger", "utoipa" ]
backend = [ "axum", "tower", "tower-http" , "tracing", "tracing-subscriber", "tokio", "cli", "dep:backend", "color-eyre" ]

[profile.dev]
Expand Down
35 changes: 0 additions & 35 deletions api/openapi.json

This file was deleted.

6 changes: 3 additions & 3 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.0.3
info:
title: bob_management
description: Bob Management GUI
title: backend
description: 'Bob Management GUI: Backend'
contact:
name: Romanov Simeon [email protected]
license:
Expand All @@ -11,7 +11,7 @@ paths:
/:
get:
tags:
- backend
- crate
operationId: root
responses:
'200':
Expand Down
9 changes: 9 additions & 0 deletions backend/gen_openapi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::fs;
use utoipa::OpenApi;
// in ./src/gen_openapi.rs
fn main() {
let doc = backend::ApiDoc::openapi().to_pretty_json().unwrap();
let _ = fs::write("./api/openapi.json", doc);
let doc = backend::ApiDoc::openapi().to_yaml().unwrap();
let _ = fs::write("./api/openapi.yaml", doc);
}
17 changes: 9 additions & 8 deletions backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ pub async fn root() -> &'static str {
"Hello Bob!"
}

#[derive(OpenApi)]
#[openapi(
paths(root),
tags(
(name = "bob", description = "BOB management API")
)
)]
pub struct ApiDoc;
/// Generate openapi documentation for the project
#[cfg(feature = "swagger")]
pub fn openapi_doc() -> Router {
Expand All @@ -34,14 +42,7 @@ pub fn openapi_doc() -> Router {
/* Swagger-only routes */
#[cfg(debug_assertions)]
tracing::info!("Generating OpenAPI documentation...");
#[derive(OpenApi)]
#[openapi(
paths(root),
tags(
(name = "bob", description = "BOB management API")
)
)]
struct ApiDoc;

/* Mount Swagger ui */
Router::new().merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi()))
.merge(Redoc::with_url("/redoc", ApiDoc::openapi()))
Expand Down
Loading

0 comments on commit d042ef7

Please sign in to comment.