Skip to content

Commit

Permalink
APIGOV-29554 - use updated scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
dgghinea committed Feb 17, 2025
1 parent a990b8f commit 6cc5c04
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
3 changes: 2 additions & 1 deletion scripts/apiserver/apiserver_generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ cd ${cwd}
if [ -z "${PROTOCOL}" ]; then export PROTOCOL=https; fi
if [ -z "${HOST}" ]; then export HOST=apicentral.axway.com; fi
if [ -z "${PORT}" ]; then export PORT=443; fi
if [ -z "${DEBUG}" ]; then export DEBUG="false"; fi

# set the environment vars
export GO_POST_PROCESS_FILE="`command -v gofmt` -w"
export GO111MODULE=on

if node ./generate.js ${PROTOCOL} ${HOST} ${PORT}; then
if node ./generate.js ${PROTOCOL} ${HOST} ${PORT} ${DEBUG}; then
# update all go imports
goimports -w=true ${OUTDIR}

Expand Down
41 changes: 33 additions & 8 deletions scripts/apiserver/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ const https = require("https");
const http = require("http");
const fs = require("fs");
const { exit } = require("process");
const { version } = require("os");

const outDir = process.env.OUTDIR;
const clientsPath = outDir + "/clients/";
const modelsPath = outDir + "/models/";
const resourcesTmplPath = "resources.tmpl";
const clientsTmplPath = "clients.tmpl";

var isDebug = false;

function parseBool(val) { return val === true || val === "true" }

const fetch = () => {
const [, , protocol, host, port] = process.argv;
const [, , protocol, host, port, debug] = process.argv;
isDebug = parseBool(debug);
if (!protocol || !host || !port) {
throw new Error(
"Protocol, host, and port are required. Ex: node generate.js https apicentral.axway.com 443",
Expand Down Expand Up @@ -67,9 +73,11 @@ fetch()
process.exit(1);
}
const [subResources, mainResources] = createMainAndSubResources(resources);
// uncomment to see how the resources are grouped
//fs.writeFileSync(outDir + '/sub-resources.json', JSON.stringify(subResources));
//fs.writeFileSync(outDir + '/main-resources.json', JSON.stringify(mainResources));

if (isDebug) {
fs.writeFileSync(outDir + '/sub-resources.json', JSON.stringify(subResources));
fs.writeFileSync(outDir + '/main-resources.json', JSON.stringify(mainResources));
}
delete subResources.api; // the api resources are common resources, and have been written manually.
writeSubResources(subResources);
writeMainResources(mainResources);
Expand All @@ -90,9 +98,26 @@ const writeSubResources = (subResources) => {
for (let versionKey in groupObj) {
// stringify the group and version data, update all references to drop group and version within path
const data = JSON.stringify(groupObj[versionKey]).replaceAll(`components/schemas/${groupKey}.${versionKey}.`, `components/schemas/`);
const res = execSync(
`openapi-generator-cli generate -g go -i /dev/stdin --package-name ${groupKey} --output ${modelsPath}${groupKey}/${versionKey} --global-property modelDocs=false,models << 'EOF'\n${data}\nEOF`
);
const fn =`${groupKey}-${versionKey}.json`;
fs.writeFileSync(fn, data)

console.log(`generating from ${fn}`);
try {
if (isDebug) {
const res1 = execSync(`openapi-generator-cli validate -i ${fn}`);
console.log(res1.toString());
}
const res = execSync(`openapi-generator-cli generate -g go -i ${fn} --package-name ${groupKey} --output ${modelsPath}${groupKey}/${versionKey} --global-property modelDocs=false,models`);

if (isDebug) {
console.log(res.toString());
} else {
fs.unlinkSync(fn)
}
} catch (error) {
console.error(error.message)
throw error
}
}
}
};
Expand Down Expand Up @@ -283,4 +308,4 @@ const writeSet = (resources) => {
`gomplate --context input='stdin:?type=application/json' -f ./set.tmpl --out "` + outDir + `/clients/set.go"`,
{ input: setInput }
);
};
};
1 change: 0 additions & 1 deletion scripts/apiserver/modify_models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ MODELS=`find ${OUTDIR}/models -type f -name "*.go" \
! -name 'AmplifyRuntimeConfig.go' \
! -name 'AssetMapping.go' \
! -name 'DiscoveryAgent.go' \
! -name 'GovernanceAgent.go' \
! -name 'TraceabilityAgent.go'`

SEARCH="\s*Status.*\s*\`json:\"status\"\`$"
Expand Down

0 comments on commit 6cc5c04

Please sign in to comment.