forked from loafle/openapi-generator-original
* [C] Don't convert post body strings to JSON If the body provided for the api request is a just a string itself, don't try to convert it to JSON, simply submit the string. * [C] Implement BearerToken authentication * [C] Handle nullable fields correctly * [C] Fix implementation of FromString for enums * [C] Update the test schemas to cover the changes * Update samples * Fix the updated samples * [C] Add the new samples folder to the CI workflow
205 lines
5.7 KiB
C
205 lines
5.7 KiB
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <ctype.h>
|
|
#include "DefaultAPI.h"
|
|
|
|
#define MAX_NUMBER_LENGTH 16
|
|
#define MAX_BUFFER_LENGTH 4096
|
|
#define intToStr(dst, src) \
|
|
do {\
|
|
char dst[256];\
|
|
snprintf(dst, 256, "%ld", (long int)(src));\
|
|
}while(0)
|
|
|
|
|
|
// Returns private information.
|
|
//
|
|
// This endpoint requires global security settings.
|
|
//
|
|
object_t*
|
|
DefaultAPI_privateGet(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;
|
|
|
|
// create the path
|
|
long sizeOfPath = strlen("/private")+1;
|
|
char *localVarPath = malloc(sizeOfPath);
|
|
snprintf(localVarPath, sizeOfPath, "/private");
|
|
|
|
|
|
|
|
list_addElement(localVarHeaderType,"application/json"); //produces
|
|
apiClient_invoke(apiClient,
|
|
localVarPath,
|
|
localVarQueryParameters,
|
|
localVarHeaderParameters,
|
|
localVarFormParameters,
|
|
localVarHeaderType,
|
|
localVarContentType,
|
|
localVarBodyParameters,
|
|
"GET");
|
|
|
|
// uncomment below to debug the error response
|
|
//if (apiClient->response_code == 200) {
|
|
// printf("%s\n","A JSON object with private information");
|
|
//}
|
|
//nonprimitive not container
|
|
cJSON *DefaultAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
|
|
object_t *elementToReturn = object_parseFromJSON(DefaultAPIlocalVarJSON);
|
|
cJSON_Delete(DefaultAPIlocalVarJSON);
|
|
if(elementToReturn == NULL) {
|
|
// return 0;
|
|
}
|
|
|
|
//return type
|
|
if (apiClient->dataReceived) {
|
|
free(apiClient->dataReceived);
|
|
apiClient->dataReceived = NULL;
|
|
apiClient->dataReceivedLen = 0;
|
|
}
|
|
|
|
|
|
|
|
list_freeList(localVarHeaderType);
|
|
|
|
free(localVarPath);
|
|
return elementToReturn;
|
|
end:
|
|
free(localVarPath);
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// Returns public information.
|
|
//
|
|
// This endpoint does not require authentication.
|
|
//
|
|
object_t*
|
|
DefaultAPI_publicGet(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;
|
|
|
|
// create the path
|
|
long sizeOfPath = strlen("/public")+1;
|
|
char *localVarPath = malloc(sizeOfPath);
|
|
snprintf(localVarPath, sizeOfPath, "/public");
|
|
|
|
|
|
|
|
list_addElement(localVarHeaderType,"application/json"); //produces
|
|
apiClient_invoke(apiClient,
|
|
localVarPath,
|
|
localVarQueryParameters,
|
|
localVarHeaderParameters,
|
|
localVarFormParameters,
|
|
localVarHeaderType,
|
|
localVarContentType,
|
|
localVarBodyParameters,
|
|
"GET");
|
|
|
|
// uncomment below to debug the error response
|
|
//if (apiClient->response_code == 200) {
|
|
// printf("%s\n","A JSON object with public information");
|
|
//}
|
|
//nonprimitive not container
|
|
cJSON *DefaultAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
|
|
object_t *elementToReturn = object_parseFromJSON(DefaultAPIlocalVarJSON);
|
|
cJSON_Delete(DefaultAPIlocalVarJSON);
|
|
if(elementToReturn == NULL) {
|
|
// return 0;
|
|
}
|
|
|
|
//return type
|
|
if (apiClient->dataReceived) {
|
|
free(apiClient->dataReceived);
|
|
apiClient->dataReceived = NULL;
|
|
apiClient->dataReceivedLen = 0;
|
|
}
|
|
|
|
|
|
|
|
list_freeList(localVarHeaderType);
|
|
|
|
free(localVarPath);
|
|
return elementToReturn;
|
|
end:
|
|
free(localVarPath);
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// Returns a list of users.
|
|
//
|
|
// Optional extended description in CommonMark or HTML.
|
|
//
|
|
list_t*
|
|
DefaultAPI_usersGet(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;
|
|
|
|
// create the path
|
|
long sizeOfPath = strlen("/users")+1;
|
|
char *localVarPath = malloc(sizeOfPath);
|
|
snprintf(localVarPath, sizeOfPath, "/users");
|
|
|
|
|
|
|
|
list_addElement(localVarHeaderType,"application/json"); //produces
|
|
apiClient_invoke(apiClient,
|
|
localVarPath,
|
|
localVarQueryParameters,
|
|
localVarHeaderParameters,
|
|
localVarFormParameters,
|
|
localVarHeaderType,
|
|
localVarContentType,
|
|
localVarBodyParameters,
|
|
"GET");
|
|
|
|
// uncomment below to debug the error response
|
|
//if (apiClient->response_code == 200) {
|
|
// printf("%s\n","A JSON array of user names");
|
|
//}
|
|
//primitive return type not simple
|
|
cJSON *localVarJSON = cJSON_Parse(apiClient->dataReceived);
|
|
cJSON *VarJSON;
|
|
list_t *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;
|
|
|
|
}
|
|
|