From a1c8a1b1b66191063bbecaafa023e874c3650330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ad=C3=A1mek?= Date: Mon, 20 Jan 2025 16:47:59 +0100 Subject: [PATCH] feat: allow downloading openapi specs in JSON --- docusaurus.config.js | 2 +- package.json | 4 +- .../docusaurus-theme-openapi-docs+4.3.1.patch | 42 ++++++++++++++++++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/docusaurus.config.js b/docusaurus.config.js index 9a24b0c4d..cd0bad273 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -194,7 +194,7 @@ module.exports = { config: { /** @type {import('docusaurus-plugin-openapi-docs').Options} */ v2: { - downloadUrl: 'apify-api.yaml', + downloadUrl: 'openapi.yaml', specPath: 'apify-api.yaml', outputDir: './sources/api', markdownGenerators: { diff --git a/package.json b/package.json index 22078f7f8..d701c5b11 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,9 @@ "api:rebuild": "npm run api:clean && npm run api:generate", "redoc:start": "redocly preview-docs", "redoc:build": "redocly bundle apify-api/openapi/openapi.yaml -o apify-api", - "redoc:build:clean": "redocly bundle apify-api/openapi/openapi.yaml --skip-decorator=apify/legacy-doc-url-decorator --skip-decorator=apify/client-references-links-decorator --skip-decorator=apify/code-samples-decorator -o static/api/apify-api.yaml", + "redoc:build:clean": "npm run redoc:build:clean:yaml && npm run redoc:build:clean:json", + "redoc:build:clean:yaml": "redocly bundle apify-api/openapi/openapi.yaml --skip-decorator=apify/legacy-doc-url-decorator --skip-decorator=apify/client-references-links-decorator --skip-decorator=apify/code-samples-decorator -o static/api/openapi.yaml", + "redoc:build:clean:json": "redocly bundle apify-api/openapi/openapi.yaml --skip-decorator=apify/legacy-doc-url-decorator --skip-decorator=apify/client-references-links-decorator --skip-decorator=apify/code-samples-decorator -o static/api/openapi.json", "redoc:test": "redocly lint && npm run redoc:build", "redoc:test2": "redocly lint && npm run redoc:build && bin/schemathesis", "write-translations": "docusaurus write-translations", diff --git a/patches/docusaurus-theme-openapi-docs+4.3.1.patch b/patches/docusaurus-theme-openapi-docs+4.3.1.patch index 3913d633e..48abc5237 100644 --- a/patches/docusaurus-theme-openapi-docs+4.3.1.patch +++ b/patches/docusaurus-theme-openapi-docs+4.3.1.patch @@ -1,8 +1,8 @@ diff --git a/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/CodeSnippets/index.js b/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/CodeSnippets/index.js -index 3d43486..b21e5d5 100644 +index 514066e..0d09eeb 100644 --- a/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/CodeSnippets/index.js +++ b/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/CodeSnippets/index.js -@@ -290,7 +290,7 @@ function CodeSnippets({ postman, codeSamples }) { +@@ -286,7 +286,7 @@ function CodeSnippets({ postman, codeSamples }) { CodeTab, { value: lang.language, @@ -11,3 +11,41 @@ index 3d43486..b21e5d5 100644 key: lang.language, attributes: { className: `openapi-tabs__code-item--${lang.logoClass}`, +diff --git a/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/Export/index.js b/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/Export/index.js +index a2a4e40..f2d944d 100644 +--- a/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/Export/index.js ++++ b/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/Export/index.js +@@ -30,7 +30,7 @@ function Export({ url, proxy }) { + react_1.default.createElement( + "button", + { className: "export-button button button--sm button--secondary" }, +- "Export" ++ "Download OpenAPI" + ), + react_1.default.createElement( + "ul", +@@ -48,7 +48,23 @@ function Export({ url, proxy }) { + className: "dropdown__link", + href: `${url}`, + }, +- "OpenAPI Spec" ++ "YAML" ++ ) ++ ), ++ react_1.default.createElement( ++ "li", ++ null, ++ react_1.default.createElement( ++ "a", ++ { ++ onClick: (e) => { ++ e.preventDefault(); ++ saveFile(`${url.replace(/\.yaml$/, '.json')}`); ++ }, ++ className: "dropdown__link", ++ href: `${url.replace(/\.yaml$/, '.json')}`, ++ }, ++ "JSON" + ) + ) + )