Skip to content

Commit 923c141

Browse files
committed
- Cleanup of templates
- Fixed File type for Node.js and Browser clients
1 parent 6b229a2 commit 923c141

34 files changed

+114
-106
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openapi-typescript-codegen",
3-
"version": "0.5.0-beta",
3+
"version": "0.5.0-rc",
44
"description": "NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification.",
55
"author": "Ferdi Koomen",
66
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",
@@ -46,8 +46,6 @@
4646
"build": "rollup --config --environment NODE_ENV:development",
4747
"build:watch": "rollup --config --environment NODE_ENV:development --watch",
4848
"release": "rollup --config --environment NODE_ENV:production",
49-
"start": "nest start --path ./test/server/tsconfig.json",
50-
"start:watch": "nest start --path ./test/server/tsconfig.json --watch",
5149
"run": "node ./test/index.js",
5250
"test": "jest --selectProjects UNIT",
5351
"test:update": "jest --selectProjects UNIT --updateSnapshot",

src/openApi/v2/parser/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export enum PrimaryType {
2-
FILE = 'any', // File or Buffer?
2+
FILE = 'File',
33
OBJECT = 'any',
4-
ARRAY = 'any',
4+
ARRAY = 'any[]',
55
BOOLEAN = 'boolean',
66
NUMBER = 'number',
77
STRING = 'string',

src/openApi/v2/parser/getMappedType.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getMappedType } from './getMappedType';
22

33
describe('getMappedType', () => {
44
it('should map types to the basics', () => {
5-
expect(getMappedType('File')).toEqual('any');
5+
expect(getMappedType('File')).toEqual('File');
66
expect(getMappedType('String')).toEqual('string');
77
expect(getMappedType('date')).toEqual('string');
88
expect(getMappedType('date-time')).toEqual('string');

src/openApi/v3/parser/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export enum PrimaryType {
2-
FILE = 'any', // File or Buffer?
2+
FILE = 'File',
33
OBJECT = 'any',
44
ARRAY = 'any[]',
55
BOOLEAN = 'boolean',

src/openApi/v3/parser/getMappedType.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getMappedType } from './getMappedType';
22

33
describe('getMappedType', () => {
44
it('should map types to the basics', () => {
5-
expect(getMappedType('File')).toEqual('any');
5+
expect(getMappedType('File')).toEqual('File');
66
expect(getMappedType('String')).toEqual('string');
77
expect(getMappedType('date')).toEqual('string');
88
expect(getMappedType('date-time')).toEqual('string');

src/templates/core/request.hbs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
{{#equals httpClient 'fetch'}}
2-
{{>fetch/request}}
3-
{{/equals}}
4-
{{#equals httpClient 'xhr'}}
5-
{{>xhr/request}}
6-
{{/equals}}
7-
{{#equals httpClient 'node'}}
8-
{{>node/request}}
9-
{{/equals}}
1+
{{#equals @root.httpClient 'fetch'}}{{>fetch/request}}{{/equals}}
2+
{{#equals @root.httpClient 'xhr'}}{{>xhr/request}}{{/equals}}
3+
{{#equals @root.httpClient 'node'}}{{>node/request}}{{/equals}}

src/templates/exportSchema.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{#if extends}}
33

44
{{#each extends}}
5-
import type { ${{{this}}} } from './${{{this}}}';
5+
import { ${{{this}}} } from './${{{this}}}';
66
{{/each}}
77
{{/if}}
88

src/templates/exportService.hbs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,45 +37,45 @@ export class {{{name}}} {
3737
const result = await __request({
3838
method: '{{{method}}}',
3939
path: `{{{path}}}`,
40-
{{#if parametersCookie~}}
40+
{{#if parametersCookie}}
4141
cookies: {
4242
{{#each parametersCookie}}
4343
'{{{prop}}}': {{{name}}},
4444
{{/each}}
4545
},
4646
{{/if}}
47-
{{#if parametersHeader~}}
47+
{{#if parametersHeader}}
4848
headers: {
4949
{{#each parametersHeader}}
5050
'{{{prop}}}': {{{name}}},
5151
{{/each}}
5252
},
5353
{{/if}}
54-
{{#if parametersQuery~}}
54+
{{#if parametersQuery}}
5555
query: {
5656
{{#each parametersQuery}}
5757
'{{{prop}}}': {{{name}}},
5858
{{/each}}
5959
},
6060
{{/if}}
61-
{{#if parametersForm~}}
61+
{{#if parametersForm}}
6262
formData: {
6363
{{#each parametersForm}}
6464
'{{{prop}}}': {{{name}}},
6565
{{/each}}
6666
},
6767
{{/if}}
68-
{{#if parametersBody~}}
68+
{{#if parametersBody}}
6969
body: {{{parametersBody.name}}},
7070
{{/if}}
71-
{{#if responseHeader~}}
71+
{{#if responseHeader}}
7272
responseHeader: '{{{responseHeader}}}',
7373
{{/if}}
74-
{{#if errors~}}
74+
{{#if errors}}
7575
errors: {
76-
{{#each errors}}
76+
{{#each errors}}
7777
{{{code}}}: `{{{description}}}`,
78-
{{/each}}
78+
{{/each}}
7979
},
8080
{{/if}}
8181
});

src/templates/partials/base.hbs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{~#equals this 'File'~}}
2+
{{~#equals @root.httpClient 'fetch'}}Blob{{/equals~}}
3+
{{~#equals @root.httpClient 'xhr'}}Blob{{/equals~}}
4+
{{~#equals @root.httpClient 'node'}}Buffer | ArrayBuffer | ArrayBufferView{{/equals~}}
5+
{{~else~}}
6+
{{this}}
7+
{{~/equals~}}

src/templates/partials/isRequired.hbs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{{#if @root.useOptions}}
2-
{{~#unless isRequired}}?{{else if default}}?{{/unless~}}
3-
{{else}}
4-
{{~#unless isRequired}}{{#unless default}}?{{/unless}}{{/unless~}}
5-
{{/if}}
1+
{{~#if @root.useOptions~}}
2+
{{#unless isRequired}}?{{else if default}}?{{/unless}}
3+
{{~else~}}
4+
{{#unless isRequired}}{{#unless default}}?{{/unless}}{{/unless}}
5+
{{~/if~}}

0 commit comments

Comments
 (0)