From 0881810780c0398645f1d09b7b2b603f1068ee05 Mon Sep 17 00:00:00 2001 From: curquiza Date: Mon, 11 Aug 2025 18:09:54 +0200 Subject: [PATCH 1/7] 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(()) +} From 3c583ce7a4f23d86aa8748bfa930c9cdffa45368 Mon Sep 17 00:00:00 2001 From: curquiza Date: Mon, 11 Aug 2025 18:10:39 +0200 Subject: [PATCH 2/7] Fix linting --- crates/openapi-generator/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/openapi-generator/Cargo.toml b/crates/openapi-generator/Cargo.toml index 87c41625e..652f6fc57 100644 --- a/crates/openapi-generator/Cargo.toml +++ b/crates/openapi-generator/Cargo.toml @@ -9,4 +9,4 @@ 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 +utoipa = "5.4.0" From 100a6f96e45f737e273860fab8e7a15134576de4 Mon Sep 17 00:00:00 2001 From: curquiza Date: Mon, 11 Aug 2025 18:11:23 +0200 Subject: [PATCH 3/7] Minor change --- .github/workflows/publish-release-assets.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-release-assets.yml b/.github/workflows/publish-release-assets.yml index 204480887..f9db0c91b 100644 --- a/.github/workflows/publish-release-assets.yml +++ b/.github/workflows/publish-release-assets.yml @@ -185,7 +185,7 @@ jobs: asset_name: ${{ matrix.asset_name }} tag: ${{ github.ref }} - publish-openapi: + publish-openapi-file: name: Publish OpenAPI file runs-on: ubuntu-latest steps: From c5b325de30efa1ce3d9d3e784af362d1c45781d3 Mon Sep 17 00:00:00 2001 From: curquiza Date: Mon, 11 Aug 2025 18:15:42 +0200 Subject: [PATCH 4/7] Fix rustfmt --- crates/openapi-generator/src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/openapi-generator/src/main.rs b/crates/openapi-generator/src/main.rs index 5630a6fea..a6196f771 100644 --- a/crates/openapi-generator/src/main.rs +++ b/crates/openapi-generator/src/main.rs @@ -1,8 +1,9 @@ +use std::path::PathBuf; + use anyhow::Result; use clap::Parser; use meilisearch::routes::MeilisearchApi; use utoipa::OpenApi; -use std::path::PathBuf; #[derive(Parser)] #[command(name = "openapi-generator")] From a69af611e30565f53f35a78f08d6986f4fe11615 Mon Sep 17 00:00:00 2001 From: curquiza Date: Mon, 11 Aug 2025 18:29:52 +0200 Subject: [PATCH 5/7] Add documentation --- .gitignore | 3 --- CONTRIBUTING.md | 12 +++++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index d9a945b88..44cfa8f75 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,3 @@ 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/CONTRIBUTING.md b/CONTRIBUTING.md index 72a91a765..7f718c899 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -107,12 +107,18 @@ Run `cargo xtask --help` from the root of the repository to find out what is ava To update the openAPI file in the code, see [sprint_issue.md](https://github.com/meilisearch/meilisearch/blob/main/.github/ISSUE_TEMPLATE/sprint_issue.md#reminders-when-modifying-the-api). -If you want to update the openAPI file on the [open-api repository](https://github.com/meilisearch/open-api): -- Pull the latest version of the latest rc of Meilisearch `git checkout release-vX.Y.Z; git pull` +If you want to generate OpenAPI file manually: + +With swagger: - Starts Meilisearch with the `swagger` feature flag: `cargo run --features swagger` - On a browser, open the following URL: http://localhost:7700/scalar - Click the « Download openAPI file » -- Open a PR replacing [this file](https://github.com/meilisearch/open-api/blob/main/open-api.json) with the one downloaded + +With the internal crate: +```bash +cd crates/openapi-generator +cargo run --release -- --pretty --output meilisearch.json +``` ### Logging From 3c84010403607a63e149ebd67d0c2d67c6e5ddb1 Mon Sep 17 00:00:00 2001 From: curquiza Date: Mon, 11 Aug 2025 18:31:30 +0200 Subject: [PATCH 6/7] Minor change in CI manifest --- .github/workflows/publish-release-assets.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/publish-release-assets.yml b/.github/workflows/publish-release-assets.yml index f9db0c91b..cb70b23fc 100644 --- a/.github/workflows/publish-release-assets.yml +++ b/.github/workflows/publish-release-assets.yml @@ -191,18 +191,15 @@ jobs: 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 + - name: Generate OpenAPI file 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' From 14b1a3300bb3a94fd55e9b5031ddcec2772a172e Mon Sep 17 00:00:00 2001 From: curquiza Date: Tue, 12 Aug 2025 10:07:34 +0200 Subject: [PATCH 7/7] Fix indentation --- .github/workflows/publish-release-assets.yml | 48 ++++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/publish-release-assets.yml b/.github/workflows/publish-release-assets.yml index cb70b23fc..ec0d36711 100644 --- a/.github/workflows/publish-release-assets.yml +++ b/.github/workflows/publish-release-assets.yml @@ -185,27 +185,27 @@ jobs: asset_name: ${{ matrix.asset_name }} tag: ${{ github.ref }} - publish-openapi-file: - 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 file - 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 }} + publish-openapi-file: + 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 file + 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 }}