Skip to content

Commit dedfe8f

Browse files
authored
Merge pull request #2572 from max-scopp/fix/2557-allow-undefined-options
2 parents 7fe3aa1 + a12b43e commit dedfe8f

File tree

13 files changed

+1213
-218
lines changed

13 files changed

+1213
-218
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
fix(angular): allow `httpResource` to skip requests when `undefined` is returned

examples/openapi-ts-angular-common/src/client/@angular/common/http/resources.gen.ts

Lines changed: 97 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -70,85 +70,103 @@ export class PetServiceResources {
7070
* Add a new pet to the store.
7171
*/
7272
public addPet<ThrowOnError extends boolean = false>(
73-
options: () => Options<AddPetData, ThrowOnError>,
73+
options: () => Options<AddPetData, ThrowOnError> | undefined,
7474
) {
75-
return httpResource<AddPetResponse>(() => addPetRequest(options()));
75+
return httpResource<AddPetResponse>(() => {
76+
const opts = options ? options() : undefined;
77+
return opts ? addPetRequest(opts) : undefined;
78+
});
7679
}
7780

7881
/**
7982
* Update an existing pet.
8083
* Update an existing pet by Id.
8184
*/
8285
public updatePet<ThrowOnError extends boolean = false>(
83-
options: () => Options<UpdatePetData, ThrowOnError>,
86+
options: () => Options<UpdatePetData, ThrowOnError> | undefined,
8487
) {
85-
return httpResource<UpdatePetResponse>(() => updatePetRequest(options()));
88+
return httpResource<UpdatePetResponse>(() => {
89+
const opts = options ? options() : undefined;
90+
return opts ? updatePetRequest(opts) : undefined;
91+
});
8692
}
8793

8894
/**
8995
* Finds Pets by status.
9096
* Multiple status values can be provided with comma separated strings.
9197
*/
9298
public findPetsByStatus<ThrowOnError extends boolean = false>(
93-
options: () => Options<FindPetsByStatusData, ThrowOnError>,
99+
options: () => Options<FindPetsByStatusData, ThrowOnError> | undefined,
94100
) {
95-
return httpResource<FindPetsByStatusResponse>(() =>
96-
findPetsByStatusRequest(options()),
97-
);
101+
return httpResource<FindPetsByStatusResponse>(() => {
102+
const opts = options ? options() : undefined;
103+
return opts ? findPetsByStatusRequest(opts) : undefined;
104+
});
98105
}
99106

100107
/**
101108
* Finds Pets by tags.
102109
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
103110
*/
104111
public findPetsByTags<ThrowOnError extends boolean = false>(
105-
options: () => Options<FindPetsByTagsData, ThrowOnError>,
112+
options: () => Options<FindPetsByTagsData, ThrowOnError> | undefined,
106113
) {
107-
return httpResource<FindPetsByTagsResponse>(() =>
108-
findPetsByTagsRequest(options()),
109-
);
114+
return httpResource<FindPetsByTagsResponse>(() => {
115+
const opts = options ? options() : undefined;
116+
return opts ? findPetsByTagsRequest(opts) : undefined;
117+
});
110118
}
111119

112120
/**
113121
* Deletes a pet.
114122
* Delete a pet.
115123
*/
116124
public deletePet<ThrowOnError extends boolean = false>(
117-
options: () => Options<DeletePetData, ThrowOnError>,
125+
options: () => Options<DeletePetData, ThrowOnError> | undefined,
118126
) {
119-
return httpResource<unknown>(() => deletePetRequest(options()));
127+
return httpResource<unknown>(() => {
128+
const opts = options ? options() : undefined;
129+
return opts ? deletePetRequest(opts) : undefined;
130+
});
120131
}
121132

122133
/**
123134
* Find pet by ID.
124135
* Returns a single pet.
125136
*/
126137
public getPetById<ThrowOnError extends boolean = false>(
127-
options: () => Options<GetPetByIdData, ThrowOnError>,
138+
options: () => Options<GetPetByIdData, ThrowOnError> | undefined,
128139
) {
129-
return httpResource<GetPetByIdResponse>(() => getPetByIdRequest(options()));
140+
return httpResource<GetPetByIdResponse>(() => {
141+
const opts = options ? options() : undefined;
142+
return opts ? getPetByIdRequest(opts) : undefined;
143+
});
130144
}
131145

132146
/**
133147
* Updates a pet in the store with form data.
134148
* Updates a pet resource based on the form data.
135149
*/
136150
public updatePetWithForm<ThrowOnError extends boolean = false>(
137-
options: () => Options<UpdatePetWithFormData, ThrowOnError>,
151+
options: () => Options<UpdatePetWithFormData, ThrowOnError> | undefined,
138152
) {
139-
return httpResource<UpdatePetWithFormResponse>(() =>
140-
updatePetWithFormRequest(options()),
141-
);
153+
return httpResource<UpdatePetWithFormResponse>(() => {
154+
const opts = options ? options() : undefined;
155+
return opts ? updatePetWithFormRequest(opts) : undefined;
156+
});
142157
}
143158

144159
/**
145160
* Uploads an image.
146161
* Upload image of the pet.
147162
*/
148163
public uploadFile<ThrowOnError extends boolean = false>(
149-
options: () => Options<UploadFileData, ThrowOnError>,
164+
options: () => Options<UploadFileData, ThrowOnError> | undefined,
150165
) {
151-
return httpResource<UploadFileResponse>(() => uploadFileRequest(options()));
166+
return httpResource<UploadFileResponse>(() => {
167+
const opts = options ? options() : undefined;
168+
return opts ? uploadFileRequest(opts) : undefined;
169+
});
152170
}
153171
}
154172

