forked from loafle/openapi-generator-original
[C][Client] Support freeform object (#12557)
This commit is contained in:
parent
a7db213c2d
commit
bf22f38015
@ -4,28 +4,48 @@
|
|||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
|
||||||
object_t *object_create() {
|
object_t *object_create() {
|
||||||
object_t *object = malloc(sizeof(object_t));
|
object_t *object = calloc(1, sizeof(object_t));
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
void object_free(object_t *object) {
|
void object_free(object_t *object) {
|
||||||
|
if (!object) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (object->temporary) {
|
||||||
|
free(object->temporary);
|
||||||
|
object->temporary = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
free (object);
|
free (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON *object_convertToJSON(object_t *object) {
|
cJSON *object_convertToJSON(object_t *object) {
|
||||||
cJSON *item = cJSON_CreateObject();
|
if (!object) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return item;
|
if (!object->temporary) {
|
||||||
fail:
|
return cJSON_Parse("{}");
|
||||||
cJSON_Delete(item);
|
}
|
||||||
return NULL;
|
|
||||||
|
return cJSON_Parse(object->temporary);
|
||||||
}
|
}
|
||||||
|
|
||||||
object_t *object_parseFromJSON(char *jsonString){
|
object_t *object_parseFromJSON(cJSON *json){
|
||||||
object_t *object = NULL;
|
if (!json) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
object_t *object = object_create();
|
||||||
|
if (!object) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
object->temporary = cJSON_Print(json);
|
||||||
return object;
|
return object;
|
||||||
|
|
||||||
end:
|
end:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ object_t *object_create();
|
|||||||
|
|
||||||
void object_free(object_t *object);
|
void object_free(object_t *object);
|
||||||
|
|
||||||
object_t *object_parseFromJSON(char *jsonString);
|
object_t *object_parseFromJSON(cJSON *json);
|
||||||
|
|
||||||
cJSON *object_convertToJSON(object_t *object);
|
cJSON *object_convertToJSON(object_t *object);
|
||||||
|
|
||||||
|
@ -4,28 +4,48 @@
|
|||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
|
||||||
object_t *object_create() {
|
object_t *object_create() {
|
||||||
object_t *object = malloc(sizeof(object_t));
|
object_t *object = calloc(1, sizeof(object_t));
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
void object_free(object_t *object) {
|
void object_free(object_t *object) {
|
||||||
|
if (!object) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (object->temporary) {
|
||||||
|
free(object->temporary);
|
||||||
|
object->temporary = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
free (object);
|
free (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON *object_convertToJSON(object_t *object) {
|
cJSON *object_convertToJSON(object_t *object) {
|
||||||
cJSON *item = cJSON_CreateObject();
|
if (!object) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return item;
|
if (!object->temporary) {
|
||||||
fail:
|
return cJSON_Parse("{}");
|
||||||
cJSON_Delete(item);
|
}
|
||||||
return NULL;
|
|
||||||
|
return cJSON_Parse(object->temporary);
|
||||||
}
|
}
|
||||||
|
|
||||||
object_t *object_parseFromJSON(char *jsonString){
|
object_t *object_parseFromJSON(cJSON *json){
|
||||||
object_t *object = NULL;
|
if (!json) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
object_t *object = object_create();
|
||||||
|
if (!object) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
object->temporary = cJSON_Print(json);
|
||||||
return object;
|
return object;
|
||||||
|
|
||||||
end:
|
end:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ object_t *object_create();
|
|||||||
|
|
||||||
void object_free(object_t *object);
|
void object_free(object_t *object);
|
||||||
|
|
||||||
object_t *object_parseFromJSON(char *jsonString);
|
object_t *object_parseFromJSON(cJSON *json);
|
||||||
|
|
||||||
cJSON *object_convertToJSON(object_t *object);
|
cJSON *object_convertToJSON(object_t *object);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user