Skip to content

Commit

Permalink
refactor(nms): Make TypeScript generation script executable and fix P…
Browse files Browse the repository at this point in the history
…ackageType usage

Signed-off-by: Thomas Schmitt <thomas.schmitt@tngtech.com>
  • Loading branch information
thmsschmitt committed May 18, 2022
1 parent ee21d21 commit b602119
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions nms/app/views/equipment/GatewayDetailConfigEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import type {
apn_resources,
challenge_key,
distribution_package,
enodeb_serials,
gateway_device,
gateway_dns_configs,
Expand All @@ -25,7 +26,6 @@ import type {
gateway_ran_configs,
lte_gateway,
magmad_gateway_configs,
package_type,
} from '../../../generated/MagmaAPIBindings';

import Accordion from '@material-ui/core/Accordion';
Expand Down Expand Up @@ -344,7 +344,7 @@ type Props = {
onSave: lte_gateway => void,
};

type VersionType = $PropertyType<package_type, 'version'>;
type VersionType = $PropertyType<distribution_package, 'version'>;

export function ConfigEdit(props: Props) {
const enqueueSnackbar = useEnqueueSnackbar();
Expand Down
27 changes: 17 additions & 10 deletions nms/scripts/generateAPIFromSwaggerForTypeScript.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# limitations under the License.
################################################################################

set -e
set -euo pipefail

USAGE="generateAPIFromSwaggerForTypeScript.sh
— generates TypeScript NMS API bindings for swagger spec
Expand All @@ -35,9 +35,14 @@ OUTPUT=${2}
echo "Input file: $INPUT";
echo "Output directory: $OUTPUT";

yarn --silent openapi -i "${INPUT}" -o "${OUTPUT}"
(set -x;
yarn --silent openapi --client axios --useUnionTypes -i "${INPUT}" -o "${OUTPUT}")

HEADER='/**
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
Expand All @@ -52,12 +57,14 @@ HEADER='/**
* @generated
* This file is generated by "nms/scripts/generateAPIFromSwaggerForTypeScript.sh".
*/
'
$(cat "${file}")
EOF
mv "${TEMPORARY_FILE}" "${file}"
}

# shellcheck disable=SC2044
for file in $(find "${OUTPUT}" -type f); do
TEMPORARY_FILE=$(mktemp)
(echo "${HEADER}"; cat "${file}") > "${TEMPORARY_FILE}" && mv "${TEMPORARY_FILE}" "${file}"
sed -i -e 's/?view=full(/_view_full(/g' "${file}"
sed -i -e 's/?verbose=false(/_verbose_false(/g' "${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
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func NewDefaultGatewayStatus(hardwareID string) *GatewayStatus {
},
PlatformInfo: &PlatformInfo{
VpnIP: "facebook.com",
Packages: []*Package{
Packages: []*DistributionPackage{
{
Name: "magma",
Version: "0.0.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ magma-gen-meta:
filename: machine_info_swaggergen.go
- go-struct-name: NetworkInterface
filename: network_interface_swaggergen.go
- go-struct-name: Package
- go-struct-name: DistributionPackage
filename: distribution_package_swaggergen.go
- go-struct-name: PlatformInfo
filename: platform_info_swaggergen.go
Expand Down

0 comments on commit b602119

Please sign in to comment.