File: | api/PetAPI.c |
Warning: | line 608, column 5 1st function call argument is an uninitialized value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | #include <stdlib.h> | |||
2 | #include <stdio.h> | |||
3 | #include <ctype.h> | |||
4 | #include "PetAPI.h" | |||
5 | ||||
6 | #define MAX_NUMBER_LENGTH16 16 | |||
7 | #define MAX_BUFFER_LENGTH4096 4096 | |||
8 | #define intToStr(dst, src)do { char dst[256]; snprintf(dst, 256, "%ld", (long int)(src) );}while(0) \ | |||
9 | do {\ | |||
10 | char dst[256];\ | |||
11 | snprintf(dst, 256, "%ld", (long int)(src));\ | |||
12 | }while(0) | |||
13 | ||||
14 | // Functions for enum STATUS for PetAPI_findPetsByStatus | |||
15 | ||||
16 | static char* findPetsByStatus_STATUS_ToString(openapi_petstore_findPetsByStatus_status_e STATUS){ | |||
17 | char *STATUSArray[] = { "NULL", "available", "pending", "sold" }; | |||
18 | return STATUSArray[STATUS]; | |||
19 | } | |||
20 | ||||
21 | static openapi_petstore_findPetsByStatus_status_e findPetsByStatus_STATUS_FromString(char* STATUS){ | |||
22 | int stringToReturn = 0; | |||
23 | char *STATUSArray[] = { "NULL", "available", "pending", "sold" }; | |||
24 | size_t sizeofArray = sizeof(STATUSArray) / sizeof(STATUSArray[0]); | |||
25 | while(stringToReturn < sizeofArray) { | |||
26 | if(strcmp(STATUS, STATUSArray[stringToReturn]) == 0) { | |||
27 | return stringToReturn; | |||
28 | } | |||
29 | stringToReturn++; | |||
30 | } | |||
31 | return 0; | |||
32 | } | |||
33 | ||||
34 | /* | |||
35 | // Function findPetsByStatus_STATUS_convertToJSON is not currently used, | |||
36 | // since conversion to JSON passes through the conversion of the model, and ToString. The function is kept for future reference. | |||
37 | // | |||
38 | static cJSON *findPetsByStatus_STATUS_convertToJSON(openapi_petstore_findPetsByStatus_status_e STATUS) { | |||
39 | cJSON *item = cJSON_CreateObject(); | |||
40 | return item; | |||
41 | fail: | |||
42 | cJSON_Delete(item); | |||
43 | return NULL; | |||
44 | } | |||
45 | ||||
46 | // Function findPetsByStatus_STATUS_parseFromJSON is not currently used, | |||
47 | // since conversion from JSON passes through the conversion of the model, and FromString. The function is kept for future reference. | |||
48 | // | |||
49 | static openapi_petstore_findPetsByStatus_status_e findPetsByStatus_STATUS_parseFromJSON(cJSON* STATUSJSON) { | |||
50 | openapi_petstore_findPetsByStatus_status_e STATUSVariable = 0; | |||
51 | return STATUSVariable; | |||
52 | end: | |||
53 | return 0; | |||
54 | } | |||
55 | */ | |||
56 | ||||
57 | ||||
58 | // Add a new pet to the store | |||
59 | // | |||
60 | void | |||
61 | PetAPI_addPet(apiClient_t *apiClient, pet_t * body ) | |||
62 | { | |||
63 | list_t *localVarQueryParameters = NULL((void*)0); | |||
64 | list_t *localVarHeaderParameters = NULL((void*)0); | |||
65 | list_t *localVarFormParameters = NULL((void*)0); | |||
66 | list_t *localVarHeaderType = NULL((void*)0); | |||
67 | list_t *localVarContentType = list_create(); | |||
68 | char *localVarBodyParameters = NULL((void*)0); | |||
69 | ||||
70 | // create the path | |||
71 | long sizeOfPath = strlen("/pet")+1; | |||
72 | char *localVarPath = malloc(sizeOfPath); | |||
73 | snprintf(localVarPath, sizeOfPath, "/pet"); | |||
74 | ||||
75 | ||||
76 | ||||
77 | ||||
78 | // Body Param | |||
79 | cJSON *localVarSingleItemJSON_body = NULL((void*)0); | |||
80 | if (body != NULL((void*)0)) | |||
81 | { | |||
82 | //string | |||
83 | localVarSingleItemJSON_body = pet_convertToJSON(body); | |||
84 | localVarBodyParameters = cJSON_Print(localVarSingleItemJSON_body); | |||
85 | } | |||
86 | list_addElement(localVarContentType,"application/json"); //consumes | |||
87 | list_addElement(localVarContentType,"application/xml"); //consumes | |||
88 | apiClient_invoke(apiClient, | |||
89 | localVarPath, | |||
90 | localVarQueryParameters, | |||
91 | localVarHeaderParameters, | |||
92 | localVarFormParameters, | |||
93 | localVarHeaderType, | |||
94 | localVarContentType, | |||
95 | localVarBodyParameters, | |||
96 | "POST"); | |||
97 | ||||
98 | if (apiClient->response_code == 405) { | |||
99 | printf("%s\n","Invalid input"); | |||
100 | } | |||
101 | //No return type | |||
102 | end: | |||
103 | if (apiClient->dataReceived) { | |||
104 | free(apiClient->dataReceived); | |||
105 | apiClient->dataReceived = NULL((void*)0); | |||
106 | apiClient->dataReceivedLen = 0; | |||
107 | } | |||
108 | ||||
109 | ||||
110 | ||||
111 | ||||
112 | list_free(localVarContentType); | |||
113 | free(localVarPath); | |||
114 | if (localVarSingleItemJSON_body) { | |||
115 | cJSON_Delete(localVarSingleItemJSON_body); | |||
116 | localVarSingleItemJSON_body = NULL((void*)0); | |||
117 | } | |||
118 | free(localVarBodyParameters); | |||
119 | ||||
120 | } | |||
121 | ||||
122 | // Deletes a pet | |||
123 | // | |||
124 | void | |||
125 | PetAPI_deletePet(apiClient_t *apiClient, long petId , char * api_key ) | |||
126 | { | |||
127 | list_t *localVarQueryParameters = NULL((void*)0); | |||
128 | list_t *localVarHeaderParameters = list_create(); | |||
129 | list_t *localVarFormParameters = NULL((void*)0); | |||
130 | list_t *localVarHeaderType = NULL((void*)0); | |||
131 | list_t *localVarContentType = NULL((void*)0); | |||
132 | char *localVarBodyParameters = NULL((void*)0); | |||
133 | ||||
134 | // create the path | |||
135 | long sizeOfPath = strlen("/pet/{petId}")+1; | |||
136 | char *localVarPath = malloc(sizeOfPath); | |||
137 | snprintf(localVarPath, sizeOfPath, "/pet/{petId}"); | |||
138 | ||||
139 | ||||
140 | // Path Params | |||
141 | long sizeOfPathParams_petId = sizeof(petId)+3 + strlen("{ petId }"); | |||
142 | if(petId == 0){ | |||
143 | goto end; | |||
144 | } | |||
145 | char* localVarToReplace_petId = malloc(sizeOfPathParams_petId); | |||
146 | snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); | |||
147 | ||||
148 | char localVarBuff_petId[256]; | |||
149 | intToStr(localVarBuff_petId, petId)do { char localVarBuff_petId[256]; snprintf(localVarBuff_petId , 256, "%ld", (long int)(petId));}while(0); | |||
150 | ||||
151 | localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); | |||
152 | ||||
153 | ||||
154 | ||||
155 | ||||
156 | // header parameters | |||
157 | char *keyHeader_api_key = NULL((void*)0); | |||
158 | char * valueHeader_api_key = 0; | |||
159 | keyValuePair_t *keyPairHeader_api_key = 0; | |||
160 | if (api_key) { | |||
161 | keyHeader_api_key = strdup("api_key"); | |||
162 | valueHeader_api_key = strdup((api_key)); | |||
163 | keyPairHeader_api_key = keyValuePair_create(keyHeader_api_key, valueHeader_api_key); | |||
164 | list_addElement(localVarHeaderParameters,keyPairHeader_api_key); | |||
165 | } | |||
166 | ||||
167 | apiClient_invoke(apiClient, | |||
168 | localVarPath, | |||
169 | localVarQueryParameters, | |||
170 | localVarHeaderParameters, | |||
171 | localVarFormParameters, | |||
172 | localVarHeaderType, | |||
173 | localVarContentType, | |||
174 | localVarBodyParameters, | |||
175 | "DELETE"); | |||
176 | ||||
177 | if (apiClient->response_code == 400) { | |||
178 | printf("%s\n","Invalid pet value"); | |||
179 | } | |||
180 | //No return type | |||
181 | end: | |||
182 | if (apiClient->dataReceived) { | |||
183 | free(apiClient->dataReceived); | |||
184 | apiClient->dataReceived = NULL((void*)0); | |||
185 | apiClient->dataReceivedLen = 0; | |||
186 | } | |||
187 | ||||
188 | list_free(localVarHeaderParameters); | |||
189 | ||||
190 | ||||
191 | ||||
192 | free(localVarPath); | |||
193 | free(localVarToReplace_petId); | |||
194 | if (keyHeader_api_key) { | |||
195 | free(keyHeader_api_key); | |||
196 | keyHeader_api_key = NULL((void*)0); | |||
197 | } | |||
198 | if (valueHeader_api_key) { | |||
199 | free(valueHeader_api_key); | |||
200 | valueHeader_api_key = NULL((void*)0); | |||
201 | } | |||
202 | free(keyPairHeader_api_key); | |||
203 | ||||
204 | } | |||
205 | ||||
206 | // Finds Pets by status | |||
207 | // | |||
208 | // Multiple status values can be provided with comma separated strings | |||
209 | // | |||
210 | list_t* | |||
211 | PetAPI_findPetsByStatus(apiClient_t *apiClient, list_t * status ) | |||
212 | { | |||
213 | list_t *localVarQueryParameters = list_create(); | |||
214 | list_t *localVarHeaderParameters = NULL((void*)0); | |||
215 | list_t *localVarFormParameters = NULL((void*)0); | |||
216 | list_t *localVarHeaderType = list_create(); | |||
217 | list_t *localVarContentType = NULL((void*)0); | |||
218 | char *localVarBodyParameters = NULL((void*)0); | |||
219 | ||||
220 | // create the path | |||
221 | long sizeOfPath = strlen("/pet/findByStatus")+1; | |||
222 | char *localVarPath = malloc(sizeOfPath); | |||
223 | snprintf(localVarPath, sizeOfPath, "/pet/findByStatus"); | |||
224 | ||||
225 | ||||
226 | ||||
227 | ||||
228 | // query parameters | |||
229 | if (status) | |||
230 | { | |||
231 | list_addElement(localVarQueryParameters,status); | |||
232 | } | |||
233 | list_addElement(localVarHeaderType,"application/xml"); //produces | |||
234 | list_addElement(localVarHeaderType,"application/json"); //produces | |||
235 | apiClient_invoke(apiClient, | |||
236 | localVarPath, | |||
237 | localVarQueryParameters, | |||
238 | localVarHeaderParameters, | |||
239 | localVarFormParameters, | |||
240 | localVarHeaderType, | |||
241 | localVarContentType, | |||
242 | localVarBodyParameters, | |||
243 | "GET"); | |||
244 | ||||
245 | if (apiClient->response_code == 200) { | |||
246 | printf("%s\n","successful operation"); | |||
247 | } | |||
248 | if (apiClient->response_code == 400) { | |||
249 | printf("%s\n","Invalid status value"); | |||
250 | } | |||
251 | cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); | |||
252 | if(!cJSON_IsArray(PetAPIlocalVarJSON)) { | |||
253 | return 0;//nonprimitive container | |||
254 | } | |||
255 | list_t *elementToReturn = list_create(); | |||
256 | cJSON *VarJSON; | |||
257 | cJSON_ArrayForEach(VarJSON, PetAPIlocalVarJSON)for(VarJSON = (PetAPIlocalVarJSON != ((void*)0)) ? (PetAPIlocalVarJSON )->child : ((void*)0); VarJSON != ((void*)0); VarJSON = VarJSON ->next) | |||
258 | { | |||
259 | if(!cJSON_IsObject(VarJSON)) | |||
260 | { | |||
261 | // return 0; | |||
262 | } | |||
263 | char *localVarJSONToChar = cJSON_Print(VarJSON); | |||
264 | list_addElement(elementToReturn , localVarJSONToChar); | |||
265 | } | |||
266 | ||||
267 | cJSON_Delete( PetAPIlocalVarJSON); | |||
268 | cJSON_Delete( VarJSON); | |||
269 | //return type | |||
270 | if (apiClient->dataReceived) { | |||
271 | free(apiClient->dataReceived); | |||
272 | apiClient->dataReceived = NULL((void*)0); | |||
273 | apiClient->dataReceivedLen = 0; | |||
274 | } | |||
275 | list_free(localVarQueryParameters); | |||
276 | ||||
277 | ||||
278 | list_free(localVarHeaderType); | |||
279 | ||||
280 | free(localVarPath); | |||
281 | return elementToReturn; | |||
282 | end: | |||
283 | free(localVarPath); | |||
284 | return NULL((void*)0); | |||
285 | ||||
286 | } | |||
287 | ||||
288 | // Finds Pets by tags | |||
289 | // | |||
290 | // Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. | |||
291 | // | |||
292 | list_t* | |||
293 | PetAPI_findPetsByTags(apiClient_t *apiClient, list_t * tags ) | |||
294 | { | |||
295 | list_t *localVarQueryParameters = list_create(); | |||
296 | list_t *localVarHeaderParameters = NULL((void*)0); | |||
297 | list_t *localVarFormParameters = NULL((void*)0); | |||
298 | list_t *localVarHeaderType = list_create(); | |||
299 | list_t *localVarContentType = NULL((void*)0); | |||
300 | char *localVarBodyParameters = NULL((void*)0); | |||
301 | ||||
302 | // create the path | |||
303 | long sizeOfPath = strlen("/pet/findByTags")+1; | |||
304 | char *localVarPath = malloc(sizeOfPath); | |||
305 | snprintf(localVarPath, sizeOfPath, "/pet/findByTags"); | |||
306 | ||||
307 | ||||
308 | ||||
309 | ||||
310 | // query parameters | |||
311 | if (tags) | |||
312 | { | |||
313 | list_addElement(localVarQueryParameters,tags); | |||
314 | } | |||
315 | list_addElement(localVarHeaderType,"application/xml"); //produces | |||
316 | list_addElement(localVarHeaderType,"application/json"); //produces | |||
317 | apiClient_invoke(apiClient, | |||
318 | localVarPath, | |||
319 | localVarQueryParameters, | |||
320 | localVarHeaderParameters, | |||
321 | localVarFormParameters, | |||
322 | localVarHeaderType, | |||
323 | localVarContentType, | |||
324 | localVarBodyParameters, | |||
325 | "GET"); | |||
326 | ||||
327 | if (apiClient->response_code == 200) { | |||
328 | printf("%s\n","successful operation"); | |||
329 | } | |||
330 | if (apiClient->response_code == 400) { | |||
331 | printf("%s\n","Invalid tag value"); | |||
332 | } | |||
333 | cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); | |||
334 | if(!cJSON_IsArray(PetAPIlocalVarJSON)) { | |||
335 | return 0;//nonprimitive container | |||
336 | } | |||
337 | list_t *elementToReturn = list_create(); | |||
338 | cJSON *VarJSON; | |||
339 | cJSON_ArrayForEach(VarJSON, PetAPIlocalVarJSON)for(VarJSON = (PetAPIlocalVarJSON != ((void*)0)) ? (PetAPIlocalVarJSON )->child : ((void*)0); VarJSON != ((void*)0); VarJSON = VarJSON ->next) | |||
340 | { | |||
341 | if(!cJSON_IsObject(VarJSON)) | |||
342 | { | |||
343 | // return 0; | |||
344 | } | |||
345 | char *localVarJSONToChar = cJSON_Print(VarJSON); | |||
346 | list_addElement(elementToReturn , localVarJSONToChar); | |||
347 | } | |||
348 | ||||
349 | cJSON_Delete( PetAPIlocalVarJSON); | |||
350 | cJSON_Delete( VarJSON); | |||
351 | //return type | |||
352 | if (apiClient->dataReceived) { | |||
353 | free(apiClient->dataReceived); | |||
354 | apiClient->dataReceived = NULL((void*)0); | |||
355 | apiClient->dataReceivedLen = 0; | |||
356 | } | |||
357 | list_free(localVarQueryParameters); | |||
358 | ||||
359 | ||||
360 | list_free(localVarHeaderType); | |||
361 | ||||
362 | free(localVarPath); | |||
363 | return elementToReturn; | |||
364 | end: | |||
365 | free(localVarPath); | |||
366 | return NULL((void*)0); | |||
367 | ||||
368 | } | |||
369 | ||||
370 | // Find pet by ID | |||
371 | // | |||
372 | // Returns a single pet | |||
373 | // | |||
374 | pet_t* | |||
375 | PetAPI_getPetById(apiClient_t *apiClient, long petId ) | |||
376 | { | |||
377 | list_t *localVarQueryParameters = NULL((void*)0); | |||
378 | list_t *localVarHeaderParameters = NULL((void*)0); | |||
379 | list_t *localVarFormParameters = NULL((void*)0); | |||
380 | list_t *localVarHeaderType = list_create(); | |||
381 | list_t *localVarContentType = NULL((void*)0); | |||
382 | char *localVarBodyParameters = NULL((void*)0); | |||
383 | ||||
384 | // create the path | |||
385 | long sizeOfPath = strlen("/pet/{petId}")+1; | |||
386 | char *localVarPath = malloc(sizeOfPath); | |||
387 | snprintf(localVarPath, sizeOfPath, "/pet/{petId}"); | |||
388 | ||||
389 | ||||
390 | // Path Params | |||
391 | long sizeOfPathParams_petId = sizeof(petId)+3 + strlen("{ petId }"); | |||
392 | if(petId == 0){ | |||
393 | goto end; | |||
394 | } | |||
395 | char* localVarToReplace_petId = malloc(sizeOfPathParams_petId); | |||
396 | snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); | |||
397 | ||||
398 | char localVarBuff_petId[256]; | |||
399 | intToStr(localVarBuff_petId, petId)do { char localVarBuff_petId[256]; snprintf(localVarBuff_petId , 256, "%ld", (long int)(petId));}while(0); | |||
400 | ||||
401 | localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); | |||
402 | ||||
403 | ||||
404 | ||||
405 | list_addElement(localVarHeaderType,"application/xml"); //produces | |||
406 | list_addElement(localVarHeaderType,"application/json"); //produces | |||
407 | apiClient_invoke(apiClient, | |||
408 | localVarPath, | |||
409 | localVarQueryParameters, | |||
410 | localVarHeaderParameters, | |||
411 | localVarFormParameters, | |||
412 | localVarHeaderType, | |||
413 | localVarContentType, | |||
414 | localVarBodyParameters, | |||
415 | "GET"); | |||
416 | ||||
417 | if (apiClient->response_code == 200) { | |||
418 | printf("%s\n","successful operation"); | |||
419 | } | |||
420 | if (apiClient->response_code == 400) { | |||
421 | printf("%s\n","Invalid ID supplied"); | |||
422 | } | |||
423 | if (apiClient->response_code == 404) { | |||
424 | printf("%s\n","Pet not found"); | |||
425 | } | |||
426 | //nonprimitive not container | |||
427 | cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); | |||
428 | pet_t *elementToReturn = pet_parseFromJSON(PetAPIlocalVarJSON); | |||
429 | cJSON_Delete(PetAPIlocalVarJSON); | |||
430 | if(elementToReturn == NULL((void*)0)) { | |||
431 | // return 0; | |||
432 | } | |||
433 | ||||
434 | //return type | |||
435 | if (apiClient->dataReceived) { | |||
436 | free(apiClient->dataReceived); | |||
437 | apiClient->dataReceived = NULL((void*)0); | |||
438 | apiClient->dataReceivedLen = 0; | |||
439 | } | |||
440 | ||||
441 | ||||
442 | ||||
443 | list_free(localVarHeaderType); | |||
444 | ||||
445 | free(localVarPath); | |||
446 | free(localVarToReplace_petId); | |||
447 | return elementToReturn; | |||
448 | end: | |||
449 | free(localVarPath); | |||
450 | return NULL((void*)0); | |||
451 | ||||
452 | } | |||
453 | ||||
454 | // Update an existing pet | |||
455 | // | |||
456 | void | |||
457 | PetAPI_updatePet(apiClient_t *apiClient, pet_t * body ) | |||
458 | { | |||
459 | list_t *localVarQueryParameters = NULL((void*)0); | |||
460 | list_t *localVarHeaderParameters = NULL((void*)0); | |||
461 | list_t *localVarFormParameters = NULL((void*)0); | |||
462 | list_t *localVarHeaderType = NULL((void*)0); | |||
463 | list_t *localVarContentType = list_create(); | |||
464 | char *localVarBodyParameters = NULL((void*)0); | |||
465 | ||||
466 | // create the path | |||
467 | long sizeOfPath = strlen("/pet")+1; | |||
468 | char *localVarPath = malloc(sizeOfPath); | |||
469 | snprintf(localVarPath, sizeOfPath, "/pet"); | |||
470 | ||||
471 | ||||
472 | ||||
473 | ||||
474 | // Body Param | |||
475 | cJSON *localVarSingleItemJSON_body = NULL((void*)0); | |||
476 | if (body != NULL((void*)0)) | |||
477 | { | |||
478 | //string | |||
479 | localVarSingleItemJSON_body = pet_convertToJSON(body); | |||
480 | localVarBodyParameters = cJSON_Print(localVarSingleItemJSON_body); | |||
481 | } | |||
482 | list_addElement(localVarContentType,"application/json"); //consumes | |||
483 | list_addElement(localVarContentType,"application/xml"); //consumes | |||
484 | apiClient_invoke(apiClient, | |||
485 | localVarPath, | |||
486 | localVarQueryParameters, | |||
487 | localVarHeaderParameters, | |||
488 | localVarFormParameters, | |||
489 | localVarHeaderType, | |||
490 | localVarContentType, | |||
491 | localVarBodyParameters, | |||
492 | "PUT"); | |||
493 | ||||
494 | if (apiClient->response_code == 400) { | |||
495 | printf("%s\n","Invalid ID supplied"); | |||
496 | } | |||
497 | if (apiClient->response_code == 404) { | |||
498 | printf("%s\n","Pet not found"); | |||
499 | } | |||
500 | if (apiClient->response_code == 405) { | |||
501 | printf("%s\n","Validation exception"); | |||
502 | } | |||
503 | //No return type | |||
504 | end: | |||
505 | if (apiClient->dataReceived) { | |||
506 | free(apiClient->dataReceived); | |||
507 | apiClient->dataReceived = NULL((void*)0); | |||
508 | apiClient->dataReceivedLen = 0; | |||
509 | } | |||
510 | ||||
511 | ||||
512 | ||||
513 | ||||
514 | list_free(localVarContentType); | |||
515 | free(localVarPath); | |||
516 | if (localVarSingleItemJSON_body) { | |||
517 | cJSON_Delete(localVarSingleItemJSON_body); | |||
518 | localVarSingleItemJSON_body = NULL((void*)0); | |||
519 | } | |||
520 | free(localVarBodyParameters); | |||
521 | ||||
522 | } | |||
523 | ||||
524 | // Updates a pet in the store with form data | |||
525 | // | |||
526 | void | |||
527 | PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId , char * name , char * status ) | |||
528 | { | |||
529 | list_t *localVarQueryParameters = NULL((void*)0); | |||
530 | list_t *localVarHeaderParameters = NULL((void*)0); | |||
531 | list_t *localVarFormParameters = list_create(); | |||
532 | list_t *localVarHeaderType = NULL((void*)0); | |||
533 | list_t *localVarContentType = list_create(); | |||
534 | char *localVarBodyParameters = NULL((void*)0); | |||
535 | ||||
536 | // create the path | |||
537 | long sizeOfPath = strlen("/pet/{petId}")+1; | |||
538 | char *localVarPath = malloc(sizeOfPath); | |||
539 | snprintf(localVarPath, sizeOfPath, "/pet/{petId}"); | |||
540 | ||||
541 | ||||
542 | // Path Params | |||
543 | long sizeOfPathParams_petId = sizeof(petId)+3 + strlen("{ petId }"); | |||
544 | if(petId == 0){ | |||
| ||||
545 | goto end; | |||
546 | } | |||
547 | char* localVarToReplace_petId = malloc(sizeOfPathParams_petId); | |||
548 | snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); | |||
549 | ||||
550 | char localVarBuff_petId[256]; | |||
551 | intToStr(localVarBuff_petId, petId)do { char localVarBuff_petId[256]; snprintf(localVarBuff_petId , 256, "%ld", (long int)(petId));}while(0); | |||
552 | ||||
553 | localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); | |||
554 | ||||
555 | ||||
556 | ||||
557 | ||||
558 | // form parameters | |||
559 | char *keyForm_name = NULL((void*)0); | |||
560 | char * valueForm_name = 0; | |||
561 | keyValuePair_t *keyPairForm_name = 0; | |||
562 | if (name != NULL((void*)0)) | |||
563 | { | |||
564 | keyForm_name = strdup("name"); | |||
565 | valueForm_name = strdup((name)); | |||
566 | keyPairForm_name = keyValuePair_create(keyForm_name,valueForm_name); | |||
567 | list_addElement(localVarFormParameters,keyPairForm_name); | |||
568 | } | |||
569 | ||||
570 | // form parameters | |||
571 | char *keyForm_status = NULL((void*)0); | |||
572 | char * valueForm_status = 0; | |||
573 | keyValuePair_t *keyPairForm_status = 0; | |||
574 | if (status != NULL((void*)0)) | |||
575 | { | |||
576 | keyForm_status = strdup("status"); | |||
577 | valueForm_status = strdup((status)); | |||
578 | keyPairForm_status = keyValuePair_create(keyForm_status,valueForm_status); | |||
579 | list_addElement(localVarFormParameters,keyPairForm_status); | |||
580 | } | |||
581 | list_addElement(localVarContentType,"application/x-www-form-urlencoded"); //consumes | |||
582 | apiClient_invoke(apiClient, | |||
583 | localVarPath, | |||
584 | localVarQueryParameters, | |||
585 | localVarHeaderParameters, | |||
586 | localVarFormParameters, | |||
587 | localVarHeaderType, | |||
588 | localVarContentType, | |||
589 | localVarBodyParameters, | |||
590 | "POST"); | |||
591 | ||||
592 | if (apiClient->response_code == 405) { | |||
593 | printf("%s\n","Invalid input"); | |||
594 | } | |||
595 | //No return type | |||
596 | end: | |||
597 | if (apiClient->dataReceived) { | |||
598 | free(apiClient->dataReceived); | |||
599 | apiClient->dataReceived = NULL((void*)0); | |||
600 | apiClient->dataReceivedLen = 0; | |||
601 | } | |||
602 | ||||
603 | ||||
604 | list_free(localVarFormParameters); | |||
605 | ||||
606 | list_free(localVarContentType); | |||
607 | free(localVarPath); | |||
608 | free(localVarToReplace_petId); | |||
| ||||
609 | if (keyForm_name) { | |||
610 | free(keyForm_name); | |||
611 | keyForm_name = NULL((void*)0); | |||
612 | } | |||
613 | if (valueForm_name) { | |||
614 | free(valueForm_name); | |||
615 | valueForm_name = NULL((void*)0); | |||
616 | } | |||
617 | keyValuePair_free(keyPairForm_name); | |||
618 | if (keyForm_status) { | |||
619 | free(keyForm_status); | |||
620 | keyForm_status = NULL((void*)0); | |||
621 | } | |||
622 | if (valueForm_status) { | |||
623 | free(valueForm_status); | |||
624 | valueForm_status = NULL((void*)0); | |||
625 | } | |||
626 | keyValuePair_free(keyPairForm_status); | |||
627 | ||||
628 | } | |||
629 | ||||
630 | // uploads an image | |||
631 | // | |||
632 | api_response_t* | |||
633 | PetAPI_uploadFile(apiClient_t *apiClient, long petId , char * additionalMetadata , binary_t* file ) | |||
634 | { | |||
635 | list_t *localVarQueryParameters = NULL((void*)0); | |||
636 | list_t *localVarHeaderParameters = NULL((void*)0); | |||
637 | list_t *localVarFormParameters = list_create(); | |||
638 | list_t *localVarHeaderType = list_create(); | |||
639 | list_t *localVarContentType = list_create(); | |||
640 | char *localVarBodyParameters = NULL((void*)0); | |||
641 | ||||
642 | // create the path | |||
643 | long sizeOfPath = strlen("/pet/{petId}/uploadImage")+1; | |||
644 | char *localVarPath = malloc(sizeOfPath); | |||
645 | snprintf(localVarPath, sizeOfPath, "/pet/{petId}/uploadImage"); | |||
646 | ||||
647 | ||||
648 | // Path Params | |||
649 | long sizeOfPathParams_petId = sizeof(petId)+3 + strlen("{ petId }"); | |||
650 | if(petId == 0){ | |||
651 | goto end; | |||
652 | } | |||
653 | char* localVarToReplace_petId = malloc(sizeOfPathParams_petId); | |||
654 | snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); | |||
655 | ||||
656 | char localVarBuff_petId[256]; | |||
657 | intToStr(localVarBuff_petId, petId)do { char localVarBuff_petId[256]; snprintf(localVarBuff_petId , 256, "%ld", (long int)(petId));}while(0); | |||
658 | ||||
659 | localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); | |||
660 | ||||
661 | ||||
662 | ||||
663 | ||||
664 | // form parameters | |||
665 | char *keyForm_additionalMetadata = NULL((void*)0); | |||
666 | char * valueForm_additionalMetadata = 0; | |||
667 | keyValuePair_t *keyPairForm_additionalMetadata = 0; | |||
668 | if (additionalMetadata != NULL((void*)0)) | |||
669 | { | |||
670 | keyForm_additionalMetadata = strdup("additionalMetadata"); | |||
671 | valueForm_additionalMetadata = strdup((additionalMetadata)); | |||
672 | keyPairForm_additionalMetadata = keyValuePair_create(keyForm_additionalMetadata,valueForm_additionalMetadata); | |||
673 | list_addElement(localVarFormParameters,keyPairForm_additionalMetadata); | |||
674 | } | |||
675 | ||||
676 | // form parameters | |||
677 | char *keyForm_file = NULL((void*)0); | |||
678 | binary_t* valueForm_file = 0; | |||
679 | keyValuePair_t *keyPairForm_file = 0; | |||
680 | if (file != NULL((void*)0)) | |||
681 | { | |||
682 | keyForm_file = strdup("file"); | |||
683 | valueForm_file = file; | |||
684 | keyPairForm_file = keyValuePair_create(keyForm_file, &valueForm_file); | |||
685 | list_addElement(localVarFormParameters,keyPairForm_file); //file adding | |||
686 | } | |||
687 | list_addElement(localVarHeaderType,"application/json"); //produces | |||
688 | list_addElement(localVarContentType,"multipart/form-data"); //consumes | |||
689 | apiClient_invoke(apiClient, | |||
690 | localVarPath, | |||
691 | localVarQueryParameters, | |||
692 | localVarHeaderParameters, | |||
693 | localVarFormParameters, | |||
694 | localVarHeaderType, | |||
695 | localVarContentType, | |||
696 | localVarBodyParameters, | |||
697 | "POST"); | |||
698 | ||||
699 | if (apiClient->response_code == 200) { | |||
700 | printf("%s\n","successful operation"); | |||
701 | } | |||
702 | //nonprimitive not container | |||
703 | cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); | |||
704 | api_response_t *elementToReturn = api_response_parseFromJSON(PetAPIlocalVarJSON); | |||
705 | cJSON_Delete(PetAPIlocalVarJSON); | |||
706 | if(elementToReturn == NULL((void*)0)) { | |||
707 | // return 0; | |||
708 | } | |||
709 | ||||
710 | //return type | |||
711 | if (apiClient->dataReceived) { | |||
712 | free(apiClient->dataReceived); | |||
713 | apiClient->dataReceived = NULL((void*)0); | |||
714 | apiClient->dataReceivedLen = 0; | |||
715 | } | |||
716 | ||||
717 | ||||
718 | list_free(localVarFormParameters); | |||
719 | list_free(localVarHeaderType); | |||
720 | list_free(localVarContentType); | |||
721 | free(localVarPath); | |||
722 | free(localVarToReplace_petId); | |||
723 | if (keyForm_additionalMetadata) { | |||
724 | free(keyForm_additionalMetadata); | |||
725 | keyForm_additionalMetadata = NULL((void*)0); | |||
726 | } | |||
727 | if (valueForm_additionalMetadata) { | |||
728 | free(valueForm_additionalMetadata); | |||
729 | valueForm_additionalMetadata = NULL((void*)0); | |||
730 | } | |||
731 | free(keyPairForm_additionalMetadata); | |||
732 | if (keyForm_file) { | |||
733 | free(keyForm_file); | |||
734 | keyForm_file = NULL((void*)0); | |||
735 | } | |||
736 | // free(fileVar_file->data); | |||
737 | // free(fileVar_file); | |||
738 | free(keyPairForm_file); | |||
739 | return elementToReturn; | |||
740 | end: | |||
741 | free(localVarPath); | |||
742 | return NULL((void*)0); | |||
743 | ||||
744 | } | |||
745 |