Skip to content

Commit fd6326a

Browse files
committed
feat: add @hey-api/angular-resource plugin with Angular resource generation
- Introduced the @hey-api/angular-resource plugin to facilitate Angular resource generation. - Implemented configuration options for generating resources as classes or functions. - Created necessary types and interfaces for the plugin. - Developed the plugin handler to generate Angular services based on SDK operations. - Added auto-generated resource methods for Pet, Store, and User entities. - Updated the plugin configuration map to include the new angular-resource plugin. - Removed deprecated httpResource option from the client-angular plugin.
1 parent 69ce916 commit fd6326a

File tree

13 files changed

+1571
-682
lines changed

13 files changed

+1571
-682
lines changed

examples/openapi-ts-angular/openapi-ts.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ export default defineConfig({
1010
},
1111
plugins: [
1212
'@hey-api/client-angular',
13+
'@tanstack/angular-query-experimental',
14+
{
15+
// asClass: true,
16+
name: '@hey-api/angular-resource',
17+
},
1318
'@hey-api/schemas',
1419
{
15-
asClass: false,
20+
asClass: true,
1621
name: '@hey-api/sdk',
1722
},
1823
{
Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import { Injectable, resource } from '@angular/core';
4+
5+
import type { Options } from '../sdk.gen';
6+
import { Pet, Store, User } from '../sdk.gen';
7+
import type {
8+
AddPetData,
9+
CreateUserData,
10+
CreateUsersWithListInputData,
11+
DeleteOrderData,
12+
DeletePetData,
13+
DeleteUserData,
14+
FindPetsByStatusData,
15+
FindPetsByTagsData,
16+
GetInventoryData,
17+
GetOrderByIdData,
18+
GetPetByIdData,
19+
GetUserByNameData,
20+
LoginUserData,
21+
LogoutUserData,
22+
PlaceOrderData,
23+
UpdatePetData,
24+
UpdatePetWithFormData,
25+
UpdateUserData,
26+
UploadFileData,
27+
} from '../types.gen';
28+
29+
@Injectable({
30+
providedIn: 'root',
31+
})
32+
export class PetResource {
33+
/**
34+
* Add a new pet to the store.
35+
* Add a new pet to the store.
36+
*/
37+
public addPet<ThrowOnError extends boolean = false>(
38+
options: Options<AddPetData, ThrowOnError>,
39+
) {
40+
return resource({
41+
loader: async ({ params }) => Pet.addPet(params),
42+
params: () => options,
43+
});
44+
}
45+
46+
/**
47+
* Update an existing pet.
48+
* Update an existing pet by Id.
49+
*/
50+
public updatePet<ThrowOnError extends boolean = false>(
51+
options: Options<UpdatePetData, ThrowOnError>,
52+
) {
53+
return resource({
54+
loader: async ({ params }) => Pet.updatePet(params),
55+
params: () => options,
56+
});
57+
}
58+
59+
/**
60+
* Finds Pets by status.
61+
* Multiple status values can be provided with comma separated strings.
62+
*/
63+
public findPetsByStatus<ThrowOnError extends boolean = false>(
64+
options: Options<FindPetsByStatusData, ThrowOnError>,
65+
) {
66+
return resource({
67+
loader: async ({ params }) => Pet.findPetsByStatus(params),
68+
params: () => options,
69+
});
70+
}
71+
72+
/**
73+
* Finds Pets by tags.
74+
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
75+
*/
76+
public findPetsByTags<ThrowOnError extends boolean = false>(
77+
options: Options<FindPetsByTagsData, ThrowOnError>,
78+
) {
79+
return resource({
80+
loader: async ({ params }) => Pet.findPetsByTags(params),
81+
params: () => options,
82+
});
83+
}
84+
85+
/**
86+
* Deletes a pet.
87+
* Delete a pet.
88+
*/
89+
public deletePet<ThrowOnError extends boolean = false>(
90+
options: Options<DeletePetData, ThrowOnError>,
91+
) {
92+
return resource({
93+
loader: async ({ params }) => Pet.deletePet(params),
94+
params: () => options,
95+
});
96+
}
97+
98+
/**
99+
* Find pet by ID.
100+
* Returns a single pet.
101+
*/
102+
public getPetById<ThrowOnError extends boolean = false>(
103+
options: Options<GetPetByIdData, ThrowOnError>,
104+
) {
105+
return resource({
106+
loader: async ({ params }) => Pet.getPetById(params),
107+
params: () => options,
108+
});
109+
}
110+
111+
/**
112+
* Updates a pet in the store with form data.
113+
* Updates a pet resource based on the form data.
114+
*/
115+
public updatePetWithForm<ThrowOnError extends boolean = false>(
116+
options: Options<UpdatePetWithFormData, ThrowOnError>,
117+
) {
118+
return resource({
119+
loader: async ({ params }) => Pet.updatePetWithForm(params),
120+
params: () => options,
121+
});
122+
}
123+
124+
/**
125+
* Uploads an image.
126+
* Upload image of the pet.
127+
*/
128+
public uploadFile<ThrowOnError extends boolean = false>(
129+
options: Options<UploadFileData, ThrowOnError>,
130+
) {
131+
return resource({
132+
loader: async ({ params }) => Pet.uploadFile(params),
133+
params: () => options,
134+
});
135+
}
136+
}
137+
138+
@Injectable({
139+
providedIn: 'root',
140+
})
141+
export class StoreResource {
142+
/**
143+
* Returns pet inventories by status.
144+
* Returns a map of status codes to quantities.
145+
*/
146+
public getInventory<ThrowOnError extends boolean = false>(
147+
options?: Options<GetInventoryData, ThrowOnError>,
148+
) {
149+
return resource({
150+
loader: async ({ params }) => Store.getInventory(params),
151+
params: () => options,
152+
});
153+
}
154+
155+
/**
156+
* Place an order for a pet.
157+
* Place a new order in the store.
158+
*/
159+
public placeOrder<ThrowOnError extends boolean = false>(
160+
options?: Options<PlaceOrderData, ThrowOnError>,
161+
) {
162+
return resource({
163+
loader: async ({ params }) => Store.placeOrder(params),
164+
params: () => options,
165+
});
166+
}
167+
168+
/**
169+
* Delete purchase order by identifier.
170+
* For valid response try integer IDs with value < 1000. Anything above 1000 or non-integers will generate API errors.
171+
*/
172+
public deleteOrder<ThrowOnError extends boolean = false>(
173+
options: Options<DeleteOrderData, ThrowOnError>,
174+
) {
175+
return resource({
176+
loader: async ({ params }) => Store.deleteOrder(params),
177+
params: () => options,
178+
});
179+
}
180+
181+
/**
182+
* Find purchase order by ID.
183+
* For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
184+
*/
185+
public getOrderById<ThrowOnError extends boolean = false>(
186+
options: Options<GetOrderByIdData, ThrowOnError>,
187+
) {
188+
return resource({
189+
loader: async ({ params }) => Store.getOrderById(params),
190+
params: () => options,
191+
});
192+
}
193+
}
194+
195+
@Injectable({
196+
providedIn: 'root',
197+
})
198+
export class UserResource {
199+
/**
200+
* Create user.
201+
* This can only be done by the logged in user.
202+
*/
203+
public createUser<ThrowOnError extends boolean = false>(
204+
options?: Options<CreateUserData, ThrowOnError>,
205+
) {
206+
return resource({
207+
loader: async ({ params }) => User.createUser(params),
208+
params: () => options,
209+
});
210+
}
211+
212+
/**
213+
* Creates list of users with given input array.
214+
* Creates list of users with given input array.
215+
*/
216+
public createUsersWithListInput<ThrowOnError extends boolean = false>(
217+
options?: Options<CreateUsersWithListInputData, ThrowOnError>,
218+
) {
219+
return resource({
220+
loader: async ({ params }) => User.createUsersWithListInput(params),
221+
params: () => options,
222+
});
223+
}
224+
225+
/**
226+
* Logs user into the system.
227+
* Log into the system.
228+
*/
229+
public loginUser<ThrowOnError extends boolean = false>(
230+
options?: Options<LoginUserData, ThrowOnError>,
231+
) {
232+
return resource({
233+
loader: async ({ params }) => User.loginUser(params),
234+
params: () => options,
235+
});
236+
}
237+
238+
/**
239+
* Logs out current logged in user session.
240+
* Log user out of the system.
241+
*/
242+
public logoutUser<ThrowOnError extends boolean = false>(
243+
options?: Options<LogoutUserData, ThrowOnError>,
244+
) {
245+
return resource({
246+
loader: async ({ params }) => User.logoutUser(params),
247+
params: () => options,
248+
});
249+
}
250+
251+
/**
252+
* Delete user resource.
253+
* This can only be done by the logged in user.
254+
*/
255+
public deleteUser<ThrowOnError extends boolean = false>(
256+
options: Options<DeleteUserData, ThrowOnError>,
257+
) {
258+
return resource({
259+
loader: async ({ params }) => User.deleteUser(params),
260+
params: () => options,
261+
});
262+
}
263+
264+
/**
265+
* Get user by user name.
266+
* Get user detail based on username.
267+
*/
268+
public getUserByName<ThrowOnError extends boolean = false>(
269+
options: Options<GetUserByNameData, ThrowOnError>,
270+
) {
271+
return resource({
272+
loader: async ({ params }) => User.getUserByName(params),
273+
params: () => options,
274+
});
275+
}
276+
277+
/**
278+
* Update user resource.
279+
* This can only be done by the logged in user.
280+
*/
281+
public updateUser<ThrowOnError extends boolean = false>(
282+
options: Options<UpdateUserData, ThrowOnError>,
283+
) {
284+
return resource({
285+
loader: async ({ params }) => User.updateUser(params),
286+
params: () => options,
287+
});
288+
}
289+
}

0 commit comments

Comments
 (0)