@hey-api/openapi-ts 0.80.13 → 0.80.15

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.
@@ -138,6 +138,28 @@ export const createQuerySerializer = <T = unknown>({
138
138
  return querySerializer;
139
139
  };
140
140
 
141
+ const checkForExistence = (
142
+ options: Pick<RequestOptions, 'auth' | 'query'> & {
143
+ headers: Record<any, unknown>;
144
+ },
145
+ name?: string,
146
+ ): boolean => {
147
+ if (!name) {
148
+ return false;
149
+ }
150
+ if (name in options.headers || options.query?.[name]) {
151
+ return true;
152
+ }
153
+ if (
154
+ 'Cookie' in options.headers &&
155
+ options.headers['Cookie'] &&
156
+ typeof options.headers['Cookie'] === 'string'
157
+ ) {
158
+ return options.headers['Cookie'].includes(`${name}=`);
159
+ }
160
+ return false;
161
+ };
162
+
141
163
  export const setAuthParams = async ({
142
164
  security,
143
165
  ...options
@@ -146,6 +168,9 @@ export const setAuthParams = async ({
146
168
  headers: Record<any, unknown>;
147
169
  }) => {
148
170
  for (const auth of security) {
171
+ if (checkForExistence(options, auth.name)) {
172
+ continue;
173
+ }
149
174
  const token = await getAuthToken(auth, options.auth);
150
175
 
151
176
  if (!token) {
@@ -175,8 +200,6 @@ export const setAuthParams = async ({
175
200
  options.headers[name] = token;
176
201
  break;
177
202
  }
178
-
179
- return;
180
203
  }
181
204
  };
182
205
 
@@ -186,6 +186,25 @@ export const getParseAs = (
186
186
  return;
187
187
  };
188
188
 
189
+ const checkForExistence = (
190
+ options: Pick<RequestOptions, 'auth' | 'query'> & {
191
+ headers: Headers;
192
+ },
193
+ name?: string,
194
+ ): boolean => {
195
+ if (!name) {
196
+ return false;
197
+ }
198
+ if (
199
+ options.headers.has(name) ||
200
+ options.query?.[name] ||
201
+ options.headers.get('Cookie')?.includes(`${name}=`)
202
+ ) {
203
+ return true;
204
+ }
205
+ return false;
206
+ };
207
+
189
208
  export const setAuthParams = async ({
190
209
  security,
191
210
  ...options
@@ -194,6 +213,10 @@ export const setAuthParams = async ({
194
213
  headers: Headers;
195
214
  }) => {
196
215
  for (const auth of security) {
216
+ if (checkForExistence(options, auth.name)) {
217
+ continue;
218
+ }
219
+
197
220
  const token = await getAuthToken(auth, options.auth);
198
221
 
199
222
  if (!token) {
@@ -217,8 +240,6 @@ export const setAuthParams = async ({
217
240
  options.headers.set(name, token);
218
241
  break;
219
242
  }
220
-
221
- return;
222
243
  }
223
244
  };
224
245
 
@@ -186,6 +186,25 @@ export const getParseAs = (
186
186
  return;
187
187
  };
188
188
 
189
+ const checkForExistence = (
190
+ options: Pick<RequestOptions, 'auth' | 'query'> & {
191
+ headers: Headers;
192
+ },
193
+ name?: string,
194
+ ): boolean => {
195
+ if (!name) {
196
+ return false;
197
+ }
198
+ if (
199
+ options.headers.has(name) ||
200
+ options.query?.[name] ||
201
+ options.headers.get('Cookie')?.includes(`${name}=`)
202
+ ) {
203
+ return true;
204
+ }
205
+ return false;
206
+ };
207
+
189
208
  export const setAuthParams = async ({
190
209
  security,
191
210
  ...options
@@ -194,6 +213,9 @@ export const setAuthParams = async ({
194
213
  headers: Headers;
195
214
  }) => {
196
215
  for (const auth of security) {
216
+ if (checkForExistence(options, auth.name)) {
217
+ continue;
218
+ }
197
219
  const token = await getAuthToken(auth, options.auth);
198
220
 
199
221
  if (!token) {
@@ -217,8 +239,6 @@ export const setAuthParams = async ({
217
239
  options.headers.set(name, token);
218
240
  break;
219
241
  }
220
-
221
- return;
222
242
  }
223
243
  };
224
244
 
@@ -146,6 +146,25 @@ export const createQuerySerializer = <T = unknown>({
146
146
  return querySerializer;
147
147
  };
148
148
 
149
+ const checkForExistence = (
150
+ options: Pick<RequestOptions, 'auth' | 'query'> & {
151
+ headers: Headers;
152
+ },
153
+ name?: string,
154
+ ): boolean => {
155
+ if (!name) {
156
+ return false;
157
+ }
158
+ if (
159
+ options.headers.has(name) ||
160
+ toValue(options.query)?.[name] ||
161
+ options.headers.get('Cookie')?.includes(`${name}=`)
162
+ ) {
163
+ return true;
164
+ }
165
+ return false;
166
+ };
167
+
149
168
  export const setAuthParams = async ({
150
169
  security,
151
170
  ...options
@@ -154,6 +173,9 @@ export const setAuthParams = async ({
154
173
  headers: Headers;
155
174
  }) => {
156
175
  for (const auth of security) {
176
+ if (checkForExistence(options, auth.name)) {
177
+ continue;
178
+ }
157
179
  const token = await getAuthToken(auth, options.auth);
158
180
 
159
181
  if (!token) {
@@ -177,8 +199,6 @@ export const setAuthParams = async ({
177
199
  options.headers.set(name, token);
178
200
  break;
179
201
  }
180
-
181
- return;
182
202
  }
183
203
  };
184
204