-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from hey-api/feat/add-use-legacy-enums
feat(client): add useLegacyEnums option to generate typescript enums
- Loading branch information
Showing
238 changed files
with
4,150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hey-api/openapi-ts": minor | ||
--- | ||
|
||
Add useLegacyEnums options to generate TypeScript enums |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
test/__snapshots__/v3-legacy-enums/test/generated/v3_legacy_enums/core/ApiError.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { ApiRequestOptions } from './ApiRequestOptions'; | ||
import type { ApiResult } from './ApiResult'; | ||
|
||
export class ApiError extends Error { | ||
public readonly url: string; | ||
public readonly status: number; | ||
public readonly statusText: string; | ||
public readonly body: unknown; | ||
public readonly request: ApiRequestOptions; | ||
|
||
constructor(request: ApiRequestOptions, response: ApiResult, message: string) { | ||
super(message); | ||
|
||
this.name = 'ApiError'; | ||
this.url = response.url; | ||
this.status = response.status; | ||
this.statusText = response.statusText; | ||
this.body = response.body; | ||
this.request = request; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...snapshots__/v3-legacy-enums/test/generated/v3_legacy_enums/core/ApiRequestOptions.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export type ApiRequestOptions = { | ||
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; | ||
readonly url: string; | ||
readonly path?: Record<string, unknown>; | ||
readonly cookies?: Record<string, unknown>; | ||
readonly headers?: Record<string, unknown>; | ||
readonly query?: Record<string, unknown>; | ||
readonly formData?: Record<string, unknown>; | ||
readonly body?: any; | ||
readonly mediaType?: string; | ||
readonly responseHeader?: string; | ||
readonly errors?: Record<number, string>; | ||
}; |
7 changes: 7 additions & 0 deletions
7
test/__snapshots__/v3-legacy-enums/test/generated/v3_legacy_enums/core/ApiResult.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type ApiResult<TData = any> = { | ||
readonly body: TData; | ||
readonly ok: boolean; | ||
readonly status: number; | ||
readonly statusText: string; | ||
readonly url: string; | ||
}; |
126 changes: 126 additions & 0 deletions
126
...snapshots__/v3-legacy-enums/test/generated/v3_legacy_enums/core/CancelablePromise.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
export class CancelError extends Error { | ||
constructor(message: string) { | ||
super(message); | ||
this.name = 'CancelError'; | ||
} | ||
|
||
public get isCancelled(): boolean { | ||
return true; | ||
} | ||
} | ||
|
||
export interface OnCancel { | ||
readonly isResolved: boolean; | ||
readonly isRejected: boolean; | ||
readonly isCancelled: boolean; | ||
|
||
(cancelHandler: () => void): void; | ||
} | ||
|
||
export class CancelablePromise<T> implements Promise<T> { | ||
#isResolved: boolean; | ||
#isRejected: boolean; | ||
#isCancelled: boolean; | ||
readonly #cancelHandlers: (() => void)[]; | ||
readonly #promise: Promise<T>; | ||
#resolve?: (value: T | PromiseLike<T>) => void; | ||
#reject?: (reason?: unknown) => void; | ||
|
||
constructor( | ||
executor: ( | ||
resolve: (value: T | PromiseLike<T>) => void, | ||
reject: (reason?: unknown) => void, | ||
onCancel: OnCancel | ||
) => void | ||
) { | ||
this.#isResolved = false; | ||
this.#isRejected = false; | ||
this.#isCancelled = false; | ||
this.#cancelHandlers = []; | ||
this.#promise = new Promise<T>((resolve, reject) => { | ||
this.#resolve = resolve; | ||
this.#reject = reject; | ||
|
||
const onResolve = (value: T | PromiseLike<T>): void => { | ||
if (this.#isResolved || this.#isRejected || this.#isCancelled) { | ||
return; | ||
} | ||
this.#isResolved = true; | ||
if (this.#resolve) this.#resolve(value); | ||
}; | ||
|
||
const onReject = (reason?: unknown): void => { | ||
if (this.#isResolved || this.#isRejected || this.#isCancelled) { | ||
return; | ||
} | ||
this.#isRejected = true; | ||
if (this.#reject) this.#reject(reason); | ||
}; | ||
|
||
const onCancel = (cancelHandler: () => void): void => { | ||
if (this.#isResolved || this.#isRejected || this.#isCancelled) { | ||
return; | ||
} | ||
this.#cancelHandlers.push(cancelHandler); | ||
}; | ||
|
||
Object.defineProperty(onCancel, 'isResolved', { | ||
get: (): boolean => this.#isResolved, | ||
}); | ||
|
||
Object.defineProperty(onCancel, 'isRejected', { | ||
get: (): boolean => this.#isRejected, | ||
}); | ||
|
||
Object.defineProperty(onCancel, 'isCancelled', { | ||
get: (): boolean => this.#isCancelled, | ||
}); | ||
|
||
return executor(onResolve, onReject, onCancel as OnCancel); | ||
}); | ||
} | ||
|
||
get [Symbol.toStringTag]() { | ||
return 'Cancellable Promise'; | ||
} | ||
|
||
public then<TResult1 = T, TResult2 = never>( | ||
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, | ||
onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | ||
): Promise<TResult1 | TResult2> { | ||
return this.#promise.then(onFulfilled, onRejected); | ||
} | ||
|
||
public catch<TResult = never>( | ||
onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null | ||
): Promise<T | TResult> { | ||
return this.#promise.catch(onRejected); | ||
} | ||
|
||
public finally(onFinally?: (() => void) | null): Promise<T> { | ||
return this.#promise.finally(onFinally); | ||
} | ||
|
||
public cancel(): void { | ||
if (this.#isResolved || this.#isRejected || this.#isCancelled) { | ||
return; | ||
} | ||
this.#isCancelled = true; | ||
if (this.#cancelHandlers.length) { | ||
try { | ||
for (const cancelHandler of this.#cancelHandlers) { | ||
cancelHandler(); | ||
} | ||
} catch (error) { | ||
console.warn('Cancellation threw an error', error); | ||
return; | ||
} | ||
} | ||
this.#cancelHandlers.length = 0; | ||
if (this.#reject) this.#reject(new CancelError('Request aborted')); | ||
} | ||
|
||
public get isCancelled(): boolean { | ||
return this.#isCancelled; | ||
} | ||
} |
Oops, something went wrong.