@@ -161,45 +179,51 @@ export class StoreServiceResources {
161179
* Returns a map of status codes to quantities.
162180
*/
163181
public getInventory<ThrowOnError extends boolean = false>(
164-
options?: () => Options<GetInventoryData, ThrowOnError>,
182+
options?: () => Options<GetInventoryData, ThrowOnError> | undefined,
165183
) {
166-
return httpResource<GetInventoryResponse>(() =>
167-
getInventoryRequest(options ? options() : undefined),
168-
);
184+
return httpResource<GetInventoryResponse>(() => {
185+
const opts = options ? options() : undefined;
186+
return opts ? getInventoryRequest(opts) : undefined;
187+
});
169188
}
170189

171190
/**
172191
* Place an order for a pet.
173192
* Place a new order in the store.
174193
*/
175194
public placeOrder<ThrowOnError extends boolean = false>(
176-
options?: () => Options<PlaceOrderData, ThrowOnError>,
195+
options?: () => Options<PlaceOrderData, ThrowOnError> | undefined,
177196
) {
178-
return httpResource<PlaceOrderResponse>(() =>
179-
placeOrderRequest(options ? options() : undefined),
180-
);
197+
return httpResource<PlaceOrderResponse>(() => {
198+
const opts = options ? options() : undefined;
199+
return opts ? placeOrderRequest(opts) : undefined;
200+
});
181201
}
182202

183203
/**
184204
* Delete purchase order by identifier.
185205
* For valid response try integer IDs with value < 1000. Anything above 1000 or non-integers will generate API errors.
186206
*/
187207
public deleteOrder<ThrowOnError extends boolean = false>(
188-
options: () => Options<DeleteOrderData, ThrowOnError>,
208+
options: () => Options<DeleteOrderData, ThrowOnError> | undefined,
189209
) {
190-
return httpResource<unknown>(() => deleteOrderRequest(options()));
210+
return httpResource<unknown>(() => {
211+
const opts = options ? options() : undefined;
212+
return opts ? deleteOrderRequest(opts) : undefined;
213+
});
191214
}
192215

193216
/**
194217
* Find purchase order by ID.
195218
* For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
196219
*/
197220
public getOrderById<ThrowOnError extends boolean = false>(
198-
options: () => Options<GetOrderByIdData, ThrowOnError>,
221+
options: () => Options<GetOrderByIdData, ThrowOnError> | undefined,
199222
) {
200-
return httpResource<GetOrderByIdResponse>(() =>
201-
getOrderByIdRequest(options()),
202-
);
223+
return httpResource<GetOrderByIdResponse>(() => {
224+
const opts = options ? options() : undefined;
225+
return opts ? getOrderByIdRequest(opts) : undefined;
226+
});
203227
}
204228
}
205229

