Skip to content

Commit

Permalink
Merge pull request #508 from hey-api/fix/do-not-export-unless-needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanshatford authored Apr 29, 2024
2 parents 06419ca + 8fb464e commit e3b9876
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 107 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-teachers-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

fix: do not export inline enums
13 changes: 11 additions & 2 deletions packages/openapi-ts/src/utils/write/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ const processComposition = (client: Client, model: Model, onNode: OnNode) => {
model.enums.forEach((enumerator) => processEnum(client, enumerator, onNode));
};

const processEnum = (client: Client, model: Model, onNode: OnNode) => {
const processEnum = (
client: Client,
model: Model,
onNode: OnNode,
isExported: boolean = false,
) => {
if (!isExported) {
return;
}

const config = getConfig();

const properties: Record<string | number, unknown> = {};
Expand Down Expand Up @@ -123,7 +132,7 @@ const processModel = (client: Client, model: Model, onNode: OnNode) => {
case 'interface':
return processComposition(client, model, onNode);
case 'enum':
return processEnum(client, model, onNode);
return processEnum(client, model, onNode, true);
default:
return processType(client, model, onNode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,6 @@ export type ModelWithEnum = {
bool?: boolean;
};

/**
* This is a simple enum with strings
*/
export type test = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串';

/**
* These are the HTTP error code enums
*/
export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar';

/**
* This is a model with one enum
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,6 @@ export type ModelWithNullableString = {
'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串';
};

/**
* This is a simple enum with strings
*/
export type foo_bar_enum_ = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串';

/**
* This is a model with one enum
*/
Expand All @@ -302,20 +297,13 @@ export type ModelWithEnum = {
bool?: boolean;
};

/**
* These are the HTTP error code enums
*/
export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar';

/**
* This is a model with one enum with escaped name
*/
export type ModelWithEnumWithHyphen = {
'foo-bar-baz-qux'?: '3.0';
};

export type foo_bar_baz_qux_ = '3.0';

/**
* This is a model with one enum
*/
Expand Down Expand Up @@ -728,8 +716,6 @@ export type ModelWithOneOfEnum = {
foo: 'Corge';
};

export type foo = 'Bar';

export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar';

export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux';
Expand Down Expand Up @@ -788,11 +774,6 @@ export type ModelWithNumericEnumUnion = {
value?: -10 | -1 | 0 | 1 | 3 | 6 | 12;
};

/**
* Период
*/
export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12;

/**
* Some description with `back ticks`
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,6 @@ export type ModelWithNullableString = {
'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串';
};

/**
* This is a simple enum with strings
*/
export type foo_bar_enum_ = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串';

/**
* This is a model with one enum
*/
Expand All @@ -302,20 +297,13 @@ export type ModelWithEnum = {
bool?: boolean;
};

/**
* These are the HTTP error code enums
*/
export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar';

/**
* This is a model with one enum with escaped name
*/
export type ModelWithEnumWithHyphen = {
'foo-bar-baz-qux'?: '3.0';
};

export type foo_bar_baz_qux_ = '3.0';

/**
* This is a model with one enum
*/
Expand Down Expand Up @@ -728,8 +716,6 @@ export type ModelWithOneOfEnum = {
foo: 'Corge';
};

export type foo = 'Bar';

export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar';

export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux';
Expand Down Expand Up @@ -788,11 +774,6 @@ export type ModelWithNumericEnumUnion = {
value?: -10 | -1 | 0 | 1 | 3 | 6 | 12;
};

/**
* Период
*/
export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12;

/**
* Some description with `back ticks`
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,6 @@ export type ModelWithNullableString = {
'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串';
};

/**
* This is a simple enum with strings
*/
export type foo_bar_enum_ = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串';

/**
* This is a model with one enum
*/
Expand All @@ -302,20 +297,13 @@ export type ModelWithEnum = {
bool?: boolean;
};

/**
* These are the HTTP error code enums
*/
export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar';

/**
* This is a model with one enum with escaped name
*/
export type ModelWithEnumWithHyphen = {
'foo-bar-baz-qux'?: '3.0';
};

export type foo_bar_baz_qux_ = '3.0';

/**
* This is a model with one enum
*/
Expand Down Expand Up @@ -728,8 +716,6 @@ export type ModelWithOneOfEnum = {
foo: 'Corge';
};

export type foo = 'Bar';

export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar';

export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux';
Expand Down Expand Up @@ -788,11 +774,6 @@ export type ModelWithNumericEnumUnion = {
value?: -10 | -1 | 0 | 1 | 3 | 6 | 12;
};

/**
* Период
*/
export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12;

/**
* Some description with `back ticks`
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,6 @@ export type ModelWithNullableString = {
'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串';
};

/**
* This is a simple enum with strings
*/
export type foo_bar_enum_ = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串';

/**
* This is a model with one enum
*/
Expand All @@ -302,20 +297,13 @@ export type ModelWithEnum = {
bool?: boolean;
};

/**
* These are the HTTP error code enums
*/
export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar';

/**
* This is a model with one enum with escaped name
*/
export type ModelWithEnumWithHyphen = {
'foo-bar-baz-qux'?: '3.0';
};

export type foo_bar_baz_qux_ = '3.0';

/**
* This is a model with one enum
*/
Expand Down Expand Up @@ -728,8 +716,6 @@ export type ModelWithOneOfEnum = {
foo: 'Corge';
};

export type foo = 'Bar';

export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar';

export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux';
Expand Down Expand Up @@ -788,11 +774,6 @@ export type ModelWithNumericEnumUnion = {
value?: -10 | -1 | 0 | 1 | 3 | 6 | 12;
};

/**
* Период
*/
export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12;

/**
* Some description with `back ticks`
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,6 @@ export type ModelWithNullableString = {
'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串';
};

/**
* This is a simple enum with strings
*/
export type foo_bar_enum_ = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串';

/**
* This is a model with one enum
*/
Expand All @@ -302,20 +297,13 @@ export type ModelWithEnum = {
bool?: boolean;
};

/**
* These are the HTTP error code enums
*/
export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar';

/**
* This is a model with one enum with escaped name
*/
export type ModelWithEnumWithHyphen = {
'foo-bar-baz-qux'?: '3.0';
};

export type foo_bar_baz_qux_ = '3.0';

/**
* This is a model with one enum
*/
Expand Down Expand Up @@ -728,8 +716,6 @@ export type ModelWithOneOfEnum = {
foo: 'Corge';
};

export type foo = 'Bar';

export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar';

export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux';
Expand Down Expand Up @@ -788,11 +774,6 @@ export type ModelWithNumericEnumUnion = {
value?: -10 | -1 | 0 | 1 | 3 | 6 | 12;
};

/**
* Период
*/
export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12;

/**
* Some description with `back ticks`
*/
Expand Down

0 comments on commit e3b9876

Please sign in to comment.