mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 11:06:50 +08:00
feat(openapi): automatically generate OpenAPI spec from code (#318)
Co-authored-by: bernard eugine <bernard.eugine@bernard.eugine-MacBookPro> Co-authored-by: Sanchith Hegde <sanchith.hegde@juspay.in>
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
use router::{
|
||||
configs::settings::{CmdLineConf, Settings},
|
||||
configs::settings::{CmdLineConf, Settings, Subcommand},
|
||||
core::errors::{BachError, BachResult},
|
||||
logger,
|
||||
};
|
||||
@ -10,6 +10,20 @@ async fn main() -> BachResult<()> {
|
||||
// get commandline config before initializing config
|
||||
let cmd_line = CmdLineConf::from_args();
|
||||
|
||||
if let Some(Subcommand::GenerateOpenapiSpec) = cmd_line.subcommand {
|
||||
let file_path = "openapi/generated.json";
|
||||
#[allow(clippy::expect_used)]
|
||||
std::fs::write(
|
||||
file_path,
|
||||
<router::openapi::ApiDoc as utoipa::OpenApi>::openapi()
|
||||
.to_pretty_json()
|
||||
.expect("Failed to generate serialize OpenAPI specification as JSON"),
|
||||
)
|
||||
.expect("Failed to write OpenAPI specification to file");
|
||||
println!("Successfully saved OpenAPI specification file at '{file_path}'");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
#[allow(clippy::expect_used)]
|
||||
let conf = Settings::with_config_path(cmd_line.config_path)
|
||||
.expect("Unable to construct application configuration");
|
||||
|
||||
Reference in New Issue
Block a user