From c4260dc8826d74303edbf610f62c4b0fce8ae919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thea=20Sch=C3=B6bl?= Date: Tue, 27 Jun 2023 11:14:28 +0200 Subject: [PATCH] feat: add openapi gen to core --- frontend/app/package.json | 4 +-- package.json | 2 +- packages/api-cli/package.json | 2 +- packages/api-cli/src/e2e.ts | 6 ++--- packages/api-cli/turbo.json | 9 ------- packages/core-tools/package.json | 3 +-- packages/core-tools/src/app.ts | 25 +------------------ packages/core-tools/src/routes.ts | 7 +----- packages/core/package.json | 3 ++- packages/easy-ast/src/easy-ast.ts | 2 +- .../easy-ast/src/types/lightweight-project.ts | 2 +- 11 files changed, 14 insertions(+), 51 deletions(-) delete mode 100644 packages/api-cli/turbo.json diff --git a/frontend/app/package.json b/frontend/app/package.json index 84d571e8..fc164a12 100644 --- a/frontend/app/package.json +++ b/frontend/app/package.json @@ -14,10 +14,10 @@ ], "scripts": { "analyze": "webpack-bundle-analyzer www/stats.json", - "build:prod": "ng build --configuration=production", + "build": "ng build", "build:analyze": "npm run build:stats && npm run analyze", "build:android": "ionic capacitor build android --no-open && cd android && ./gradlew clean assembleDebug && cd ..", - "build": "ng build", + "build:prod": "ng build --configuration=production", "build:stats": "ng build --configuration=production --stats-json", "changelog": "conventional-changelog -p angular -i src/assets/about/CHANGELOG.md -s -r 0", "check-icons": "ts-node scripts/check-icon-correctness.ts", diff --git a/package.json b/package.json index 47907187..1a2c1ccf 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,8 @@ "syncpack": "syncpack list-mismatches && syncpack lint-semver-ranges", "syncpack:fix": "syncpack format && syncpack fix-mismatches", "test": "trap 'node coverage.mjs' EXIT && dotenv -c -- turbo run test --filter=!@openstapps/app", - "test:skip": "dotenv -c -- turbo-ignore --task='test' --filter=!@openstapps/app", "test:integration": "dotenv -c -- turbo run test:integration", + "test:skip": "dotenv -c -- turbo-ignore --task='test' --filter=!@openstapps/app", "turboify-pipeline": "node deploy.mjs backend,api-cli,database && pnpm build:full && pnpm test && pnpm run docs" }, "devDependencies": { diff --git a/packages/api-cli/package.json b/packages/api-cli/package.json index 4ec79abd..47e09fe3 100644 --- a/packages/api-cli/package.json +++ b/packages/api-cli/package.json @@ -42,8 +42,8 @@ "@types/cli-progress": "3.11.0", "@types/express": "4.17.17", "@types/fs-extra": "9.0.13", - "@types/junit-report-builder": "3.0.0", "@types/json-schema": "7.0.11", + "@types/junit-report-builder": "3.0.0", "@types/mocha": "10.0.1", "@types/node": "18.15.3", "@types/wait-on": "5.3.1", diff --git a/packages/api-cli/src/e2e.ts b/packages/api-cli/src/e2e.ts index 734d06d7..ba29e2bd 100644 --- a/packages/api-cli/src/e2e.ts +++ b/packages/api-cli/src/e2e.ts @@ -114,9 +114,9 @@ async function retrieveItems(api: ConnectorClient, suite: junit.TestSuite, error type: 'value', }, }; - for (const uid of localItemMap.keys()) { + for (const {uid, type} of localItemMap.values()) { await runTest( - `Should find ${uid}`, + `Should find ${type} (${uid})`, async () => { singleItemSearchRequest.filter!.arguments.value = uid; const searchResponse = await api.search(singleItemSearchRequest); @@ -139,7 +139,7 @@ async function retrieveItems(api: ConnectorClient, suite: junit.TestSuite, error async function compareItems(suite: junit.TestSuite, errors: string[]) { for (const localThing of localItemMap.values()) { await runTest( - `Should be the same for ${localThing.uid}`, + `Should be the same for ${localThing.type} (${localThing.uid})`, async () => { /* istanbul ignore next retrieveItems will throw before*/ if (!remoteItemMap.has(localThing.uid)) { diff --git a/packages/api-cli/turbo.json b/packages/api-cli/turbo.json deleted file mode 100644 index b5ceabf6..00000000 --- a/packages/api-cli/turbo.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": ["//"], - "pipeline": { - "deploy": { - "dependsOn": ["@openstapps/api-cli#build"], - "outputs": [".deploy/api-cli"] - } - } -} diff --git a/packages/core-tools/package.json b/packages/core-tools/package.json index f4c4887a..8ec9d305 100644 --- a/packages/core-tools/package.json +++ b/packages/core-tools/package.json @@ -103,7 +103,6 @@ ] }, "eslintIgnore": [ - "resources", - "openapi" + "resources" ] } diff --git a/packages/core-tools/src/app.ts b/packages/core-tools/src/app.ts index 526da6a3..15f242e6 100644 --- a/packages/core-tools/src/app.ts +++ b/packages/core-tools/src/app.ts @@ -15,7 +15,6 @@ import {Logger} from '@openstapps/logger'; import {Command} from 'commander'; import {existsSync, readFileSync, writeFileSync} from 'fs'; -import {copy} from 'fs-extra'; import path from 'path'; import {lightweightDefinitionsFromPath, lightweightProjectFromPath} from '@openstapps/easy-ast'; import {openapi3Template} from './resources/openapi-303-template.js'; @@ -57,7 +56,7 @@ commander // get absolute paths const sourcePath = path.resolve(relativeSourceBundlePath); const outDirectoryPath = path.resolve(relativeOutDirectoryPath); - const outDirectorySchemasPath = path.join(outDirectoryPath, 'schemas'); + const outDirectorySchemasPath = path.join(outDirectoryPath, 'schema'); // get information about routes const routes = await gatherRouteInformation(sourcePath); @@ -82,9 +81,6 @@ commander // initialize json output const output = openapi3Template; - // names of the schemas to copy - const schemasToCopy: string[] = []; - // generate documentation for all routes for (const routeWithMetaInformation of routes) { routeWithMetaInformation.tags = [capitalize(routeWithMetaInformation.route.urlPath.split('/')[1])]; @@ -92,29 +88,10 @@ commander output.paths[routeWithMetaInformation.route.urlPath] = generateOpenAPIForRoute( routeWithMetaInformation, path.relative(relativeOutDirectoryPath, outDirectorySchemasPath), - schemasToCopy, tagsToKeep, ); } - // copy schema json schema files - try { - if (!existsSync(outDirectorySchemasPath)) { - await mkdir(outDirectorySchemasPath, { - recursive: true, - }); - } - for (const fileName of schemasToCopy) { - await copy( - path.join(sourcePath, 'schema', `${fileName}.json`), - path.join(outDirectorySchemasPath, `${fileName}.json`), - ); - } - } catch (error) { - await Logger.error(error); - process.exit(-2); - } - // write openapi object to file (prettified) writeFileSync(path.join(outDirectoryPath, 'openapi.json'), JSON.stringify(output, undefined, 2)); diff --git a/packages/core-tools/src/routes.ts b/packages/core-tools/src/routes.ts index 8c622451..40be6b98 100644 --- a/packages/core-tools/src/routes.ts +++ b/packages/core-tools/src/routes.ts @@ -79,20 +79,16 @@ export async function gatherRouteInformation(path: string): Promise { return Object.fromEntries( - Object.values(project).flatMap((definitions, file) => + Object.entries(project).flatMap(([file, definitions]) => Object.keys(definitions).map(definition => [definition, file.toString()]), ), );