From d12d999f7090422687a46f6e71cf664f1ee264e5 Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 29 Jan 2024 16:01:00 +0000 Subject: [PATCH 1/3] test(ci): match steps from CircleCI --- .github/workflows/unittest.yml | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 5b78eb8c3..88d0fde35 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -6,15 +6,32 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - name: Checkout + uses: actions/checkout@v4.1.1 + + - name: Setup Node environment + uses: actions/setup-node@v4.0.1 with: node-version: 20 + - name: Cache Modules - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: "**/node_modules" key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }} - - run: npm install - - run: npm run test + + - name: Install dependencies + run: npm install + + - name: Build library + run: npm run release + + - name: Run unit tests + run: npm run test + + # - name: Run e2e tests + # run: npm run test:e2e + + # - name: Submit to Codecov + # run: npm run codecov From b0a2db3b3230b7dddc94e959d151c713d17d378c Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Mon, 29 Jan 2024 11:58:40 -0500 Subject: [PATCH 2/3] Change package name --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f75f4fcf8..dcd40c7a2 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@canoapbc/openapi-typescript-codegen", + "name": "@nicolas-chaulet/openapi-typescript-codegen", "version": "0.27.2", "description": "Library that generates Typescript clients based on the OpenAPI specification.", "author": "Ferdi Koomen", From 8a4fad3f0865f92200630d68f33ab12ba62c3e57 Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 30 Jan 2024 03:54:39 +0000 Subject: [PATCH 3/3] fix(client): support regexp to select models to export --- README.md | 2 +- bin/index.js | 14 ++++++++------ bin/index.spec.js | 4 +++- src/index.ts | 2 +- src/utils/writeClient.ts | 7 ++++++- src/utils/writeClientIndex.ts | 2 +- types/index.d.ts | 2 +- 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 63f268332..b0d3ad873 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ $ openapi --help --useUnionTypes Use union types instead of enums --exportCore Write core files to disk (default: true) --exportServices Write services to disk [true, false, regexp] (default: true) - --exportModels Write models to disk (default: true) + --exportModels Write models to disk [true, false, regexp] (default: true) --exportSchemas Write schemas to disk (default: false) --indent Indentation options [4, 2, tab] (default: "4") --postfixServices Service name postfix (default: "Service") diff --git a/bin/index.js b/bin/index.js index edb7879f1..36664e351 100755 --- a/bin/index.js +++ b/bin/index.js @@ -29,13 +29,15 @@ const params = program const OpenAPI = require(path.resolve(__dirname, '../dist/index.js')); -if (OpenAPI) { - let exportServices; +const parseBooleanOrString = value => { try { - exportServices = JSON.parse(params.exportServices) === true; + return JSON.parse(value) === true; } catch (error) { - exportServices = params.exportServices; + return value; } +}; + +if (OpenAPI) { OpenAPI.generate({ input: params.input, output: params.output, @@ -44,8 +46,8 @@ if (OpenAPI) { useOptions: params.useOptions, useUnionTypes: params.useUnionTypes, exportCore: JSON.parse(params.exportCore) === true, - exportServices, - exportModels: JSON.parse(params.exportModels) === true, + exportServices: parseBooleanOrString(params.exportServices), + exportModels: parseBooleanOrString(params.exportModels), exportSchemas: JSON.parse(params.exportSchemas) === true, indent: params.indent, postfixServices: params.postfixServices, diff --git a/bin/index.spec.js b/bin/index.spec.js index e9dadabef..ff1cff75a 100755 --- a/bin/index.spec.js +++ b/bin/index.spec.js @@ -43,7 +43,7 @@ describe('bin', () => { expect(result.stderr.toString()).toBe(''); }); - it('it should support regexp in exportSchemas', async () => { + it('it should support regexp params', async () => { const result = crossSpawn.sync('node', [ './bin/index.js', '--input', @@ -52,6 +52,8 @@ describe('bin', () => { './test/generated/bin', '--exportServices', '^(Simple|Types)', + '--exportModels', + '^(Simple|Types)', ]); expect(result.stdout.toString()).toBe(''); expect(result.stderr.toString()).toBe(''); diff --git a/src/index.ts b/src/index.ts index 3763ed67d..749a2cfb2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,7 +21,7 @@ export type Options = { useUnionTypes?: boolean; exportCore?: boolean; exportServices?: boolean | string; - exportModels?: boolean; + exportModels?: boolean | string; exportSchemas?: boolean; indent?: Indent; postfixServices?: string; diff --git a/src/utils/writeClient.ts b/src/utils/writeClient.ts index 2f55b0e05..6cc491ecd 100644 --- a/src/utils/writeClient.ts +++ b/src/utils/writeClient.ts @@ -42,7 +42,7 @@ export const writeClient = async ( useUnionTypes: boolean, exportCore: boolean, exportServices: boolean | string, - exportModels: boolean, + exportModels: boolean | string, exportSchemas: boolean, indent: Indent, postfixServices: string, @@ -65,6 +65,11 @@ export const writeClient = async ( client.services = client.services.filter(service => regexp.test(service.name)); } + if (typeof exportModels === 'string') { + const regexp = new RegExp(exportModels); + client.models = client.models.filter(model => regexp.test(model.name)); + } + if (exportCore) { await rmdir(outputPathCore); await mkdir(outputPathCore); diff --git a/src/utils/writeClientIndex.ts b/src/utils/writeClientIndex.ts index 72723c0f1..5f0ced589 100644 --- a/src/utils/writeClientIndex.ts +++ b/src/utils/writeClientIndex.ts @@ -30,7 +30,7 @@ export const writeClientIndex = async ( useUnionTypes: boolean, exportCore: boolean, exportServices: boolean | string, - exportModels: boolean, + exportModels: boolean | string, exportSchemas: boolean, postfixServices: string, postfixModels: string, diff --git a/types/index.d.ts b/types/index.d.ts index f347d74bc..127ec7af9 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -21,7 +21,7 @@ export type Options = { useUnionTypes?: boolean; exportCore?: boolean; exportServices?: boolean | string; - exportModels?: boolean; + exportModels?: boolean | string; exportSchemas?: boolean; indent?: Indent | '4' | '2' | 'tab'; postfixServices?: string;