-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor rapidoc (use external script and webpack 5)
- Loading branch information
Showing
15 changed files
with
10,329 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,8 +85,8 @@ jobs: | |
target/${{ matrix.target }}/release/sctgdesk-api-server & | ||
sleep 5 | ||
curl http://127.0.0.1:21114/openapi.json > docs/openapi3.json | ||
curl http://127.0.0.1:21114/js/openapisnippet.min.js > docs/openapisnippet.min.js | ||
curl http://127.0.0.1:21114/js/openapisnippet.min.js.map > docs/openapisnippet.min.js.map | ||
curl http://127.0.0.1:21114/js/sctgdesk-server.min.js > docs/sctgdesk-server.min.js | ||
curl http://127.0.0.1:21114/js/sctgdesk-server.min.js.map > docs/sctgdesk-server.min.js.map | ||
kill $! | ||
- name: Create Rapidoc index.html | ||
|
@@ -99,44 +99,8 @@ jobs: | |
<head> | ||
<meta charset="utf-8" /> | ||
<!-- Important: rapi-doc uses utf8 charecters --> | ||
<script | ||
type="module" | ||
src="https://unpkg.com/rapidoc/dist/rapidoc-min.js" | ||
></script> | ||
<script src="openapisnippet.min.js"></script> | ||
<script> | ||
window.addEventListener('DOMContentLoaded', (event) => { | ||
const rapidocEl = document.getElementById('rapidoc'); | ||
const spec_url = "data:application/json;base64,$(base64 -w 0 docs/openapi3.json)"; | ||
const targets = ['c','javascript_fetch','go','php','rust','python','shell_curl']; | ||
fetch(spec_url) | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
if (data['host'] === undefined) { | ||
data['host'] = window.location.host; | ||
} | ||
if (data['basePath'] === undefined) { | ||
data['basePath'] = '/'; | ||
} | ||
for (let path in data.paths) { | ||
for (let method in data.paths[path]) { | ||
const snippets = OpenAPISnippets.getEndpointSnippets(data,path,method,targets); | ||
const pathItem = data.paths[path][method]; | ||
const code_samples = []; | ||
for (let snippet of snippets.snippets) { | ||
code_samples.push({ | ||
lang: snippet.id, | ||
label: snippet.title, | ||
source: snippet.content | ||
}); | ||
} | ||
pathItem['x-code-samples'] = code_samples; | ||
} | ||
} | ||
rapidocEl.loadSpec(data); | ||
}); | ||
}); | ||
</script> | ||
<script>window.SPEC_URL = "data:application/json;base64,$(base64 -w 0 docs/openapi3.json)";</script> | ||
<script src="sctgdesk-server.min.js"></script> | ||
</head> | ||
<body> | ||
<rapi-doc | ||
|
@@ -177,16 +141,16 @@ jobs: | |
gh release create $TAG_NAME -t "$TAG_NAME" -n "$TAG_NAME" || true | ||
gh release upload $TAG_NAME ${{ matrix.os }}_${{ matrix.target }}_${TAG_NAME}.zip --clobber | ||
gh release upload $TAG_NAME docs/openapi3.json --clobber | ||
gh release upload $TAG_NAME docs/openapisnippet.min.js --clobber | ||
gh release upload $TAG_NAME docs/openapisnippet.min.js.map --clobber | ||
gh release upload $TAG_NAME docs/sctgdesk-server.min.js --clobber | ||
gh release upload $TAG_NAME docs/sctgdesk-server.min.js.map --clobber | ||
gh release upload $TAG_NAME docs/index.html --clobber | ||
- name: Commit and push to GitHub | ||
continue-on-error: true | ||
run: | | ||
git config --global user.name 'github-actions' | ||
git config --global user.email '[email protected]' | ||
git add -v -f docs/openapi3.json docs/index.html docs/openapisnippet.min.js docs/openapisnippet.min.js.map | ||
git add -v -f docs/openapi3.json docs/index.html docs/sctgdesk-server.min.js docs/sctgdesk-server.min.js.map | ||
git commit -m "Update GitHub Pages" docs/* | ||
git push origin HEAD | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* sctgdesk-server | ||
* Copyright (c) 2024 - Ronan LE MEILLAT | ||
* Licensed under Affero GPL v3 | ||
*/ | ||
import { OpenAPISnippets } from '@sctg/openapi-snippet'; | ||
import type { paths, components } from 'openapi3'; | ||
|
||
import 'rapidoc'; | ||
type OpenAPI3 = { | ||
openapi: string; | ||
info: { | ||
title: string; | ||
version: string; | ||
}; | ||
paths: paths; | ||
components: components; | ||
host?: string; | ||
basePath?: string; | ||
} | ||
|
||
window.addEventListener('DOMContentLoaded', (event) => { | ||
const rapidocEl = document.getElementById('rapidoc') as any; | ||
const spec_url = (window as any).SPEC_URL; | ||
const targets = ['c', 'javascript_fetch', 'go', 'php', 'rust', 'python', 'shell_curl']; | ||
fetch(spec_url) | ||
.then((res) => res.json() as Promise<OpenAPI3>) | ||
.then((data) => { | ||
if (data['host'] === undefined) { | ||
data['host'] = window.location.host; | ||
} | ||
if (data['basePath'] === undefined) { | ||
data['basePath'] = '/'; | ||
} | ||
for (let path in data.paths) { | ||
for (let method in data.paths[path as keyof paths]) { | ||
const snippets = OpenAPISnippets.getEndpointSnippets(data, path, method, targets); | ||
const currentPath = data.paths[path as keyof paths]; | ||
const pathItem = currentPath[method as keyof typeof currentPath]; | ||
const code_samples = []; | ||
for (let snippet of snippets.snippets) { | ||
code_samples.push({ | ||
lang: snippet.id, | ||
label: snippet.title, | ||
source: snippet.content | ||
}); | ||
} | ||
if (pathItem !== undefined && pathItem['x-code-samples' as keyof typeof pathItem] === undefined) { | ||
(pathItem as any)['x-code-samples'] = code_samples; | ||
} | ||
} | ||
} | ||
rapidocEl?.loadSpec(data); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module '@sctg/openapi-snippet'; |
Oops, something went wrong.