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
42 lines
1.3 KiB
C
42 lines
1.3 KiB
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include "preference.h"
|
|
|
|
|
|
char* preference_preference_ToString(openapi_petstore_preference__e preference) {
|
|
char *preferenceArray[] = { "NULL", "cats", "dogs", "birds", "fish", "snakes", "other" };
|
|
return preferenceArray[preference];
|
|
}
|
|
|
|
openapi_petstore_preference__e preference_preference_FromString(char* preference) {
|
|
int stringToReturn = 0;
|
|
char *preferenceArray[] = { "NULL", "cats", "dogs", "birds", "fish", "snakes", "other" };
|
|
size_t sizeofArray = sizeof(preferenceArray) / sizeof(preferenceArray[0]);
|
|
while(stringToReturn < sizeofArray) {
|
|
if(strcmp(preference, preferenceArray[stringToReturn]) == 0) {
|
|
return stringToReturn;
|
|
}
|
|
stringToReturn++;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
cJSON *preference_convertToJSON(openapi_petstore_preference__e preference) {
|
|
cJSON *item = cJSON_CreateObject();
|
|
if(cJSON_AddStringToObject(item, "preference", preference_preference_ToString(preference)) == NULL) {
|
|
goto fail;
|
|
}
|
|
return item;
|
|
fail:
|
|
cJSON_Delete(item);
|
|
return NULL;
|
|
}
|
|
|
|
openapi_petstore_preference__e preference_parseFromJSON(cJSON *preferenceJSON) {
|
|
if(!cJSON_IsString(preferenceJSON) || (preferenceJSON->valuestring == NULL)) {
|
|
return 0;
|
|
}
|
|
return preference_preference_FromString(preferenceJSON->valuestring);
|
|
}
|