diff --git a/.changeset/modern-teachers-peel.md b/.changeset/modern-teachers-peel.md new file mode 100644 index 000000000..e4c65ce8f --- /dev/null +++ b/.changeset/modern-teachers-peel.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": patch +--- + +fix: do not export inline enums diff --git a/packages/openapi-ts/src/utils/write/types.ts b/packages/openapi-ts/src/utils/write/types.ts index 900e06b4f..541e00157 100644 --- a/packages/openapi-ts/src/utils/write/types.ts +++ b/packages/openapi-ts/src/utils/write/types.ts @@ -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 = {}; @@ -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); } diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/types.gen.ts.snap index fb38c8238..a8cf49cad 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/types.gen.ts.snap @@ -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 */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap index 0e6f5888b..62ddfec84 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap @@ -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 */ @@ -302,11 +297,6 @@ 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 */ @@ -314,8 +304,6 @@ export type ModelWithEnumWithHyphen = { 'foo-bar-baz-qux'?: '3.0'; }; -export type foo_bar_baz_qux_ = '3.0'; - /** * This is a model with one enum */ @@ -728,8 +716,6 @@ export type ModelWithOneOfEnum = { foo: 'Corge'; }; -export type foo = 'Bar'; - export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; @@ -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` */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap index 0e6f5888b..62ddfec84 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap @@ -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 */ @@ -302,11 +297,6 @@ 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 */ @@ -314,8 +304,6 @@ export type ModelWithEnumWithHyphen = { 'foo-bar-baz-qux'?: '3.0'; }; -export type foo_bar_baz_qux_ = '3.0'; - /** * This is a model with one enum */ @@ -728,8 +716,6 @@ export type ModelWithOneOfEnum = { foo: 'Corge'; }; -export type foo = 'Bar'; - export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; @@ -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` */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap index e6e3c05ca..016357520 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap @@ -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 */ @@ -302,11 +297,6 @@ 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 */ @@ -314,8 +304,6 @@ export type ModelWithEnumWithHyphen = { 'foo-bar-baz-qux'?: '3.0'; }; -export type foo_bar_baz_qux_ = '3.0'; - /** * This is a model with one enum */ @@ -728,8 +716,6 @@ export type ModelWithOneOfEnum = { foo: 'Corge'; }; -export type foo = 'Bar'; - export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; @@ -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` */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap index 0e6f5888b..62ddfec84 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap @@ -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 */ @@ -302,11 +297,6 @@ 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 */ @@ -314,8 +304,6 @@ export type ModelWithEnumWithHyphen = { 'foo-bar-baz-qux'?: '3.0'; }; -export type foo_bar_baz_qux_ = '3.0'; - /** * This is a model with one enum */ @@ -728,8 +716,6 @@ export type ModelWithOneOfEnum = { foo: 'Corge'; }; -export type foo = 'Bar'; - export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; @@ -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` */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap index f170ba4bf..b01ae227a 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_models/types.gen.ts.snap @@ -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 */ @@ -302,11 +297,6 @@ 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 */ @@ -314,8 +304,6 @@ export type ModelWithEnumWithHyphen = { 'foo-bar-baz-qux'?: '3.0'; }; -export type foo_bar_baz_qux_ = '3.0'; - /** * This is a model with one enum */ @@ -728,8 +716,6 @@ export type ModelWithOneOfEnum = { foo: 'Corge'; }; -export type foo = 'Bar'; - export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; @@ -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` */