forked from loafle/openapi-generator-original
* [C][Client] Remove redundant casts Don't explicitly cast void pointers as it's unnecessary in C, but leave printf arguments untouched to avoid setting off -Wformat. * [C][Client] Cosmetic: remove unnecessary parens, align some lines * [C][Client] Reduce number of unnecessary strlen() calls
607 lines
18 KiB
C
607 lines
18 KiB
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <ctype.h>
|
|
#include "StoreAPI.h"
|
|
|
|
#define MAX_NUMBER_LENGTH 16
|
|
#define MAX_BUFFER_LENGTH 4096
|
|
|
|
// Functions for enum RATING for StoreAPI_sendRating
|
|
|
|
static char* sendRating_RATING_ToString(openapi_petstore_sendRating_rating_e RATING){
|
|
char *RATINGArray[] = { "NULL", "Excellent", "Great", "Good", "Regular", "Bad", "Awful" };
|
|
return RATINGArray[RATING];
|
|
}
|
|
|
|
static openapi_petstore_sendRating_rating_e sendRating_RATING_FromString(char* RATING){
|
|
int stringToReturn = 0;
|
|
char *RATINGArray[] = { "NULL", "Excellent", "Great", "Good", "Regular", "Bad", "Awful" };
|
|
size_t sizeofArray = sizeof(RATINGArray) / sizeof(RATINGArray[0]);
|
|
while(stringToReturn < sizeofArray) {
|
|
if(strcmp(RATING, RATINGArray[stringToReturn]) == 0) {
|
|
return stringToReturn;
|
|
}
|
|
stringToReturn++;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
// Function sendRating_RATING_convertToJSON is not currently used,
|
|
// since conversion to JSON passes through the conversion of the model, and ToString. The function is kept for future reference.
|
|
//
|
|
static cJSON *sendRating_RATING_convertToJSON(openapi_petstore_sendRating_rating_e RATING) {
|
|
cJSON *item = cJSON_CreateObject();
|
|
if(cJSON_AddStringToObject(item, "rating", sendRating_RATING_ToString(RATING)) == NULL) {
|
|
goto fail;
|
|
}
|
|
return item;
|
|
fail:
|
|
cJSON_Delete(item);
|
|
return NULL;
|
|
}
|
|
|
|
// Function sendRating_RATING_parseFromJSON is not currently used,
|
|
// since conversion from JSON passes through the conversion of the model, and FromString. The function is kept for future reference.
|
|
//
|
|
static openapi_petstore_sendRating_rating_e sendRating_RATING_parseFromJSON(cJSON* RATINGJSON) {
|
|
openapi_petstore_sendRating_rating_e RATINGVariable = 0;
|
|
cJSON *RATINGVar = cJSON_GetObjectItemCaseSensitive(RATINGJSON, "rating");
|
|
if(!cJSON_IsString(RATINGVar) || (RATINGVar->valuestring == NULL))
|
|
{
|
|
goto end;
|
|
}
|
|
RATINGVariable = sendRating_RATING_FromString(RATINGVar->valuestring);
|
|
return RATINGVariable;
|
|
end:
|
|
return 0;
|
|
}
|
|
*/
|
|
|
|
|
|
// Delete purchase order by ID
|
|
//
|
|
// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
|
//
|
|
void
|
|
StoreAPI_deleteOrder(apiClient_t *apiClient, char *orderId)
|
|
{
|
|
list_t *localVarQueryParameters = NULL;
|
|
list_t *localVarHeaderParameters = NULL;
|
|
list_t *localVarFormParameters = NULL;
|
|
list_t *localVarHeaderType = NULL;
|
|
list_t *localVarContentType = NULL;
|
|
char *localVarBodyParameters = NULL;
|
|
size_t localVarBodyLength = 0;
|
|
|
|
// clear the error code from the previous api call
|
|
apiClient->response_code = 0;
|
|
|
|
// create the path
|
|
char *localVarPath = strdup("/store/order/{orderId}");
|
|
|
|
if(!orderId)
|
|
goto end;
|
|
|
|
|
|
// Path Params
|
|
long sizeOfPathParams_orderId = strlen(orderId)+3 + sizeof("{ orderId }") - 1;
|
|
if(orderId == NULL) {
|
|
goto end;
|
|
}
|
|
char* localVarToReplace_orderId = malloc(sizeOfPathParams_orderId);
|
|
sprintf(localVarToReplace_orderId, "{%s}", "orderId");
|
|
|
|
localVarPath = strReplace(localVarPath, localVarToReplace_orderId, orderId);
|
|
|
|
|
|
apiClient_invoke(apiClient,
|
|
localVarPath,
|
|
localVarQueryParameters,
|
|
localVarHeaderParameters,
|
|
localVarFormParameters,
|
|
localVarHeaderType,
|
|
localVarContentType,
|
|
localVarBodyParameters,
|
|
localVarBodyLength,
|
|
"DELETE");
|
|
|
|
// uncomment below to debug the error response
|
|
//if (apiClient->response_code == 400) {
|
|
// printf("%s\n","Invalid ID supplied");
|
|
//}
|
|
// uncomment below to debug the error response
|
|
//if (apiClient->response_code == 404) {
|
|
// printf("%s\n","Order not found");
|
|
//}
|
|
//No return type
|
|
end:
|
|
if (apiClient->dataReceived) {
|
|
free(apiClient->dataReceived);
|
|
apiClient->dataReceived = NULL;
|
|
apiClient->dataReceivedLen = 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
free(localVarPath);
|
|
free(localVarToReplace_orderId);
|
|
|
|
}
|
|
|
|
// Returns pet inventories by status
|
|
//
|
|
// Returns a map of status codes to quantities
|
|
//
|
|
list_t*
|
|
StoreAPI_getInventory(apiClient_t *apiClient)
|
|
{
|
|
list_t *localVarQueryParameters = NULL;
|
|
list_t *localVarHeaderParameters = NULL;
|
|
list_t *localVarFormParameters = NULL;
|
|
list_t *localVarHeaderType = list_createList();
|
|
list_t *localVarContentType = NULL;
|
|
char *localVarBodyParameters = NULL;
|
|
size_t localVarBodyLength = 0;
|
|
|
|
// clear the error code from the previous api call
|
|
apiClient->response_code = 0;
|
|
|
|
// create the path
|
|
char *localVarPath = strdup("/store/inventory");
|
|
|
|
|
|
|
|
|
|
list_addElement(localVarHeaderType,"application/json"); //produces
|
|
apiClient_invoke(apiClient,
|
|
localVarPath,
|
|
localVarQueryParameters,
|
|
localVarHeaderParameters,
|
|
localVarFormParameters,
|
|
localVarHeaderType,
|
|
localVarContentType,
|
|
localVarBodyParameters,
|
|
localVarBodyLength,
|
|
"GET");
|
|
|
|
// uncomment below to debug the error response
|
|
//if (apiClient->response_code == 200) {
|
|
// printf("%s\n","successful operation");
|
|
//}
|
|
//primitive return type not simple
|
|
list_t *elementToReturn = NULL;
|
|
if(apiClient->response_code >= 200 && apiClient->response_code < 300) {
|
|
cJSON *localVarJSON = cJSON_Parse(apiClient->dataReceived);
|
|
cJSON *VarJSON;
|
|
elementToReturn = list_createList();
|
|
cJSON_ArrayForEach(VarJSON, localVarJSON){
|
|
keyValuePair_t *keyPair = keyValuePair_create(strdup(VarJSON->string), cJSON_Print(VarJSON));
|
|
list_addElement(elementToReturn, keyPair);
|
|
}
|
|
cJSON_Delete(localVarJSON);
|
|
}
|
|
|
|
if (apiClient->dataReceived) {
|
|
free(apiClient->dataReceived);
|
|
apiClient->dataReceived = NULL;
|
|
apiClient->dataReceivedLen = 0;
|
|
}
|
|
|
|
|
|
|
|
list_freeList(localVarHeaderType);
|
|
|
|
free(localVarPath);
|
|
return elementToReturn;
|
|
end:
|
|
free(localVarPath);
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// Find purchase order by ID
|
|
//
|
|
// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions
|
|
//
|
|
order_t*
|
|
StoreAPI_getOrderById(apiClient_t *apiClient, long orderId)
|
|
{
|
|
list_t *localVarQueryParameters = NULL;
|
|
list_t *localVarHeaderParameters = NULL;
|
|
list_t *localVarFormParameters = NULL;
|
|
list_t *localVarHeaderType = list_createList();
|
|
list_t *localVarContentType = NULL;
|
|
char *localVarBodyParameters = NULL;
|
|
size_t localVarBodyLength = 0;
|
|
|
|
// clear the error code from the previous api call
|
|
apiClient->response_code = 0;
|
|
|
|
// create the path
|
|
char *localVarPath = strdup("/store/order/{orderId}");
|
|
|
|
|
|
|
|
// Path Params
|
|
long sizeOfPathParams_orderId = sizeof(orderId)+3 + sizeof("{ orderId }") - 1;
|
|
if(orderId == 0){
|
|
goto end;
|
|
}
|
|
char* localVarToReplace_orderId = malloc(sizeOfPathParams_orderId);
|
|
snprintf(localVarToReplace_orderId, sizeOfPathParams_orderId, "{%s}", "orderId");
|
|
|
|
char localVarBuff_orderId[256];
|
|
snprintf(localVarBuff_orderId, sizeof localVarBuff_orderId, "%ld", orderId);
|
|
|
|
localVarPath = strReplace(localVarPath, localVarToReplace_orderId, localVarBuff_orderId);
|
|
|
|
|
|
|
|
list_addElement(localVarHeaderType,"application/xml"); //produces
|
|
list_addElement(localVarHeaderType,"application/json"); //produces
|
|
apiClient_invoke(apiClient,
|
|
localVarPath,
|
|
localVarQueryParameters,
|
|
localVarHeaderParameters,
|
|
localVarFormParameters,
|
|
localVarHeaderType,
|
|
localVarContentType,
|
|
localVarBodyParameters,
|
|
localVarBodyLength,
|
|
"GET");
|
|
|
|
// uncomment below to debug the error response
|
|
//if (apiClient->response_code == 200) {
|
|
// printf("%s\n","successful operation");
|
|
//}
|
|
// uncomment below to debug the error response
|
|
//if (apiClient->response_code == 400) {
|
|
// printf("%s\n","Invalid ID supplied");
|
|
//}
|
|
// uncomment below to debug the error response
|
|
//if (apiClient->response_code == 404) {
|
|
// printf("%s\n","Order not found");
|
|
//}
|
|
//nonprimitive not container
|
|
order_t *elementToReturn = NULL;
|
|
if(apiClient->response_code >= 200 && apiClient->response_code < 300) {
|
|
cJSON *StoreAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
|
|
elementToReturn = order_parseFromJSON(StoreAPIlocalVarJSON);
|
|
cJSON_Delete(StoreAPIlocalVarJSON);
|
|
if(elementToReturn == NULL) {
|
|
// return 0;
|
|
}
|
|
}
|
|
|
|
//return type
|
|
if (apiClient->dataReceived) {
|
|
free(apiClient->dataReceived);
|
|
apiClient->dataReceived = NULL;
|
|
apiClient->dataReceivedLen = 0;
|
|
}
|
|
|
|
|
|
|
|
list_freeList(localVarHeaderType);
|
|
|
|
free(localVarPath);
|
|
free(localVarToReplace_orderId);
|
|
return elementToReturn;
|
|
end:
|
|
free(localVarPath);
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// Place an order for a pet
|
|
//
|
|
order_t*
|
|
StoreAPI_placeOrder(apiClient_t *apiClient, order_t *body)
|
|
{
|
|
list_t *localVarQueryParameters = NULL;
|
|
list_t *localVarHeaderParameters = NULL;
|
|
list_t *localVarFormParameters = NULL;
|
|
list_t *localVarHeaderType = list_createList();
|
|
list_t *localVarContentType = NULL;
|
|
char *localVarBodyParameters = NULL;
|
|
size_t localVarBodyLength = 0;
|
|
|
|
// clear the error code from the previous api call
|
|
apiClient->response_code = 0;
|
|
|
|
// create the path
|
|
char *localVarPath = strdup("/store/order");
|
|
|
|
|
|
|
|
|
|
|
|
// Body Param
|
|
cJSON *localVarSingleItemJSON_body = NULL;
|
|
if (body != NULL)
|
|
{
|
|
//not string, not binary
|
|
localVarSingleItemJSON_body = order_convertToJSON(body);
|
|
localVarBodyParameters = cJSON_Print(localVarSingleItemJSON_body);
|
|
localVarBodyLength = strlen(localVarBodyParameters);
|
|
}
|
|
list_addElement(localVarHeaderType,"application/xml"); //produces
|
|
list_addElement(localVarHeaderType,"application/json"); //produces
|
|
apiClient_invoke(apiClient,
|
|
localVarPath,
|
|
localVarQueryParameters,
|
|
localVarHeaderParameters,
|
|
localVarFormParameters,
|
|
localVarHeaderType,
|
|
localVarContentType,
|
|
localVarBodyParameters,
|
|
localVarBodyLength,
|
|
"POST");
|
|
|
|
// uncomment below to debug the error response
|
|
//if (apiClient->response_code == 200) {
|
|
// printf("%s\n","successful operation");
|
|
//}
|
|
// uncomment below to debug the error response
|
|
//if (apiClient->response_code == 400) {
|
|
// printf("%s\n","Invalid Order");
|
|
//}
|
|
//nonprimitive not container
|
|
order_t *elementToReturn = NULL;
|
|
if(apiClient->response_code >= 200 && apiClient->response_code < 300) {
|
|
cJSON *StoreAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
|
|
elementToReturn = order_parseFromJSON(StoreAPIlocalVarJSON);
|
|
cJSON_Delete(StoreAPIlocalVarJSON);
|
|
if(elementToReturn == NULL) {
|
|
// return 0;
|
|
}
|
|
}
|
|
|
|
//return type
|
|
if (apiClient->dataReceived) {
|
|
free(apiClient->dataReceived);
|
|
apiClient->dataReceived = NULL;
|
|
apiClient->dataReceivedLen = 0;
|
|
}
|
|
|
|
|
|
|
|
list_freeList(localVarHeaderType);
|
|
|
|
free(localVarPath);
|
|
if (localVarSingleItemJSON_body) {
|
|
cJSON_Delete(localVarSingleItemJSON_body);
|
|
localVarSingleItemJSON_body = NULL;
|
|
}
|
|
free(localVarBodyParameters);
|
|
return elementToReturn;
|
|
end:
|
|
free(localVarPath);
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// Send us a feedback message
|
|
//
|
|
char*
|
|
StoreAPI_sendFeedback(apiClient_t *apiClient, char *feedback)
|
|
{
|
|
list_t *localVarQueryParameters = NULL;
|
|
list_t *localVarHeaderParameters = NULL;
|
|
list_t *localVarFormParameters = NULL;
|
|
list_t *localVarHeaderType = list_createList();
|
|
list_t *localVarContentType = NULL;
|
|
char *localVarBodyParameters = NULL;
|
|
size_t localVarBodyLength = 0;
|
|
|
|
// clear the error code from the previous api call
|
|
apiClient->response_code = 0;
|
|
|
|
// create the path
|
|
char *localVarPath = strdup("/store/feedback");
|
|
|
|
|
|
|
|
|
|
|
|
// Body Param
|
|
localVarBodyParameters = strdup(feedback);
|
|
localVarBodyLength = strlen(localVarBodyParameters);
|
|
list_addElement(localVarHeaderType,"*/*"); //produces
|
|
apiClient_invoke(apiClient,
|
|
localVarPath,
|
|
localVarQueryParameters,
|
|
localVarHeaderParameters,
|
|
localVarFormParameters,
|
|
localVarHeaderType,
|
|
localVarContentType,
|
|
localVarBodyParameters,
|
|
localVarBodyLength,
|
|
"POST");
|
|
|
|
// uncomment below to debug the error response
|
|
//if (apiClient->response_code == 200) {
|
|
// printf("%s\n","successful operation");
|
|
//}
|
|
//primitive return type simple string
|
|
char* elementToReturn = NULL;
|
|
if(apiClient->response_code >= 200 && apiClient->response_code < 300)
|
|
elementToReturn = strdup((char*)apiClient->dataReceived);
|
|
|
|
if (apiClient->dataReceived) {
|
|
free(apiClient->dataReceived);
|
|
apiClient->dataReceived = NULL;
|
|
apiClient->dataReceivedLen = 0;
|
|
}
|
|
|
|
|
|
|
|
list_freeList(localVarHeaderType);
|
|
|
|
free(localVarPath);
|
|
free(localVarBodyParameters);
|
|
return elementToReturn;
|
|
end:
|
|
free(localVarPath);
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// How would you rate our service?
|
|
//
|
|
char*
|
|
StoreAPI_sendRating(apiClient_t *apiClient, openapi_petstore_sendRating_rating_e rating)
|
|
{
|
|
list_t *localVarQueryParameters = NULL;
|
|
list_t *localVarHeaderParameters = NULL;
|
|
list_t *localVarFormParameters = NULL;
|
|
list_t *localVarHeaderType = list_createList();
|
|
list_t *localVarContentType = NULL;
|
|
char *localVarBodyParameters = NULL;
|
|
size_t localVarBodyLength = 0;
|
|
|
|
// clear the error code from the previous api call
|
|
apiClient->response_code = 0;
|
|
|
|
// create the path
|
|
char *localVarPath = strdup("/store/rating/{rating}");
|
|
|
|
if(!rating)
|
|
goto end;
|
|
|
|
|
|
// Path Params
|
|
long sizeOfPathParams_rating = strlen(sendRating_RATING_ToString(rating))+3 + sizeof("{ rating }") - 1;
|
|
if(rating == 0) {
|
|
goto end;
|
|
}
|
|
char* localVarToReplace_rating = malloc(sizeOfPathParams_rating);
|
|
sprintf(localVarToReplace_rating, "{%s}", "rating");
|
|
|
|
localVarPath = strReplace(localVarPath, localVarToReplace_rating, sendRating_RATING_ToString(rating));
|
|
|
|
|
|
list_addElement(localVarHeaderType,"*/*"); //produces
|
|
apiClient_invoke(apiClient,
|
|
localVarPath,
|
|
localVarQueryParameters,
|
|
localVarHeaderParameters,
|
|
localVarFormParameters,
|
|
localVarHeaderType,
|
|
localVarContentType,
|
|
localVarBodyParameters,
|
|
localVarBodyLength,
|
|
"POST");
|
|
|
|
// uncomment below to debug the error response
|
|
//if (apiClient->response_code == 200) {
|
|
// printf("%s\n","successful operation");
|
|
//}
|
|
//primitive return type simple string
|
|
char* elementToReturn = NULL;
|
|
if(apiClient->response_code >= 200 && apiClient->response_code < 300)
|
|
elementToReturn = strdup((char*)apiClient->dataReceived);
|
|
|
|
if (apiClient->dataReceived) {
|
|
free(apiClient->dataReceived);
|
|
apiClient->dataReceived = NULL;
|
|
apiClient->dataReceivedLen = 0;
|
|
}
|
|
|
|
|
|
|
|
list_freeList(localVarHeaderType);
|
|
|
|
free(localVarPath);
|
|
free(localVarToReplace_rating);
|
|
return elementToReturn;
|
|
end:
|
|
free(localVarPath);
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// Would you recommend our service to a friend?
|
|
//
|
|
char*
|
|
StoreAPI_sendRecommend(apiClient_t *apiClient, int *recommend)
|
|
{
|
|
list_t *localVarQueryParameters = NULL;
|
|
list_t *localVarHeaderParameters = NULL;
|
|
list_t *localVarFormParameters = list_createList();
|
|
list_t *localVarHeaderType = list_createList();
|
|
list_t *localVarContentType = list_createList();
|
|
char *localVarBodyParameters = NULL;
|
|
size_t localVarBodyLength = 0;
|
|
|
|
// clear the error code from the previous api call
|
|
apiClient->response_code = 0;
|
|
|
|
// create the path
|
|
char *localVarPath = strdup("/store/recommend");
|
|
|
|
|
|
|
|
|
|
|
|
// form parameters
|
|
char *keyForm_recommend = NULL;
|
|
char * valueForm_recommend = 0;
|
|
keyValuePair_t *keyPairForm_recommend = 0;
|
|
if (recommend != NULL)
|
|
{
|
|
keyForm_recommend = strdup("recommend");
|
|
valueForm_recommend = calloc(1,MAX_NUMBER_LENGTH);
|
|
snprintf(valueForm_recommend, MAX_NUMBER_LENGTH, "%d", *recommend);
|
|
keyPairForm_recommend = keyValuePair_create(keyForm_recommend,valueForm_recommend);
|
|
list_addElement(localVarFormParameters,keyPairForm_recommend);
|
|
}
|
|
list_addElement(localVarHeaderType,"*/*"); //produces
|
|
list_addElement(localVarContentType,"multipart/form-data"); //consumes
|
|
apiClient_invoke(apiClient,
|
|
localVarPath,
|
|
localVarQueryParameters,
|
|
localVarHeaderParameters,
|
|
localVarFormParameters,
|
|
localVarHeaderType,
|
|
localVarContentType,
|
|
localVarBodyParameters,
|
|
localVarBodyLength,
|
|
"POST");
|
|
|
|
// uncomment below to debug the error response
|
|
//if (apiClient->response_code == 200) {
|
|
// printf("%s\n","successful operation");
|
|
//}
|
|
//primitive return type simple string
|
|
char* elementToReturn = NULL;
|
|
if(apiClient->response_code >= 200 && apiClient->response_code < 300)
|
|
elementToReturn = strdup((char*)apiClient->dataReceived);
|
|
|
|
if (apiClient->dataReceived) {
|
|
free(apiClient->dataReceived);
|
|
apiClient->dataReceived = NULL;
|
|
apiClient->dataReceivedLen = 0;
|
|
}
|
|
|
|
|
|
list_freeList(localVarFormParameters);
|
|
list_freeList(localVarHeaderType);
|
|
list_freeList(localVarContentType);
|
|
free(localVarPath);
|
|
if (keyForm_recommend) {
|
|
free(keyForm_recommend);
|
|
keyForm_recommend = NULL;
|
|
}
|
|
free(keyPairForm_recommend);
|
|
return elementToReturn;
|
|
end:
|
|
free(localVarPath);
|
|
return NULL;
|
|
|
|
}
|
|
|