Skip to content

Commit

Permalink
Merge pull request #172 from hey-api/feat/import-all-models-in-one-im…
Browse files Browse the repository at this point in the history
…port

feat(client): import all models required in service in one import
  • Loading branch information
jordanshatford authored Mar 28, 2024
2 parents 7e896e9 + e33b300 commit 69f1000
Show file tree
Hide file tree
Showing 19 changed files with 26 additions and 57 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-spiders-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": minor
---

Import all required models for a service in one import
6 changes: 4 additions & 2 deletions src/utils/handlebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) => {
Expand Down
4 changes: 1 addition & 3 deletions test/__snapshots__/v2/services/ResponseService.ts.snap
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
5 changes: 1 addition & 4 deletions test/__snapshots__/v3/services/ComplexService.ts.snap
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
3 changes: 1 addition & 2 deletions test/__snapshots__/v3/services/DefaultService.ts.snap
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
5 changes: 1 addition & 4 deletions test/__snapshots__/v3/services/ParametersService.ts.snap
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 1 addition & 3 deletions test/__snapshots__/v3/services/ResponseService.ts.snap
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
5 changes: 1 addition & 4 deletions test/__snapshots__/v3_client/services/ComplexService.ts.snap
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
3 changes: 1 addition & 2 deletions test/__snapshots__/v3_client/services/DefaultService.ts.snap
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit 69f1000

Please sign in to comment.