diff --git a/.changeset/gorgeous-spiders-grin.md b/.changeset/gorgeous-spiders-grin.md new file mode 100644 index 000000000..ef95e2a81 --- /dev/null +++ b/.changeset/gorgeous-spiders-grin.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": minor +--- + +Import all required models for a service in one import diff --git a/src/utils/handlebars.ts b/src/utils/handlebars.ts index 7e9a9f49b..965b3b310 100644 --- a/src/utils/handlebars.ts +++ b/src/utils/handlebars.ts @@ -101,8 +101,10 @@ const escapeComment = (value: string) => .replace(/\r?\n(.*)/g, (_, w) => `${EOL} * ${w.trim()}`); const modelImports = (model: Service, path: string) => { - const output = model.imports.map(item => `import type { ${item} } from '${path}';`); - return output.join('\n'); + if (model.imports.length === 0) { + return ''; + } + return `import type { ${model.imports.join(',')} } from '${path}';`; }; const dataParameters = (parameters: OperationParameter[]) => { diff --git a/test/__snapshots__/v2/services/ResponseService.ts.snap b/test/__snapshots__/v2/services/ResponseService.ts.snap index 0c4b36715..3ec2aeba9 100644 --- a/test/__snapshots__/v2/services/ResponseService.ts.snap +++ b/test/__snapshots__/v2/services/ResponseService.ts.snap @@ -1,6 +1,4 @@ -import type { ModelThatExtends } from '../models'; -import type { ModelThatExtendsExtends } from '../models'; -import type { ModelWithString } from '../models'; +import type { ModelThatExtends, ModelThatExtendsExtends, ModelWithString } from '../models'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; diff --git a/test/__snapshots__/v3/services/ComplexService.ts.snap b/test/__snapshots__/v3/services/ComplexService.ts.snap index abb157906..fc3af8ed9 100644 --- a/test/__snapshots__/v3/services/ComplexService.ts.snap +++ b/test/__snapshots__/v3/services/ComplexService.ts.snap @@ -1,7 +1,4 @@ -import type { ModelWithArray } from '../models'; -import type { ModelWithDictionary } from '../models'; -import type { ModelWithEnum } from '../models'; -import type { ModelWithString } from '../models'; +import type { ModelWithArray, ModelWithDictionary, ModelWithEnum, ModelWithString } from '../models'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; diff --git a/test/__snapshots__/v3/services/DefaultService.ts.snap b/test/__snapshots__/v3/services/DefaultService.ts.snap index c07a61d76..7a42ade9a 100644 --- a/test/__snapshots__/v3/services/DefaultService.ts.snap +++ b/test/__snapshots__/v3/services/DefaultService.ts.snap @@ -1,5 +1,4 @@ -import type { ModelWithArrayReadOnlyAndWriteOnly } from '../models'; -import type { ModelWithReadOnlyAndWriteOnly } from '../models'; +import type { ModelWithArrayReadOnlyAndWriteOnly, ModelWithReadOnlyAndWriteOnly } from '../models'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; diff --git a/test/__snapshots__/v3/services/ParametersService.ts.snap b/test/__snapshots__/v3/services/ParametersService.ts.snap index 0f87766d6..26e9b22a5 100644 --- a/test/__snapshots__/v3/services/ParametersService.ts.snap +++ b/test/__snapshots__/v3/services/ParametersService.ts.snap @@ -1,7 +1,4 @@ -import type { ModelWithNestedArrayEnumsDataFoo } from '../models'; -import type { ModelWithOneOfEnum } from '../models'; -import type { ModelWithString } from '../models'; -import type { Pageable } from '../models'; +import type { ModelWithNestedArrayEnumsDataFoo, ModelWithOneOfEnum, ModelWithString, Pageable } from '../models'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; diff --git a/test/__snapshots__/v3/services/ResponseService.ts.snap b/test/__snapshots__/v3/services/ResponseService.ts.snap index daf8a4e98..d25e4d887 100644 --- a/test/__snapshots__/v3/services/ResponseService.ts.snap +++ b/test/__snapshots__/v3/services/ResponseService.ts.snap @@ -1,6 +1,4 @@ -import type { ModelThatExtends } from '../models'; -import type { ModelThatExtendsExtends } from '../models'; -import type { ModelWithString } from '../models'; +import type { ModelThatExtends, ModelThatExtendsExtends, ModelWithString } from '../models'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; diff --git a/test/__snapshots__/v3_angular/services/ComplexService.ts.snap b/test/__snapshots__/v3_angular/services/ComplexService.ts.snap index ef303c6af..d89d51a49 100644 --- a/test/__snapshots__/v3_angular/services/ComplexService.ts.snap +++ b/test/__snapshots__/v3_angular/services/ComplexService.ts.snap @@ -1,10 +1,7 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import type { Observable } from 'rxjs'; -import type { ModelWithArray } from '../models'; -import type { ModelWithDictionary } from '../models'; -import type { ModelWithEnum } from '../models'; -import type { ModelWithString } from '../models'; +import type { ModelWithArray, ModelWithDictionary, ModelWithEnum, ModelWithString } from '../models'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; diff --git a/test/__snapshots__/v3_angular/services/DefaultService.ts.snap b/test/__snapshots__/v3_angular/services/DefaultService.ts.snap index ae4bcdd0d..f5c8c2cc3 100644 --- a/test/__snapshots__/v3_angular/services/DefaultService.ts.snap +++ b/test/__snapshots__/v3_angular/services/DefaultService.ts.snap @@ -1,8 +1,7 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import type { Observable } from 'rxjs'; -import type { ModelWithArrayReadOnlyAndWriteOnly } from '../models'; -import type { ModelWithReadOnlyAndWriteOnly } from '../models'; +import type { ModelWithArrayReadOnlyAndWriteOnly, ModelWithReadOnlyAndWriteOnly } from '../models'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; diff --git a/test/__snapshots__/v3_angular/services/ParametersService.ts.snap b/test/__snapshots__/v3_angular/services/ParametersService.ts.snap index 972d92a97..a912f22dd 100644 --- a/test/__snapshots__/v3_angular/services/ParametersService.ts.snap +++ b/test/__snapshots__/v3_angular/services/ParametersService.ts.snap @@ -1,10 +1,7 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import type { Observable } from 'rxjs'; -import type { ModelWithNestedArrayEnumsDataFoo } from '../models'; -import type { ModelWithOneOfEnum } from '../models'; -import type { ModelWithString } from '../models'; -import type { Pageable } from '../models'; +import type { ModelWithNestedArrayEnumsDataFoo, ModelWithOneOfEnum, ModelWithString, Pageable } from '../models'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; diff --git a/test/__snapshots__/v3_angular/services/ResponseService.ts.snap b/test/__snapshots__/v3_angular/services/ResponseService.ts.snap index 5971aa984..7a842859a 100644 --- a/test/__snapshots__/v3_angular/services/ResponseService.ts.snap +++ b/test/__snapshots__/v3_angular/services/ResponseService.ts.snap @@ -1,9 +1,7 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import type { Observable } from 'rxjs'; -import type { ModelThatExtends } from '../models'; -import type { ModelThatExtendsExtends } from '../models'; -import type { ModelWithString } from '../models'; +import type { ModelThatExtends, ModelThatExtendsExtends, ModelWithString } from '../models'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; diff --git a/test/__snapshots__/v3_client/services/ComplexService.ts.snap b/test/__snapshots__/v3_client/services/ComplexService.ts.snap index 2c58d55ac..0284636b4 100644 --- a/test/__snapshots__/v3_client/services/ComplexService.ts.snap +++ b/test/__snapshots__/v3_client/services/ComplexService.ts.snap @@ -1,7 +1,4 @@ -import type { ModelWithArray } from '../models'; -import type { ModelWithDictionary } from '../models'; -import type { ModelWithEnum } from '../models'; -import type { ModelWithString } from '../models'; +import type { ModelWithArray, ModelWithDictionary, ModelWithEnum, ModelWithString } from '../models'; import type { CancelablePromise } from '../core/CancelablePromise'; import type { BaseHttpRequest } from '../core/BaseHttpRequest'; diff --git a/test/__snapshots__/v3_client/services/DefaultService.ts.snap b/test/__snapshots__/v3_client/services/DefaultService.ts.snap index ab835ce62..f3fd87493 100644 --- a/test/__snapshots__/v3_client/services/DefaultService.ts.snap +++ b/test/__snapshots__/v3_client/services/DefaultService.ts.snap @@ -1,5 +1,4 @@ -import type { ModelWithArrayReadOnlyAndWriteOnly } from '../models'; -import type { ModelWithReadOnlyAndWriteOnly } from '../models'; +import type { ModelWithArrayReadOnlyAndWriteOnly, ModelWithReadOnlyAndWriteOnly } from '../models'; import type { CancelablePromise } from '../core/CancelablePromise'; import type { BaseHttpRequest } from '../core/BaseHttpRequest'; diff --git a/test/__snapshots__/v3_client/services/ParametersService.ts.snap b/test/__snapshots__/v3_client/services/ParametersService.ts.snap index e3d5391b3..0a200d930 100644 --- a/test/__snapshots__/v3_client/services/ParametersService.ts.snap +++ b/test/__snapshots__/v3_client/services/ParametersService.ts.snap @@ -1,7 +1,4 @@ -import type { ModelWithNestedArrayEnumsDataFoo } from '../models'; -import type { ModelWithOneOfEnum } from '../models'; -import type { ModelWithString } from '../models'; -import type { Pageable } from '../models'; +import type { ModelWithNestedArrayEnumsDataFoo, ModelWithOneOfEnum, ModelWithString, Pageable } from '../models'; import type { CancelablePromise } from '../core/CancelablePromise'; import type { BaseHttpRequest } from '../core/BaseHttpRequest'; diff --git a/test/__snapshots__/v3_client/services/ResponseService.ts.snap b/test/__snapshots__/v3_client/services/ResponseService.ts.snap index e31769ac4..98d4ef416 100644 --- a/test/__snapshots__/v3_client/services/ResponseService.ts.snap +++ b/test/__snapshots__/v3_client/services/ResponseService.ts.snap @@ -1,6 +1,4 @@ -import type { ModelThatExtends } from '../models'; -import type { ModelThatExtendsExtends } from '../models'; -import type { ModelWithString } from '../models'; +import type { ModelThatExtends, ModelThatExtendsExtends, ModelWithString } from '../models'; import type { CancelablePromise } from '../core/CancelablePromise'; import type { BaseHttpRequest } from '../core/BaseHttpRequest'; diff --git a/test/__snapshots__/v3_legacy_enums/services/ComplexService.ts.snap b/test/__snapshots__/v3_legacy_enums/services/ComplexService.ts.snap index abb157906..fc3af8ed9 100644 --- a/test/__snapshots__/v3_legacy_enums/services/ComplexService.ts.snap +++ b/test/__snapshots__/v3_legacy_enums/services/ComplexService.ts.snap @@ -1,7 +1,4 @@ -import type { ModelWithArray } from '../models'; -import type { ModelWithDictionary } from '../models'; -import type { ModelWithEnum } from '../models'; -import type { ModelWithString } from '../models'; +import type { ModelWithArray, ModelWithDictionary, ModelWithEnum, ModelWithString } from '../models'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; diff --git a/test/__snapshots__/v3_legacy_enums/services/DefaultService.ts.snap b/test/__snapshots__/v3_legacy_enums/services/DefaultService.ts.snap index c07a61d76..7a42ade9a 100644 --- a/test/__snapshots__/v3_legacy_enums/services/DefaultService.ts.snap +++ b/test/__snapshots__/v3_legacy_enums/services/DefaultService.ts.snap @@ -1,5 +1,4 @@ -import type { ModelWithArrayReadOnlyAndWriteOnly } from '../models'; -import type { ModelWithReadOnlyAndWriteOnly } from '../models'; +import type { ModelWithArrayReadOnlyAndWriteOnly, ModelWithReadOnlyAndWriteOnly } from '../models'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; diff --git a/test/__snapshots__/v3_legacy_enums/services/ParametersService.ts.snap b/test/__snapshots__/v3_legacy_enums/services/ParametersService.ts.snap index 0f87766d6..26e9b22a5 100644 --- a/test/__snapshots__/v3_legacy_enums/services/ParametersService.ts.snap +++ b/test/__snapshots__/v3_legacy_enums/services/ParametersService.ts.snap @@ -1,7 +1,4 @@ -import type { ModelWithNestedArrayEnumsDataFoo } from '../models'; -import type { ModelWithOneOfEnum } from '../models'; -import type { ModelWithString } from '../models'; -import type { Pageable } from '../models'; +import type { ModelWithNestedArrayEnumsDataFoo, ModelWithOneOfEnum, ModelWithString, Pageable } from '../models'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; diff --git a/test/__snapshots__/v3_legacy_enums/services/ResponseService.ts.snap b/test/__snapshots__/v3_legacy_enums/services/ResponseService.ts.snap index daf8a4e98..d25e4d887 100644 --- a/test/__snapshots__/v3_legacy_enums/services/ResponseService.ts.snap +++ b/test/__snapshots__/v3_legacy_enums/services/ResponseService.ts.snap @@ -1,6 +1,4 @@ -import type { ModelThatExtends } from '../models'; -import type { ModelThatExtendsExtends } from '../models'; -import type { ModelWithString } from '../models'; +import type { ModelThatExtends, ModelThatExtendsExtends, ModelWithString } from '../models'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request';