@@ -212,78 +236,91 @@ export class UserServiceResources {
212236
* This can only be done by the logged in user.
213237
*/
214238
public createUser<ThrowOnError extends boolean = false>(
215-
options?: () => Options<CreateUserData, ThrowOnError>,
239+
options?: () => Options<CreateUserData, ThrowOnError> | undefined,
216240
) {
217-
return httpResource<CreateUserResponse>(() =>
218-
createUserRequest(options ? options() : undefined),
219-
);
241+
return httpResource<CreateUserResponse>(() => {
242+
const opts = options ? options() : undefined;
243+
return opts ? createUserRequest(opts) : undefined;
244+
});
220245
}
221246

222247
/**
223248
* Creates list of users with given input array.
224249
* Creates list of users with given input array.
225250
*/
226251
public createUsersWithListInput<ThrowOnError extends boolean = false>(
227-
options?: () => Options<CreateUsersWithListInputData, ThrowOnError>,
252+
options?: () =>
253+
| Options<CreateUsersWithListInputData, ThrowOnError>
254+
| undefined,
228255
) {
229-
return httpResource<CreateUsersWithListInputResponse>(() =>
230-
createUsersWithListInputRequest(options ? options() : undefined),
231-
);
256+
return httpResource<CreateUsersWithListInputResponse>(() => {
257+
const opts = options ? options() : undefined;
258+
return opts ? createUsersWithListInputRequest(opts) : undefined;
259+
});
232260
}
233261

234262
/**
235263
* Logs user into the system.
236264
* Log into the system.
237265
*/
238266
public loginUser<ThrowOnError extends boolean = false>(
239-
options?: () => Options<LoginUserData, ThrowOnError>,
267+
options?: () => Options<LoginUserData, ThrowOnError> | undefined,
240268
) {
241-
return httpResource<LoginUserResponse>(() =>
242-
loginUserRequest(options ? options() : undefined),
243-
);
269+
return httpResource<LoginUserResponse>(() => {
270+
const opts = options ? options() : undefined;
271+
return opts ? loginUserRequest(opts) : undefined;
272+
});
244273
}
245274

246275
/**
247276
* Logs out current logged in user session.
248277
* Log user out of the system.
249278
*/
250279
public logoutUser<ThrowOnError extends boolean = false>(
251-
options?: () => Options<LogoutUserData, ThrowOnError>,
280+
options?: () => Options<LogoutUserData, ThrowOnError> | undefined,
252281
) {
253-
return httpResource<unknown>(() =>
254-
logoutUserRequest(options ? options() : undefined),
255-
);
282+
return httpResource<unknown>(() => {
283+
const opts = options ? options() : undefined;
284+
return opts ? logoutUserRequest(opts) : undefined;
285+
});
256286
}
257287

258288
/**
259289
* Delete user resource.
260290
* This can only be done by the logged in user.
261291
*/
262292
public deleteUser<ThrowOnError extends boolean = false>(
263-
options: () => Options<DeleteUserData, ThrowOnError>,
293+
options: () => Options<DeleteUserData, ThrowOnError> | undefined,
264294
) {
265-
return httpResource<unknown>(() => deleteUserRequest(options()));
295+
return httpResource<unknown>(() => {
296+
const opts = options ? options() : undefined;
297+
return opts ? deleteUserRequest(opts) : undefined;
298+
});
266299
}
267300

268301
/**
269302
* Get user by user name.
270303
* Get user detail based on username.
271304
*/
272305
public getUserByName<ThrowOnError extends boolean = false>(
273-
options: () => Options<GetUserByNameData, ThrowOnError>,
306+
options: () => Options<GetUserByNameData, ThrowOnError> | undefined,
274307
) {
275-
return httpResource<GetUserByNameResponse>(() =>
276-
getUserByNameRequest(options()),
277-
);
308+
return httpResource<GetUserByNameResponse>(() => {
309+
const opts = options ? options() : undefined;
310+
return opts ? getUserByNameRequest(opts) : undefined;
311+
});
278312
}
279313

280314
/**
281315
* Update user resource.
282316
* This can only be done by the logged in user.
283317
*/
284318
public updateUser<ThrowOnError extends boolean = false>(
285-
options: () => Options<UpdateUserData, ThrowOnError>,
319+
options: () => Options<UpdateUserData, ThrowOnError> | undefined,
286320
) {
287-
return httpResource<unknown>(() => updateUserRequest(options()));
321+
return httpResource<unknown>(() => {
322+
const opts = options ? options() : undefined;
323+
return opts ? updateUserRequest(opts) : undefined;
324+
});
288325
}
289326
}

0 commit comments

Comments
 (0)