Skip to content

Commit

Permalink
feat(client): move typeX templates to typescript generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanshatford committed Apr 7, 2024
1 parent 132d9f8 commit b536bc2
Show file tree
Hide file tree
Showing 26 changed files with 166 additions and 192 deletions.
6 changes: 1 addition & 5 deletions packages/openapi-ts/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,14 @@ export function handlebarsPlugin(): Plugin {
equals: true,
escapeComment: true,
escapeDescription: true,
escapeNewline: true,
exactArray: true,
getDefaultPrintable: true,
hasDefault: true,
ifNotNullNotUndefined: true,
ifOperationDataOptional: true,
ifdef: true,
intersection: true,
modelIsRequired: true,
modelUnionType: true,
nameOperationDataType: true,
notEquals: true,
toType: true,
useDateType: true,
},
knownHelpersOnly: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { escapeName } from '../../../utils/escapeName';
import { escapeName } from '../../../utils/escape';
import type { Model } from '../../common/interfaces/client';
import { getPattern } from '../../common/parser/getPattern';
import { getType } from '../../common/parser/type';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { escapeName } from '../../../utils/escapeName';
import { escapeName } from '../../../utils/escape';
import type { Model } from '../../common/interfaces/client';
import { getDefault } from '../../common/parser/getDefault';
import { getPattern } from '../../common/parser/getPattern';
Expand Down
9 changes: 0 additions & 9 deletions packages/openapi-ts/src/templates/partials/base.hbs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{/if}}
*/
{{/ifdef}}
export type {{{name}}} = {{>type parent=name}};
export type {{{name}}} = {{toType this @root.$config}};

{{#if enums}}
{{#each enums}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type {{{name}}} = {
{{/if}}
*/
{{/ifdef}}
{{>isReadOnly}}{{{name}}}{{{modelIsRequired this}}}: {{>type parent=../name}};
{{>isReadOnly}}{{{name}}}{{{modelIsRequired this}}}: {{toType this @root.$config}};
{{/each}}
}{{>isNullable}};

Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-ts/src/templates/partials/exportType.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
{{/if}}
*/
{{/ifdef}}
export type {{{name}}} = {{>type}};
export type {{{name}}} = {{toType this @root.$config}};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data: {{#if parameters}}{{{nameOperationDataType @root this}}} & {{/if}}TConfig<
{{#if parameters}}

{{#each parameters}}
{{{name}}}{{{modelIsRequired this}}}: {{>type}}{{#hasDefault this}} = {{{getDefaultPrintable this}}}{{/hasDefault}},
{{{name}}}{{{modelIsRequired this}}}: {{toType this @root.$config}}{{#hasDefault this}} = {{{getDefaultPrintable this}}}{{/hasDefault}},
{{/each}}
{{/if}}
{{/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{{~/notEquals~}}
{{~/if~}}
{{~#if results~}}
{{#each results}}{{>type}}{{#unless @last}} | {{/unless}}{{/each}}
{{#each results}}{{toType this @root.$config}}{{#unless @last}} | {{/unless}}{{/each}}
{{~else~}}
void
{{~/if~}}
Expand Down
19 changes: 0 additions & 19 deletions packages/openapi-ts/src/templates/partials/type.hbs

This file was deleted.

9 changes: 0 additions & 9 deletions packages/openapi-ts/src/templates/partials/typeArray.hbs

This file was deleted.

5 changes: 0 additions & 5 deletions packages/openapi-ts/src/templates/partials/typeDictionary.hbs

This file was deleted.

1 change: 0 additions & 1 deletion packages/openapi-ts/src/templates/partials/typeEnum.hbs

This file was deleted.

1 change: 0 additions & 1 deletion packages/openapi-ts/src/templates/partials/typeGeneric.hbs

This file was deleted.

23 changes: 0 additions & 23 deletions packages/openapi-ts/src/templates/partials/typeInterface.hbs

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion packages/openapi-ts/src/templates/partials/typeUnion.hbs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';

import { escapeName, unescapeName } from '../escapeName';
import { escapeName, unescapeName } from '../escape';

const toCheck: { unescaped: string; escaped: string }[] = [
{ escaped: "''", unescaped: '' },
Expand Down
5 changes: 0 additions & 5 deletions packages/openapi-ts/src/utils/__tests__/handlebars.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,11 @@ describe('registerHandlebarHelpers', () => {
expect(helpers).toContain('equals');
expect(helpers).toContain('escapeComment');
expect(helpers).toContain('escapeDescription');
expect(helpers).toContain('escapeNewline');
expect(helpers).toContain('exactArray');
expect(helpers).toContain('ifdef');
expect(helpers).toContain('ifOperationDataOptional');
expect(helpers).toContain('intersection');
expect(helpers).toContain('modelIsRequired');
expect(helpers).toContain('modelUnionType');
expect(helpers).toContain('nameOperationDataType');
expect(helpers).toContain('notEquals');
expect(helpers).toContain('useDateType');
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-ts/src/utils/enum.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Enum } from '../openApi';
import type { Client } from '../types/client';
import type { Config } from '../types/config';
import { unescapeName } from './escapeName';
import { unescapeName } from './escape';
import { unique } from './unique';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { EOL } from 'os';

/**
* Javascript identifier regexp pattern retrieved from
* {@link} https://developer.mozilla.org/docs/Web/JavaScript/Reference/Lexical_grammar#identifiers
Expand All @@ -20,3 +22,12 @@ export const unescapeName = (value: string): string => {
}
return value;
};

export const escapeComment = (value: string) =>
value
.replace(/\*\//g, '*')
.replace(/\/\*/g, '*')
.replace(/\r?\n(.*)/g, (_, w) => `${EOL} * ${w.trim()}`);

Check warning on line 30 in packages/openapi-ts/src/utils/escape.ts

View check run for this annotation

Codecov / codecov/patch

packages/openapi-ts/src/utils/escape.ts#L27-L30

Added lines #L27 - L30 were not covered by tests

export const escapeDescription = (value: string) =>
value.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${');

Check warning on line 33 in packages/openapi-ts/src/utils/escape.ts

View check run for this annotation

Codecov / codecov/patch

packages/openapi-ts/src/utils/escape.ts#L33

Added line #L33 was not covered by tests
Loading

0 comments on commit b536bc2

Please sign in to comment.