forked from magma/magma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nms): generate swagger api for typescript (magma#12757)
* feat(nms): generate swagger api for typescript Signed-off-by: Fritz Lehnert <13189449+Neudrino@users.noreply.github.com> * feat(nms): rename package in swagger api Signed-off-by: Fritz Lehnert <13189449+Neudrino@users.noreply.github.com> * feat(nms): auto-generated files from swagger Signed-off-by: Fritz Lehnert <13189449+Neudrino@users.noreply.github.com> * refactor(nms): Make TypeScript generation script executable and fix PackageType usage Signed-off-by: Thomas Schmitt <thomas.schmitt@tngtech.com> Co-authored-by: Thomas Schmitt <thomas.schmitt@tngtech.com>
- Loading branch information
Showing
9 changed files
with
128 additions
and
33 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
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env bash | ||
################################################################################ | ||
# Copyright 2022 The Magma Authors. | ||
|
||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
################################################################################ | ||
|
||
set -euo pipefail | ||
|
||
usage() { | ||
cat <<EOF | ||
generateAPIFromSwaggerForTypeScript.sh | ||
— generates TypeScript NMS API bindings for swagger spec | ||
Usage: | ||
generateAPIFromSwaggerForTypeScript.sh [-f] <input> <output> | ||
Options: | ||
-i swagger.yml file | ||
-o Output directory for ts bindings | ||
-f Overwrite files without confirmation | ||
<input> Input swagger.yml file to read. | ||
<output> Output directory for js bindings. | ||
EOF | ||
exit 2 | ||
} | ||
|
||
FORCE=false | ||
INPUT="" | ||
OUTPUT="" | ||
while getopts 'hfi:o:' option; do | ||
case "$option" in | ||
f) FORCE=true ;; | ||
i) INPUT="${OPTARG}" ;; | ||
o) OUTPUT="${OPTARG}" ;; | ||
h | *) usage ;; | ||
esac | ||
done | ||
|
||
[[ -z "${INPUT}" ]] || [[ -z "${OUTPUT}" ]] && usage | ||
|
||
if [ "$FORCE" = false ] && [ -d "${OUTPUT}" ] ; then | ||
read -r -p "Are you sure you want to overwrite all files in ${OUTPUT} (y/N)? " REPLY | ||
if [[ ! $REPLY =~ ^[Yy]$ ]] | ||
then | ||
exit 1 | ||
fi | ||
fi | ||
|
||
(set -x; | ||
yarn --silent openapi --client axios --useUnionTypes -i "${INPUT}" -o "${OUTPUT}") | ||
|
||
addHeader() { | ||
local file="$1" | ||
TEMPORARY_FILE=$(mktemp) | ||
cat <<EOF > "${TEMPORARY_FILE}" | ||
/** | ||
* Copyright 2022 The Magma Authors. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* @generated | ||
* This file is generated by "nms/scripts/generateAPIFromSwaggerForTypeScript.sh". | ||
*/ | ||
$(cat "${file}") | ||
EOF | ||
mv "${TEMPORARY_FILE}" "${file}" | ||
} | ||
|
||
for file in "${OUTPUT}"/*.ts "${OUTPUT}"/**/*.ts; do | ||
addHeader "${file}" | ||
# TODO #12768 remove sed replacements | ||
sed -i 's/?view=full(/_view_full(/g' "${file}" | ||
sed -i 's/?verbose=false(/_verbose_false(/g' "${file}" | ||
done |
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
20 changes: 10 additions & 10 deletions
20
...tor/obsidian/models/package_swaggergen.go → ...models/distribution_package_swaggergen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
orc8r/cloud/go/services/orchestrator/obsidian/models/platform_info_swaggergen.go
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