Merge pull request #5823 from meilisearch/ci-open-api

Add CI to publish OpenAPI file
This commit is contained in:
Tamo
2025-08-12 12:38:05 +00:00
committed by GitHub
6 changed files with 102 additions and 4 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,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(())
}