Skip to content

Commit

Permalink
chore(deps): migrate from openapi to openapi-ts (#1464)
Browse files Browse the repository at this point in the history
* chore(deps): migrate from openapi to openapi-ts

Signed-off-by: Paul Schultz <[email protected]>

* fix test cases

Signed-off-by: Paul Schultz <[email protected]>

* update dist-dynamic

Signed-off-by: Paul Schultz <[email protected]>

---------

Signed-off-by: Paul Schultz <[email protected]>
  • Loading branch information
schultzp2020 authored Apr 9, 2024
1 parent 67757fd commit 0ccdeef
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 100 deletions.
4 changes: 2 additions & 2 deletions plugins/nexus-repository-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build": "backstage-cli package build",
"clean": "backstage-cli package clean",
"export-dynamic": "janus-cli package export-dynamic-plugin",
"generate": "openapi --input ./nexus-swagger.json --output ./src/generated --useUnionTypes --useOptions",
"generate": "openapi-ts --input ./nexus-swagger.json --output ./src/generated",
"lint": "backstage-cli package lint",
"postpack": "backstage-cli package postpack",
"postversion": "yarn run export-dynamic",
Expand Down Expand Up @@ -54,7 +54,7 @@
"@types/node": "18.18.5",
"cross-fetch": "4.0.0",
"msw": "1.3.2",
"openapi-typescript-codegen": "0.25.0",
"@hey-api/openapi-ts": "0.34.5",
"react": "18.2.0",
"react-dom": "18.2.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export const useNexusRepositoryManagerAppData = ({

acc.repositories.push(repository);
const query = v.query
? Object.assign(acc.query, v.query(repository), { sort: 'version' })
? Object.assign(acc.query ?? {}, v.query(repository), {
sort: 'version',
})
: acc.query;

return {
Expand Down
2 changes: 1 addition & 1 deletion plugins/servicenow-actions/dist-dynamic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"scripts": {},
"dependencies": {
"abort-controller": "^3.0.0",
"axios": "^1.6.8",
"form-data": "^4.0.0",
"node-fetch": "^2.7.0",
"yaml": "^2.3.3",
"zod": "^3.22.4"
},
Expand Down
42 changes: 18 additions & 24 deletions plugins/servicenow-actions/dist-dynamic/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ asynckit@^0.4.0:
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==

axios@^1.6.8:
version "1.6.8"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66"
integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

combined-stream@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
Expand All @@ -54,6 +63,11 @@ event-target-shim@^5.0.0:
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789"
integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==

follow-redirects@^1.15.6:
version "1.15.6"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b"
integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==

form-data@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
Expand All @@ -75,36 +89,16 @@ mime-types@^2.1.12:
dependencies:
mime-db "1.52.0"

node-fetch@^2.7.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
dependencies:
whatwg-url "^5.0.0"

tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

tslib@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"

yaml@^2.3.3:
version "2.4.1"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.4.1.tgz#2e57e0b5e995292c25c75d2658f0664765210eed"
Expand Down
6 changes: 3 additions & 3 deletions plugins/servicenow-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"@backstage/backend-plugin-api": "^0.6.16",
"@backstage/plugin-scaffolder-node": "^0.4.2",
"abort-controller": "^3.0.0",
"axios": "^1.6.8",
"form-data": "^4.0.0",
"node-fetch": "^2.7.0",
"yaml": "^2.3.3",
"zod": "^3.22.4"
},
Expand All @@ -58,10 +58,10 @@
"@backstage/config": "1.2.0",
"@backstage/plugin-scaffolder-node-test-utils": "0.1.2",
"@backstage/types": "1.1.1",
"@hey-api/openapi-ts": "0.34.5",
"@janus-idp/cli": "1.7.10",
"@types/node-fetch": "2.6.6",
"msw": "1.3.2",
"openapi-typescript-codegen": "0.25.0"
"msw": "1.3.2"
},
"files": [
"dist",
Expand Down
16 changes: 2 additions & 14 deletions plugins/servicenow-actions/scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,7 @@ for file in $(find openapi -name '*.json'); do
if [[ $file =~ openapi\/(.*).json ]]
then
name=${BASH_REMATCH[1]}
yarn openapi --input "./$file" --output "./src/generated/$name" --useUnionTypes --useOptions -c node
# We must use axios over node-fetch because openapi-ts only supports node-fetch v3
openapi-ts --input "./$file" --output "./src/generated/$name" -c axios
fi
done

echo "Patching generated code"

# FIXME: remove once https://github.com/ferdikoomen/openapi-typescript-codegen/issues/1751 is fixed
# This is a workaround for https://github.com/ferdikoomen/openapi-typescript-codegen/pull/1627
# iterate through the generated directory
for file in $(find src/generated -name '*.ts'); do
echo "Patching $file"

# remove function optional chainging from the generated code
POSIXLY_CORRECT=1 sed -i.bak 's/\(this\.\#[[:alnum:]]*\)?\.(\(.*\))/if(\1) \1(\2)/g' $file
rm $file.bak
done
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,17 @@ export const createRecordAction = (

let res: ServiceNowResponses['201'];
try {
res = (await DefaultService.postApiNowTable({
res = (await DefaultService.postApiNowTableByTableName({
...input,
// convert the array of fields to a comma-separated string
sysparmFields: input.sysparmFields?.join(','),
})) as ServiceNowResponses['201'];
} catch (error) {
throw new Error((error as ApiError).body.error.message);
const e = error as ApiError & {
body?: { error?: { message?: string } };
};

throw new Error(e.body?.error?.message);
}

ctx.output('result', res.result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ export const deleteRecordAction = (
updateOpenAPIConfig(OpenAPI, config);

try {
await DefaultService.deleteApiNowTable(input);
await DefaultService.deleteApiNowTableByTableNameBySysId(input);
} catch (error) {
throw new Error((error as ApiError).body.error.message);
const e = error as ApiError & {
body?: { error?: { message?: string } };
};

throw new Error(e.body?.error?.message);
}
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,16 @@ export const modifyRecordAction = (

let res: ServiceNowResponses['200'];
try {
res = (await DefaultService.putApiNowTable({
res = (await DefaultService.putApiNowTableByTableNameBySysId({
...input,
sysparmFields: input.sysparmFields?.join(','),
})) as ServiceNowResponses['200'];
} catch (error) {
throw new Error((error as ApiError).body.error.message);
const e = error as ApiError & {
body?: { error?: { message?: string } };
};

throw new Error(e.body?.error?.message);
}

ctx.output('result', res?.result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,16 @@ export const retrieveRecordAction = (

let res: ServiceNowResponses['200'];
try {
res = (await DefaultService.getApiNowTable1({
res = (await DefaultService.getApiNowTableByTableNameBySysId({
...input,
sysparmFields: input.sysparmFields?.join(','),
})) as ServiceNowResponses['200'];
} catch (error) {
throw new Error((error as ApiError).body.error.message);
const e = error as ApiError & {
body?: { error?: { message?: string } };
};

throw new Error(e.body?.error?.message);
}

ctx.output('result', res?.result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,16 @@ export const retrieveRecordsAction = (

let res: ServiceNowResponses['200'];
try {
res = (await DefaultService.getApiNowTable({
res = (await DefaultService.getApiNowTableByTableName({
...input,
sysparmFields: input.sysparmFields?.join(','),
})) as ServiceNowResponses['200'];
} catch (error) {
throw new Error((error as ApiError).body.error.message);
const e = error as ApiError & {
body?: { error?: { message?: string } };
};

throw new Error(e.body?.error?.message);
}

ctx.output('result', res?.result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,16 @@ export const updateRecordAction = (

let res: ServiceNowResponses['200'];
try {
res = (await DefaultService.patchApiNowTable({
res = (await DefaultService.patchApiNowTableByTableNameBySysId({
...input,
sysparmFields: input.sysparmFields?.join(','),
})) as ServiceNowResponses['200'];
} catch (error) {
throw new Error((error as ApiError).body.error.message);
const e = error as ApiError & {
body?: { error?: { message?: string } };
};

throw new Error(e.body?.error?.message);
}

ctx.output('result', res?.result);
Expand Down
Loading

0 comments on commit 0ccdeef

Please sign in to comment.