Skip to content

Commit 41743e8

Browse files
committed
Merge branch 'master' of https://github.com/CanoaPBC/openapi-typescript-codegen into union-bugs
2 parents 4174eb7 + 76e6851 commit 41743e8

File tree

9 files changed

+44
-18
lines changed

9 files changed

+44
-18
lines changed

.github/workflows/unittest.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,32 @@ jobs:
66
test:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
10-
- uses: actions/setup-node@v3
9+
- name: Checkout
10+
uses: actions/checkout@v4.1.1
11+
12+
- name: Setup Node environment
13+
uses: actions/setup-node@v4.0.1
1114
with:
1215
node-version: 20
16+
1317
- name: Cache Modules
14-
uses: actions/cache@v3
18+
uses: actions/cache@v4
1519
with:
1620
path: "**/node_modules"
1721
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
18-
- run: npm install
19-
- run: npm run test
22+
23+
- name: Install dependencies
24+
run: npm install
25+
26+
- name: Build library
27+
run: npm run release
28+
29+
- name: Run unit tests
30+
run: npm run test
31+
32+
# - name: Run e2e tests
33+
# run: npm run test:e2e
34+
35+
# - name: Submit to Codecov
36+
# run: npm run codecov
2037

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ $ openapi --help
4444
--useUnionTypes Use union types instead of enums
4545
--exportCore <value> Write core files to disk (default: true)
4646
--exportServices <value> Write services to disk [true, false, regexp] (default: true)
47-
--exportModels <value> Write models to disk (default: true)
47+
--exportModels <value> Write models to disk [true, false, regexp] (default: true)
4848
--exportSchemas <value> Write schemas to disk (default: false)
4949
--indent <value> Indentation options [4, 2, tab] (default: "4")
5050
--postfixServices Service name postfix (default: "Service")

bin/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ const params = program
2929

3030
const OpenAPI = require(path.resolve(__dirname, '../dist/index.js'));
3131

32-
if (OpenAPI) {
33-
let exportServices;
32+
const parseBooleanOrString = value => {
3433
try {
35-
exportServices = JSON.parse(params.exportServices) === true;
34+
return JSON.parse(value) === true;
3635
} catch (error) {
37-
exportServices = params.exportServices;
36+
return value;
3837
}
38+
};
39+
40+
if (OpenAPI) {
3941
OpenAPI.generate({
4042
input: params.input,
4143
output: params.output,
@@ -44,8 +46,8 @@ if (OpenAPI) {
4446
useOptions: params.useOptions,
4547
useUnionTypes: params.useUnionTypes,
4648
exportCore: JSON.parse(params.exportCore) === true,
47-
exportServices,
48-
exportModels: JSON.parse(params.exportModels) === true,
49+
exportServices: parseBooleanOrString(params.exportServices),
50+
exportModels: parseBooleanOrString(params.exportModels),
4951
exportSchemas: JSON.parse(params.exportSchemas) === true,
5052
indent: params.indent,
5153
postfixServices: params.postfixServices,

bin/index.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('bin', () => {
4343
expect(result.stderr.toString()).toBe('');
4444
});
4545

46-
it('it should support regexp in exportSchemas', async () => {
46+
it('it should support regexp params', async () => {
4747
const result = crossSpawn.sync('node', [
4848
'./bin/index.js',
4949
'--input',
@@ -52,6 +52,8 @@ describe('bin', () => {
5252
'./test/generated/bin',
5353
'--exportServices',
5454
'^(Simple|Types)',
55+
'--exportModels',
56+
'^(Simple|Types)',
5557
]);
5658
expect(result.stdout.toString()).toBe('');
5759
expect(result.stderr.toString()).toBe('');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@canoapbc/openapi-typescript-codegen",
2+
"name": "@nicolas-chaulet/openapi-typescript-codegen",
33
"version": "0.27.2",
44
"description": "Library that generates Typescript clients based on the OpenAPI specification.",
55
"author": "Ferdi Koomen",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type Options = {
2121
useUnionTypes?: boolean;
2222
exportCore?: boolean;
2323
exportServices?: boolean | string;
24-
exportModels?: boolean;
24+
exportModels?: boolean | string;
2525
exportSchemas?: boolean;
2626
indent?: Indent;
2727
postfixServices?: string;

src/utils/writeClient.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const writeClient = async (
4242
useUnionTypes: boolean,
4343
exportCore: boolean,
4444
exportServices: boolean | string,
45-
exportModels: boolean,
45+
exportModels: boolean | string,
4646
exportSchemas: boolean,
4747
indent: Indent,
4848
postfixServices: string,
@@ -65,6 +65,11 @@ export const writeClient = async (
6565
client.services = client.services.filter(service => regexp.test(service.name));
6666
}
6767

68+
if (typeof exportModels === 'string') {
69+
const regexp = new RegExp(exportModels);
70+
client.models = client.models.filter(model => regexp.test(model.name));
71+
}
72+
6873
if (exportCore) {
6974
await rmdir(outputPathCore);
7075
await mkdir(outputPathCore);

src/utils/writeClientIndex.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const writeClientIndex = async (
3030
useUnionTypes: boolean,
3131
exportCore: boolean,
3232
exportServices: boolean | string,
33-
exportModels: boolean,
33+
exportModels: boolean | string,
3434
exportSchemas: boolean,
3535
postfixServices: string,
3636
postfixModels: string,

types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type Options = {
2121
useUnionTypes?: boolean;
2222
exportCore?: boolean;
2323
exportServices?: boolean | string;
24-
exportModels?: boolean;
24+
exportModels?: boolean | string;
2525
exportSchemas?: boolean;
2626
indent?: Indent | '4' | '2' | 'tab';
2727
postfixServices?: string;

0 commit comments

Comments
 (0)