@hey-api/openapi-ts 0.80.5 → 0.80.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import type { Client, Config, RequestOptions } from './types';
1
+ import type { Client, Config, ResolvedRequestOptions } from './types';
2
2
  import {
3
3
  buildUrl,
4
4
  createConfig,
@@ -28,7 +28,7 @@ export const createClient = (config: Config = {}): Client => {
28
28
  Request,
29
29
  Response,
30
30
  unknown,
31
- RequestOptions
31
+ ResolvedRequestOptions
32
32
  >();
33
33
 
34
34
  const request: Client['request'] = async (options) => {
@@ -37,6 +37,7 @@ export const createClient = (config: Config = {}): Client => {
37
37
  ...options,
38
38
  fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
39
39
  headers: mergeHeaders(_config.headers, options.headers),
40
+ serializedBody: undefined,
40
41
  };
41
42
 
42
43
  if (opts.security) {
@@ -51,11 +52,11 @@ export const createClient = (config: Config = {}): Client => {
51
52
  }
52
53
 
53
54
  if (opts.body && opts.bodySerializer) {
54
- opts.body = opts.bodySerializer(opts.body);
55
+ opts.serializedBody = opts.bodySerializer(opts.body);
55
56
  }
56
57
 
57
58
  // remove Content-Type header if body is empty to avoid sending invalid requests
58
- if (opts.body === undefined || opts.body === '') {
59
+ if (opts.serializedBody === undefined || opts.serializedBody === '') {
59
60
  opts.headers.delete('Content-Type');
60
61
  }
61
62
 
@@ -63,6 +64,7 @@ export const createClient = (config: Config = {}): Client => {
63
64
  const requestInit: ReqInit = {
64
65
  redirect: 'follow',
65
66
  ...opts,
67
+ body: opts.serializedBody,
66
68
  };
67
69
 
68
70
  let request = new Request(url, requestInit);
@@ -16,6 +16,7 @@ export type {
16
16
  OptionsLegacyParser,
17
17
  RequestOptions,
18
18
  RequestResult,
19
+ ResolvedRequestOptions,
19
20
  ResponseStyle,
20
21
  TDataShape,
21
22
  } from './types';
@@ -81,6 +81,14 @@ export interface RequestOptions<
81
81
  url: Url;
82
82
  }
83
83
 
84
+ export interface ResolvedRequestOptions<
85
+ TResponseStyle extends ResponseStyle = 'fields',
86
+ ThrowOnError extends boolean = boolean,
87
+ Url extends string = string,
88
+ > extends RequestOptions<TResponseStyle, ThrowOnError, Url> {
89
+ serializedBody?: string;
90
+ }
91
+
84
92
  export type RequestResult<
85
93
  TData = unknown,
86
94
  TError = unknown,
@@ -163,7 +171,7 @@ type BuildUrlFn = <
163
171
  ) => string;
164
172
 
165
173
  export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn> & {
166
- interceptors: Middleware<Request, Response, unknown, RequestOptions>;
174
+ interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
167
175
  };
168
176
 
169
177
  /**
@@ -1,4 +1,4 @@
1
- import type { Client, Config, RequestOptions } from './types';
1
+ import type { Client, Config, ResolvedRequestOptions } from './types';
2
2
  import {
3
3
  buildUrl,
4
4
  createConfig,
@@ -24,7 +24,11 @@ export const createClient = (config: Config = {}): Client => {
24
24
  return getConfig();
25
25
  };
26
26
 
27
- const interceptors = createInterceptors<Response, unknown, RequestOptions>();
27
+ const interceptors = createInterceptors<
28
+ Response,
29
+ unknown,
30
+ ResolvedRequestOptions
31
+ >();
28
32
 
29
33
  // @ts-expect-error
30
34
  const request: Client['request'] = async (options) => {
@@ -33,6 +37,7 @@ export const createClient = (config: Config = {}): Client => {
33
37
  ...options,
34
38
  fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
35
39
  headers: mergeHeaders(_config.headers, options.headers),
40
+ serializedBody: undefined,
36
41
  };
37
42
 
38
43
  if (opts.security) {
@@ -47,11 +52,11 @@ export const createClient = (config: Config = {}): Client => {
47
52
  }
48
53
 
49
54
  if (opts.body && opts.bodySerializer) {
50
- opts.body = opts.bodySerializer(opts.body);
55
+ opts.serializedBody = opts.bodySerializer(opts.body);
51
56
  }
52
57
 
53
58
  // remove Content-Type header if body is empty to avoid sending invalid requests
54
- if (opts.body === undefined || opts.body === '') {
59
+ if (opts.serializedBody === undefined || opts.serializedBody === '') {
55
60
  opts.headers.delete('Content-Type');
56
61
  }
57
62
 
@@ -67,7 +72,7 @@ export const createClient = (config: Config = {}): Client => {
67
72
  const _fetch = opts.fetch!;
68
73
  let response = await _fetch(url, {
69
74
  ...opts,
70
- body: opts.body as ReqInit['body'],
75
+ body: opts.serializedBody as ReqInit['body'],
71
76
  });
72
77
 
73
78
  for (const fn of interceptors.response._fns) {
@@ -64,6 +64,13 @@ export interface RequestOptions<
64
64
  url: Url;
65
65
  }
66
66
 
67
+ export interface ResolvedRequestOptions<
68
+ ThrowOnError extends boolean = boolean,
69
+ Url extends string = string,
70
+ > extends RequestOptions<ThrowOnError, Url> {
71
+ serializedBody?: string;
72
+ }
73
+
67
74
  export type RequestResult<
68
75
  TData = unknown,
69
76
  TError = unknown,
@@ -126,7 +133,7 @@ type BuildUrlFn = <
126
133
  ) => string;
127
134
 
128
135
  export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn> & {
129
- interceptors: Middleware<Response, unknown, RequestOptions>;
136
+ interceptors: Middleware<Response, unknown, ResolvedRequestOptions>;
130
137
  };
131
138
 
132
139
  /**