Add CI to publish OpenAPI file

This commit is contained in:
curquiza
2025-08-11 18:09:54 +02:00
parent 33bc86d71a
commit 0881810780
6 changed files with 98 additions and 1 deletions

View 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"

View File

@ -0,0 +1,42 @@
use anyhow::Result;
use clap::Parser;
use meilisearch::routes::MeilisearchApi;
use utoipa::OpenApi;
use std::path::PathBuf;
#[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(())
}