From a11f528227925be325b3fa8154038c2275d93fc3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 07:58:47 +0000 Subject: [PATCH 1/5] Initial plan From 7e062541dff794f5a5583af43e7ecf82a24459b2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 08:04:06 +0000 Subject: [PATCH 2/5] =?UTF-8?q?Add=20WebAssembly=20browser=20build=20and?= =?UTF-8?q?=20static=20web=20UI=20for=20OpenAPI=203.0=20=E2=86=92=20Swagge?= =?UTF-8?q?r=202.0=20conversion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: c6-dev <31777460+c6-dev@users.noreply.github.com> --- README.md | 6 + code/Converter.cpp | 13 ++- code/Converter.h | 2 + wasm/CMakeLists.txt | 38 ++++++ wasm/README.md | 63 ++++++++++ wasm/index.html | 279 ++++++++++++++++++++++++++++++++++++++++++++ wasm/wasm_entry.cpp | 12 ++ 7 files changed, 411 insertions(+), 2 deletions(-) create mode 100644 wasm/CMakeLists.txt create mode 100644 wasm/README.md create mode 100644 wasm/index.html create mode 100644 wasm/wasm_entry.cpp diff --git a/README.md b/README.md index 0cde4d7..47e2257 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,9 @@ Loosely based on [api-spec-converter](https://github.com/LucyBot-Inc/api-spec-co Uses [yaml-cpp](https://github.com/jbeder/yaml-cpp). Built using Visual Studio 2022. + +### Web Version + +A browser-based version is available that runs the conversion entirely client-side via WebAssembly (no server required). It can be hosted on GitHub Pages or any static file host. + +See [`wasm/README.md`](wasm/README.md) for build instructions. diff --git a/code/Converter.cpp b/code/Converter.cpp index fb0327c..af563af 100644 --- a/code/Converter.cpp +++ b/code/Converter.cpp @@ -530,8 +530,7 @@ void Converter::ConvertSecurityDefinitions() { input["components"].remove("securitySchemes"); } -std::string Converter::Convert(const std::string& source) { - input = YAML::LoadFile(source); +std::string Converter::RunConversion() { if (input["components"]) { components = YAML::Clone(input["components"]); } @@ -567,4 +566,14 @@ std::string Converter::Convert(const std::string& source) { std::string str = "swagger: \"2.0\"\n"; str += out.c_str(); return str; +} + +std::string Converter::Convert(const std::string& source) { + input = YAML::LoadFile(source); + return RunConversion(); +} + +std::string Converter::ConvertString(const std::string& yamlContent) { + input = YAML::Load(yamlContent); + return RunConversion(); } \ No newline at end of file diff --git a/code/Converter.h b/code/Converter.h index c539e35..06e1f84 100644 --- a/code/Converter.h +++ b/code/Converter.h @@ -7,7 +7,9 @@ class Converter { public: std::string Convert(const std::string& source); + std::string ConvertString(const std::string& yamlContent); private: + std::string RunConversion(); YAML::Node input; YAML::Node components; void ConvertInfos(); diff --git a/wasm/CMakeLists.txt b/wasm/CMakeLists.txt new file mode 100644 index 0000000..61ace02 --- /dev/null +++ b/wasm/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.15) +project(openapi-downgrader-wasm) + +include(FetchContent) + +FetchContent_Declare( + yaml-cpp + GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git + GIT_TAG 0.8.0 +) +set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "" FORCE) +set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "" FORCE) +set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(yaml-cpp) + +add_executable(downgrader + ../code/Converter.cpp + ../code/Util.cpp + wasm_entry.cpp +) + +target_include_directories(downgrader PRIVATE ../include) +target_link_libraries(downgrader PRIVATE yaml-cpp) + +set_target_properties(downgrader PROPERTIES + OUTPUT_NAME "downgrader" + SUFFIX ".js" +) + +target_link_options(downgrader PRIVATE + --bind + -O2 + -sWASM=1 + -sALLOW_MEMORY_GROWTH=1 + -sMODULARIZE=1 + -sEXPORT_NAME=createModule + -sENVIRONMENT=web +) diff --git a/wasm/README.md b/wasm/README.md new file mode 100644 index 0000000..60c2adf --- /dev/null +++ b/wasm/README.md @@ -0,0 +1,63 @@ +# openapi-downgrader — WebAssembly / Browser Build + +This directory contains everything needed to build and run the OpenAPI 3.0 → Swagger 2.0 converter **entirely in the browser** using WebAssembly (Emscripten). + +## Prerequisites + +- [Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html) (`emcc`/`em++` on your PATH) +- CMake >= 3.15 +- Git (used by CMake `FetchContent` to download yaml-cpp) +- Python 3 (for the local dev server) + +### Install Emscripten SDK + +```bash +git clone https://github.com/emscripten-core/emsdk.git +cd emsdk +./emsdk install latest +./emsdk activate latest +source ./emsdk_env.sh # add to your shell profile for persistence +``` + +## Build + +Run the following commands from the **repository root**: + +```bash +mkdir build-wasm +cd build-wasm +emcmake cmake ../wasm +cmake --build . -- -j$(nproc) +``` + +This will produce `downgrader.js` and `downgrader.wasm` in the `build-wasm/` directory. + +After a successful build, copy (or symlink) those two files next to `wasm/index.html`: + +```bash +cp build-wasm/downgrader.js wasm/ +cp build-wasm/downgrader.wasm wasm/ +``` + +## Serve locally + +Browsers require a proper HTTP server to load `.wasm` files (the `file://` protocol does not work): + +```bash +cd wasm +python3 -m http.server 8080 +``` + +Then open in your browser. + +## GitHub Pages hosting + +1. After building, commit `wasm/index.html`, `wasm/downgrader.js`, and `wasm/downgrader.wasm` to your repository. +2. Enable **GitHub Pages** in the repository settings, pointing at the branch/folder that contains the `wasm/` directory (or move the files to `docs/`). +3. GitHub Pages serves static files with the correct MIME types for `.wasm`, so no extra configuration is needed. + +## Notes + +- yaml-cpp is fetched automatically by CMake `FetchContent` during configure — no manual download required. +- The prebuilt `.lib` files in `lib/` are Windows-only and are **not** used by the Wasm build. +- The conversion runs 100 % client-side; no data is sent to any server. diff --git a/wasm/index.html b/wasm/index.html new file mode 100644 index 0000000..f56f698 --- /dev/null +++ b/wasm/index.html @@ -0,0 +1,279 @@ + + + + + + OpenAPI 3.0 → Swagger 2.0 Converter + + + + +
+

OpenAPI 3.0 → Swagger 2.0 Converter

+

Conversion runs entirely in your browser — no data is uploaded anywhere.

+
+ +
⏳ Loading WebAssembly module…
+ + +
+ +
+ +
+ + +
+ +
+ +
+
+ + +
+ + +
+ + +
+
+
+ + + + + diff --git a/wasm/wasm_entry.cpp b/wasm/wasm_entry.cpp new file mode 100644 index 0000000..bb52f46 --- /dev/null +++ b/wasm/wasm_entry.cpp @@ -0,0 +1,12 @@ +#include "../code/Converter.h" +#include +#include + +std::string convert(std::string yamlInput) { + Converter converter; + return converter.ConvertString(yamlInput); +} + +EMSCRIPTEN_BINDINGS(openapi_downgrader) { + emscripten::function("convert", &convert); +} From c8d5db5ab400ae0f03278c69c9d5f93b1e6bd251 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 08:13:24 +0000 Subject: [PATCH 3/5] Add GitHub Actions workflow to build the WebAssembly version Co-authored-by: c6-dev <31777460+c6-dev@users.noreply.github.com> --- .github/workflows/build-wasm.yml | 75 ++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .github/workflows/build-wasm.yml diff --git a/.github/workflows/build-wasm.yml b/.github/workflows/build-wasm.yml new file mode 100644 index 0000000..1ea6602 --- /dev/null +++ b/.github/workflows/build-wasm.yml @@ -0,0 +1,75 @@ +name: Build WebAssembly + +on: + push: + branches: [main, master] + paths: + - 'code/**' + - 'wasm/**' + pull_request: + paths: + - 'code/**' + - 'wasm/**' + +permissions: + contents: read + +jobs: + build: + name: Build Wasm + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Emscripten SDK + uses: mymindstorm/setup-emsdk@v14 + + - name: Configure (emcmake cmake) + run: emcmake cmake -S wasm -B build-wasm + + - name: Build + run: cmake --build build-wasm -j$(nproc) + + - name: Prepare distribution files + run: | + mkdir -p dist + cp wasm/index.html dist/ + cp build-wasm/downgrader.js dist/ + cp build-wasm/downgrader.wasm dist/ + + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: wasm-dist + path: dist/ + if-no-files-found: error + + deploy: + name: Deploy to GitHub Pages + needs: build + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') + runs-on: ubuntu-latest + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + steps: + - name: Download build artifact + uses: actions/download-artifact@v4 + with: + name: wasm-dist + path: dist/ + + - name: Upload Pages artifact + uses: actions/upload-pages-artifact@v3 + with: + path: dist/ + + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 From c1eb5ad0a50c5b7d191dc3747733e90dcc38f277 Mon Sep 17 00:00:00 2001 From: c6 <31777460+c6-dev@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:57:34 +0400 Subject: [PATCH 4/5] Rename header include from converter.h to Converter.h --- code/Converter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/Converter.cpp b/code/Converter.cpp index af563af..a250cd5 100644 --- a/code/Converter.cpp +++ b/code/Converter.cpp @@ -1,4 +1,4 @@ -#include "converter.h" +#include "Converter.h" #include "Util.h" #include #include @@ -576,4 +576,4 @@ std::string Converter::Convert(const std::string& source) { std::string Converter::ConvertString(const std::string& yamlContent) { input = YAML::Load(yamlContent); return RunConversion(); -} \ No newline at end of file +} From 9ae8bac7af67faaeed66710cb8d8bcfafbf8dd2a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 10:09:11 +0000 Subject: [PATCH 5/5] Fix panel height misalignment in index.html Co-authored-by: c6-dev <31777460+c6-dev@users.noreply.github.com> --- wasm/index.html | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/wasm/index.html b/wasm/index.html index f56f698..69cd927 100644 --- a/wasm/index.html +++ b/wasm/index.html @@ -76,7 +76,15 @@ gap: 0.6rem; } - .panel label { + .panel-header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 0.5rem; + min-height: calc(0.85rem * 1.2 + 1rem); /* matches button height (padding + line-height) */ + } + + .panel-header label { font-weight: 600; font-size: 0.9rem; } @@ -152,8 +160,8 @@

OpenAPI 3.0 → Swagger 2.0 Converter

- -
+
+
@@ -165,7 +173,9 @@

OpenAPI 3.0 → Swagger 2.0 Converter

- +
+ +