From d931001ac02caecbe64516cac0037b01c5ca509a Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Thu, 12 Jan 2023 03:28:50 +0800 Subject: [PATCH] feat: add openapi viewer (#1094) * all * all * fix tests * fix tests * fix tests * fix tests * fix tests * fix tests * fix tests * fix tests * fix typecheck * fix tests * fix tests * fix tests * all --- .github/workflows/backend-test.yml | 2 +- Dockerfile | 5 +++++ backend/.gitignore | 1 + backend/windmill-api/build_openapi.sh | 9 +++++++++ backend/windmill-api/openapi-deref.yaml | 0 backend/windmill-api/openapi.yaml | 7 +++++-- backend/windmill-api/src/lib.rs | 2 +- frontend/static/openapi.html | 19 +++++++++++++++++++ 8 files changed, 41 insertions(+), 4 deletions(-) create mode 100755 backend/windmill-api/build_openapi.sh create mode 100644 backend/windmill-api/openapi-deref.yaml create mode 100644 frontend/static/openapi.html diff --git a/.github/workflows/backend-test.yml b/.github/workflows/backend-test.yml index 6c680738b5..7b89d6aaa5 100644 --- a/.github/workflows/backend-test.yml +++ b/.github/workflows/backend-test.yml @@ -40,4 +40,4 @@ jobs: backend -> target - name: cargo test timeout-minutes: 10 - run: mkdir frontend/build && cd backend && DATABASE_URL=postgres://postgres:changeme@postgres:5432/windmill cargo test --all -- --nocapture + run: mkdir frontend/build && cd backend && touch windmill-api/openapi-deref.yaml && DATABASE_URL=postgres://postgres:changeme@postgres:5432/windmill cargo test --all -- --nocapture diff --git a/Dockerfile b/Dockerfile index 82d5cae55b..0d6af9b2e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,12 +51,16 @@ COPY frontend . RUN mkdir /backend COPY /backend/windmill-api/openapi.yaml /backend/windmill-api/openapi.yaml COPY /openflow.openapi.yaml /openflow.openapi.yaml +COPY /backend/windmill-api/build_openapi.sh /backend/windmill-api/build_openapi.sh +RUN cd /backend/windmill-api && . ./build_openapi.sh + RUN npm run generate-backend-client ENV NODE_OPTIONS "--max-old-space-size=8192" RUN npm run build RUN npm run check + FROM rust_base AS planner COPY ./openflow.openapi.yaml /openflow.openapi.yaml @@ -75,6 +79,7 @@ COPY ./openflow.openapi.yaml /openflow.openapi.yaml COPY ./backend ./ COPY --from=frontend /frontend /frontend +COPY --from=frontend /backend/windmill-api/openapi-deref.yaml /backend/windmill-api/openapi-deref.yaml COPY .git/ .git/ RUN CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release --features "$features" diff --git a/backend/.gitignore b/backend/.gitignore index 582bd08f2c..b72cefe4b9 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1,3 +1,4 @@ target/ .env oauth.json +windmill-api/openapi-deref.yaml \ No newline at end of file diff --git a/backend/windmill-api/build_openapi.sh b/backend/windmill-api/build_openapi.sh new file mode 100755 index 0000000000..9d0bfa712c --- /dev/null +++ b/backend/windmill-api/build_openapi.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +npx @redocly/openapi-cli@latest bundle openapi.yaml > openapi-bundled.yaml + + +npx @redocly/openapi-cli@latest bundle openapi-bundled.yaml --ext yaml -d > openapi-deref.yaml + +rm openapi-bundled.yaml diff --git a/backend/windmill-api/openapi-deref.yaml b/backend/windmill-api/openapi-deref.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index ca6ab3235e..ab2ebaec19 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -2,9 +2,10 @@ openapi: "3.0.3" info: version: 1.60.0 - title: Windmill server API + title: Windmill API + contact: - name: Windmill contact + name: Windmill Team email: contact@windmill.dev url: https://windmill.dev @@ -12,6 +13,8 @@ info: name: Apache 2.0 url: https://www.apache.org/licenses/LICENSE-2.0.html + x-logo: + url: https://docs.windmill.dev/img/windmill.svg externalDocs: description: documentation portal url: https://docs.windmill.dev diff --git a/backend/windmill-api/src/lib.rs b/backend/windmill-api/src/lib.rs index 21fe631525..06c0511ba8 100644 --- a/backend/windmill-api/src/lib.rs +++ b/backend/windmill-api/src/lib.rs @@ -186,7 +186,7 @@ async fn git_v() -> &'static str { } async fn openapi() -> &'static str { - include_str!("../openapi.yaml") + include_str!("../openapi-deref.yaml") } pub async fn migrate_db(db: &DB) -> anyhow::Result<()> { db::migrate(db).await?; diff --git a/frontend/static/openapi.html b/frontend/static/openapi.html new file mode 100644 index 0000000000..a78630534b --- /dev/null +++ b/frontend/static/openapi.html @@ -0,0 +1,19 @@ + + + + + + Windmill API Explorer + + + + + + + + + \ No newline at end of file