From 0881810780c0398645f1d09b7b2b603f1068ee05 Mon Sep 17 00:00:00 2001 From: curquiza Date: Mon, 11 Aug 2025 18:09:54 +0200 Subject: [PATCH] Add CI to publish OpenAPI file --- ...inaries.yml => publish-release-assets.yml} | 30 ++++++++++++- .gitignore | 3 ++ Cargo.lock | 11 +++++ Cargo.toml | 1 + crates/openapi-generator/Cargo.toml | 12 ++++++ crates/openapi-generator/src/main.rs | 42 +++++++++++++++++++ 6 files changed, 98 insertions(+), 1 deletion(-) rename .github/workflows/{publish-binaries.yml => publish-release-assets.yml} (87%) create mode 100644 crates/openapi-generator/Cargo.toml create mode 100644 crates/openapi-generator/src/main.rs diff --git a/.github/workflows/publish-binaries.yml b/.github/workflows/publish-release-assets.yml similarity index 87% rename from .github/workflows/publish-binaries.yml rename to .github/workflows/publish-release-assets.yml index 27d8c3610..204480887 100644 --- a/.github/workflows/publish-binaries.yml +++ b/.github/workflows/publish-release-assets.yml @@ -1,4 +1,4 @@ -name: Publish binaries to GitHub release +name: Publish assets to GitHub release on: workflow_dispatch: @@ -184,3 +184,31 @@ jobs: file: target/${{ matrix.target }}/release/meilisearch asset_name: ${{ matrix.asset_name }} tag: ${{ github.ref }} + + publish-openapi: + name: Publish OpenAPI file + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Generate OpenAPI specification + run: | + cd crates/openapi-generator + cargo run --release -- --pretty --output ../../meilisearch.json + + - name: Upload OpenAPI to Release + # No need to upload for dry run (cron) + if: github.event_name == 'release' + uses: svenstaro/upload-release-action@2.11.2 + with: + repo_token: ${{ secrets.MEILI_BOT_GH_PAT }} + file: ./meilisearch.json + asset_name: meilisearch-openapi.json + tag: ${{ github.ref }} diff --git a/.gitignore b/.gitignore index 44cfa8f75..d9a945b88 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,6 @@ crates/meilisearch/db.snapshot # Fuzzcheck data for the facet indexing fuzz test crates/milli/fuzz/update::facet::incremental::fuzz::fuzz/ + +# OpenAPI +meilisearch.json diff --git a/Cargo.lock b/Cargo.lock index 6894e4856..061cefb3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4338,6 +4338,17 @@ version = "11.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" +[[package]] +name = "openapi-generator" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "meilisearch", + "serde_json", + "utoipa", +] + [[package]] name = "openssl-probe" version = "0.1.6" diff --git a/Cargo.toml b/Cargo.toml index 1fa86c671..dd2747c5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ members = [ "crates/tracing-trace", "crates/xtask", "crates/build-info", + "crates/openapi-generator", ] [workspace.package] diff --git a/crates/openapi-generator/Cargo.toml b/crates/openapi-generator/Cargo.toml new file mode 100644 index 000000000..87c41625e --- /dev/null +++ b/crates/openapi-generator/Cargo.toml @@ -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" \ No newline at end of file diff --git a/crates/openapi-generator/src/main.rs b/crates/openapi-generator/src/main.rs new file mode 100644 index 000000000..5630a6fea --- /dev/null +++ b/crates/openapi-generator/src/main.rs @@ -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, + + /// 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(()) +}