Ernesto Fernández 52b5b8fb76
Fix a few issues with the C generator (part 2) (#20227)
* [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
2024-12-06 01:32:34 +08:00

52 lines
859 B
C

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "object.h"
object_t *object_create() {
object_t *object = calloc(1, sizeof(object_t));
return object;
}
void object_free(object_t *object) {
if (!object) {
return ;
}
if (object->temporary) {
free(object->temporary);
object->temporary = NULL;
}
free (object);
}
cJSON *object_convertToJSON(object_t *object) {
if (!object) {
return NULL;
}
if (!object->temporary) {
return cJSON_Parse("null");
}
return cJSON_Parse(object->temporary);
}
object_t *object_parseFromJSON(cJSON *json){
if (!json) {
goto end;
}
object_t *object = object_create();
if (!object) {
goto end;
}
object->temporary = cJSON_Print(json);
return object;
end:
return NULL;
}