mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-04 19:56:30 +00:00
Merge pull request #5823 from meilisearch/ci-open-api
Add CI to publish OpenAPI file
This commit is contained in:
12
crates/openapi-generator/Cargo.toml
Normal file
12
crates/openapi-generator/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "openapi-generator"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
meilisearch = { path = "../meilisearch" }
|
||||
serde_json = "1.0"
|
||||
clap = { version = "4.5.40", features = ["derive"] }
|
||||
anyhow = "1.0.98"
|
||||
utoipa = "5.4.0"
|
43
crates/openapi-generator/src/main.rs
Normal file
43
crates/openapi-generator/src/main.rs
Normal file
@ -0,0 +1,43 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use meilisearch::routes::MeilisearchApi;
|
||||
use utoipa::OpenApi;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "openapi-generator")]
|
||||
#[command(about = "Generate OpenAPI specification for Meilisearch")]
|
||||
struct Cli {
|
||||
/// Output file path (default: meilisearch.json)
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
output: Option<PathBuf>,
|
||||
|
||||
/// Pretty print the JSON output
|
||||
#[arg(short, long)]
|
||||
pretty: bool,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
// Generate the OpenAPI specification
|
||||
let openapi = MeilisearchApi::openapi();
|
||||
|
||||
// Determine output path
|
||||
let output_path = cli.output.unwrap_or_else(|| PathBuf::from("meilisearch.json"));
|
||||
|
||||
// Serialize to JSON
|
||||
let json = if cli.pretty {
|
||||
serde_json::to_string_pretty(&openapi)?
|
||||
} else {
|
||||
serde_json::to_string(&openapi)?
|
||||
};
|
||||
|
||||
// Write to file
|
||||
std::fs::write(&output_path, json)?;
|
||||
|
||||
println!("OpenAPI specification written to: {}", output_path.display());
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user