Skip to content

Commit 5859871

Browse files
authored
feat: allow downloading openapi specs in JSON (#1419)
<img width="272" alt="image" src="https://github.com/user-attachments/assets/2e9e9197-242c-4c46-96e9-599dfaf61f8e" />
1 parent 200254f commit 5859871

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

docusaurus.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ module.exports = {
194194
config: {
195195
/** @type {import('docusaurus-plugin-openapi-docs').Options} */
196196
v2: {
197-
downloadUrl: 'apify-api.yaml',
197+
downloadUrl: 'openapi.yaml',
198198
specPath: 'apify-api.yaml',
199199
outputDir: './sources/api',
200200
markdownGenerators: {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"api:rebuild": "npm run api:clean && npm run api:generate",
2525
"redoc:start": "redocly preview-docs",
2626
"redoc:build": "redocly bundle apify-api/openapi/openapi.yaml -o apify-api",
27-
"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",
27+
"redoc:build:clean": "npm run redoc:build:clean:yaml && npm run redoc:build:clean:json",
28+
"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",
29+
"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",
2830
"redoc:test": "redocly lint && npm run redoc:build",
2931
"redoc:test2": "redocly lint && npm run redoc:build && bin/schemathesis",
3032
"write-translations": "docusaurus write-translations",
Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
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
2-
index 3d43486..b21e5d5 100644
2+
index 514066e..0d09eeb 100644
33
--- a/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/CodeSnippets/index.js
44
+++ b/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/CodeSnippets/index.js
5-
@@ -290,7 +290,7 @@ function CodeSnippets({ postman, codeSamples }) {
5+
@@ -286,7 +286,7 @@ function CodeSnippets({ postman, codeSamples }) {
66
CodeTab,
77
{
88
value: lang.language,
@@ -11,3 +11,41 @@ index 3d43486..b21e5d5 100644
1111
key: lang.language,
1212
attributes: {
1313
className: `openapi-tabs__code-item--${lang.logoClass}`,
14+
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
15+
index a2a4e40..f2d944d 100644
16+
--- a/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/Export/index.js
17+
+++ b/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/Export/index.js
18+
@@ -30,7 +30,7 @@ function Export({ url, proxy }) {
19+
react_1.default.createElement(
20+
"button",
21+
{ className: "export-button button button--sm button--secondary" },
22+
- "Export"
23+
+ "Download OpenAPI"
24+
),
25+
react_1.default.createElement(
26+
"ul",
27+
@@ -48,7 +48,23 @@ function Export({ url, proxy }) {
28+
className: "dropdown__link",
29+
href: `${url}`,
30+
},
31+
- "OpenAPI Spec"
32+
+ "YAML"
33+
+ )
34+
+ ),
35+
+ react_1.default.createElement(
36+
+ "li",
37+
+ null,
38+
+ react_1.default.createElement(
39+
+ "a",
40+
+ {
41+
+ onClick: (e) => {
42+
+ e.preventDefault();
43+
+ saveFile(`${url.replace(/\.yaml$/, '.json')}`);
44+
+ },
45+
+ className: "dropdown__link",
46+
+ href: `${url.replace(/\.yaml$/, '.json')}`,
47+
+ },
48+
+ "JSON"
49+
)
50+
)
51+
)

0 commit comments

Comments
 (0)