Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy committed Nov 10, 2023
1 parent 69a0541 commit c9ea650
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
13 changes: 9 additions & 4 deletions catalyst-gateway/bin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(crate) enum Error {
pub(crate) enum Cli {
/// Run the service
Run(ServiceSettings),
/// Build API docs of the service
/// Build API docs of the service in the JSON format
Docs(DocsSettings),
}

Expand All @@ -53,9 +53,14 @@ impl Cli {
Ok(())
},
Self::Docs(settings) => {
let docs = service::get_app_docs(&settings.format);
let mut docs_file = std::fs::File::create(settings.output)?;
docs_file.write_all(docs.as_bytes())?;
let docs = service::get_app_docs();
match settings.output {
Some(path) => {
let mut docs_file = std::fs::File::create(path)?;
docs_file.write_all(docs.as_bytes())?;
},
None => println!("{docs}"),
}
Ok(())
},
}
Expand Down
1 change: 0 additions & 1 deletion catalyst-gateway/bin/src/service/docs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ where
.nest("/rapidoc", rapidoc_ui)
.nest("/openapi_explorer", openapi_explorer)
.at("/cat-gateway.json", api_service.spec_endpoint())
.at("/cat-gateway.yml", api_service.spec_endpoint_yaml())
}

/// Embed static files.
Expand Down
11 changes: 4 additions & 7 deletions catalyst-gateway/bin/src/service/poem_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
},
Error,
},
settings::{get_api_host_names, DocsFormat, API_URL_PREFIX},
settings::{get_api_host_names, API_URL_PREFIX},
state::State,
};

Expand Down Expand Up @@ -55,13 +55,10 @@ fn mk_app(hosts: Vec<String>, base_route: Option<Route>, state: &Arc<State>) ->
.data(state.clone())
}

/// Get the API docs as a string in the specified format.
pub(crate) fn get_app_docs(format: &DocsFormat) -> String {
/// Get the API docs as a string in the JSON format.
pub(crate) fn get_app_docs() -> String {
let api_service = mk_api(vec![]);
match format {
DocsFormat::Json => api_service.spec(),
DocsFormat::Yml => api_service.spec_yaml(),
}
api_service.spec()
}

/// Run the Poem Service
Expand Down
13 changes: 3 additions & 10 deletions catalyst-gateway/bin/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ const API_HOST_NAMES_DEFAULT: &str = "https://api.prod.projectcatalyst.io";
/// Default `API_URL_PREFIX` used in development.
const API_URL_PREFIX_DEFAULT: &str = "/api";

/// Default docs format to be generated.
const DEFAULT_DOCS_FORMAT: &str = "yml";

/// Settings for the application.
///
/// This struct represents the configuration settings for the application.
Expand Down Expand Up @@ -68,15 +65,11 @@ pub(crate) enum DocsFormat {
Yml,
}

/// Settings specifies the format of the `OpenAPI` docs to be generated.
/// Settings specifies `OpenAPI` docs generation.
#[derive(Args, Clone)]
pub(crate) struct DocsSettings {
/// The output path to the generated docs file
pub(crate) output: PathBuf,

/// The format of the docs to be generated
#[clap(long, default_value = DEFAULT_DOCS_FORMAT)]
pub(crate) format: DocsFormat,
/// The output path to the generated docs file, if omitted prints to stdout.
pub(crate) output: Option<PathBuf>,
}

/// An environment variable read as a string.
Expand Down

0 comments on commit c9ea650

Please sign in to comment.