-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(type-safe-api): support documentation generation for websocket apis
Convert the OpenAPI spec to AsyncAPI, and use AsyncAPI's documentation generators for html and markdown documentation Fixes #742
- Loading branch information
Showing
32 changed files
with
21,916 additions
and
14,709 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -30,6 +30,9 @@ install_packages() { | |
[email protected] \ | ||
[email protected] \ | ||
@redocly/[email protected] \ | ||
@asyncapi/[email protected] \ | ||
@asyncapi/[email protected] \ | ||
@asyncapi/[email protected] \ | ||
[email protected] \ | ||
@faker-js/[email protected] \ | ||
@openapitools/[email protected] \ | ||
|
@@ -40,6 +43,22 @@ install_packages() { | |
[email protected] | ||
} | ||
|
||
## | ||
# runs an install command to install the given packages | ||
run_install_command() { | ||
cmd="$@" | ||
|
||
if [ "$pkg_manager" == "pnpm" ]; then | ||
runner="$pkg_manager install --reporter=default" | ||
else | ||
runner="$pkg_manager install" | ||
fi | ||
|
||
log "running command $runner $cmd" | ||
|
||
$runner $cmd | ||
} | ||
|
||
## | ||
# installs the passed packages with the package manager in use | ||
_install_packages() { | ||
|
@@ -59,6 +78,8 @@ _install_packages() { | |
|
||
# The .committed file contains the identifier of the directory already installed to | ||
_install_dir_identifier=$(cat $_install_packages_committed_file) | ||
|
||
log "packages already installed to :: $_install_packages_pdk_base_dir/$_install_dir_identifier" | ||
fi | ||
|
||
_install_packages_pdk_dir="$_install_packages_pdk_base_dir/$_install_dir_identifier" | ||
|
@@ -69,11 +90,7 @@ _install_packages() { | |
# Install if any packages are missing | ||
if [ "$_install_packages_should_install" == "true" ]; then | ||
npm init --yes | ||
if [ "$pkg_manager" == "pnpm" ]; then | ||
$pkg_manager install --reporter=default "$@" | ||
else | ||
$pkg_manager install "$@" | ||
fi | ||
run_install_command "$@" | ||
fi | ||
|
||
# Mark that we have installed the dependencies (if there's a race and we installed multiple times, | ||
|
44 changes: 44 additions & 0 deletions
44
packages/type-safe-api/scripts/type-safe-api/custom/docs/asyncapi-html
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,44 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Parse arguments | ||
spec_path='' | ||
output_path='' | ||
while [[ "$#" -gt 0 ]]; do case $1 in | ||
--spec-path) spec_path="$2"; shift;; | ||
--output-path) output_path="$2"; shift;; | ||
esac; shift; done | ||
|
||
echo "Generating AsyncAPI HTML documentation..." | ||
|
||
working_dir=$(pwd) | ||
script_dir="$( cd -- "$(dirname $([ -L "${BASH_SOURCE[0]:-$0}" ] && readlink -f "${BASH_SOURCE[0]:-$0}" || echo "${BASH_SOURCE[0]:-$0}"))" >/dev/null 2>&1 ; pwd -P )"; | ||
|
||
# load common package manager helper functions | ||
. "$script_dir/../../common/common.sh" | ||
|
||
# Create a temporary directory | ||
tmp_dir=$(mktemp -d "${TMPDIR:-/tmp/}generate-docs-async-api-html.XXXXXXXXX") | ||
cd $tmp_dir | ||
|
||
log "async-api-html :: tmp_dir :: $tmp_dir" | ||
|
||
# Install dependencies | ||
install_packages | ||
|
||
# Generate | ||
run_command asyncapi generate fromTemplate "$working_dir/$spec_path" @asyncapi/[email protected] \ | ||
--param singleFile=true \ | ||
--param outFilename=index.html \ | ||
--force-write | ||
|
||
# Copy html docs to output path | ||
rm -f $working_dir/$output_path/index.html | ||
cp index.html $working_dir/$output_path/index.html | ||
|
||
echo "AsyncAPI HTML documentation generation done!" | ||
|
||
# Clean up | ||
cd $working_dir | ||
rm -rf $tmp_dir |
43 changes: 43 additions & 0 deletions
43
packages/type-safe-api/scripts/type-safe-api/custom/docs/asyncapi-markdown
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,43 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Parse arguments | ||
spec_path='' | ||
output_path='' | ||
while [[ "$#" -gt 0 ]]; do case $1 in | ||
--spec-path) spec_path="$2"; shift;; | ||
--output-path) output_path="$2"; shift;; | ||
esac; shift; done | ||
|
||
echo "Generating AsyncAPI Markdown documentation..." | ||
|
||
working_dir=$(pwd) | ||
script_dir="$( cd -- "$(dirname $([ -L "${BASH_SOURCE[0]:-$0}" ] && readlink -f "${BASH_SOURCE[0]:-$0}" || echo "${BASH_SOURCE[0]:-$0}"))" >/dev/null 2>&1 ; pwd -P )"; | ||
|
||
# load common package manager helper functions | ||
. "$script_dir/../../common/common.sh" | ||
|
||
# Create a temporary directory | ||
tmp_dir=$(mktemp -d "${TMPDIR:-/tmp/}generate-docs-async-api-markdown.XXXXXXXXX") | ||
cd $tmp_dir | ||
|
||
log "async-api-markdown :: tmp_dir :: $tmp_dir" | ||
|
||
# Install dependencies | ||
install_packages | ||
|
||
# Generate | ||
run_command asyncapi generate fromTemplate "$working_dir/$spec_path" @asyncapi/[email protected] \ | ||
--param outFilename=index.md \ | ||
--force-write | ||
|
||
# Copy markdown docs to output path | ||
rm -f $working_dir/$output_path/index.md | ||
cp index.md $working_dir/$output_path/index.md | ||
|
||
echo "AsyncAPI Markdown documentation generation done!" | ||
|
||
# Clean up | ||
cd $working_dir | ||
rm -rf $tmp_dir |
40 changes: 40 additions & 0 deletions
40
.../type-safe-api/scripts/type-safe-api/custom/generate-asyncapi-spec/generate-asyncapi-spec
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,40 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Parse arguments | ||
spec_path='' | ||
output_path='' | ||
while [[ "$#" -gt 0 ]]; do case $1 in | ||
--spec-path) spec_path="$2"; shift;; | ||
--output-path) output_path="$2"; shift;; | ||
esac; shift; done | ||
|
||
working_dir=$(pwd) | ||
script_dir="$( cd -- "$(dirname $([ -L "${BASH_SOURCE[0]:-$0}" ] && readlink -f "${BASH_SOURCE[0]:-$0}" || echo "${BASH_SOURCE[0]:-$0}"))" >/dev/null 2>&1 ; pwd -P )"; | ||
|
||
# load common package manager helper functions | ||
. "$script_dir/../../common/common.sh" | ||
|
||
# Create a temporary directory | ||
tmp_dir=$(mktemp -d "${TMPDIR:-/tmp/}generate-asyncapi-spec.XXXXXXXXX") | ||
cd $tmp_dir | ||
|
||
log "generate-asyncapi-spec :: tmp_dir :: $tmp_dir" | ||
|
||
# Copy the parse script into the temp directory | ||
cp -r $script_dir/* . | ||
|
||
# Install dependencies | ||
install_packages | ||
|
||
# Run the parse script | ||
run_command ts-node generate-asyncapi-spec.ts \ | ||
--specPath="$working_dir/$spec_path" \ | ||
--outputPath="$working_dir/$output_path" | ||
|
||
log "generate-asyncapi-spec :: done" | ||
|
||
# Clean up | ||
cd $working_dir | ||
rm -rf $tmp_dir |
Oops, something went wrong.