Skip to content

Commit

Permalink
Update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
eafer committed Dec 26, 2024
1 parent 43aa9e5 commit e8295e2
Show file tree
Hide file tree
Showing 32 changed files with 356 additions and 48 deletions.
20 changes: 18 additions & 2 deletions samples/client/petstore/c-useJsonUnformatted/model/api_response.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@



api_response_t *api_response_create(
static api_response_t *api_response_create_internal(
int code,
char *type,
char *message
Expand All @@ -18,14 +18,30 @@ api_response_t *api_response_create(
api_response_local_var->type = type;
api_response_local_var->message = message;

api_response_local_var->_library_owned = 1;
return api_response_local_var;
}

__attribute__((deprecated)) api_response_t *api_response_create(
int code,
char *type,
char *message
) {
return api_response_create_internal (
code,
type,
message
);
}

void api_response_free(api_response_t *api_response) {
if(NULL == api_response){
return ;
}
if(api_response->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "api_response_free");
return ;
}
listEntry_t *listEntry;
if (api_response->type) {
free(api_response->type);
Expand Down Expand Up @@ -113,7 +129,7 @@ api_response_t *api_response_parseFromJSON(cJSON *api_responseJSON){
}


api_response_local_var = api_response_create (
api_response_local_var = api_response_create_internal (
code ? code->valuedouble : 0,
type && !cJSON_IsNull(type) ? strdup(type->valuestring) : NULL,
message && !cJSON_IsNull(message) ? strdup(message->valuestring) : NULL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ typedef struct api_response_t {
char *type; // string
char *message; // string

int _library_owned; // Is the library responsible for freeing this object?
} api_response_t;

api_response_t *api_response_create(
__attribute__((deprecated)) api_response_t *api_response_create(
int code,
char *type,
char *message
Expand Down
18 changes: 16 additions & 2 deletions samples/client/petstore/c-useJsonUnformatted/model/category.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@



category_t *category_create(
static category_t *category_create_internal(
long id,
char *name
) {
Expand All @@ -16,14 +16,28 @@ category_t *category_create(
category_local_var->id = id;
category_local_var->name = name;

category_local_var->_library_owned = 1;
return category_local_var;
}

__attribute__((deprecated)) category_t *category_create(
long id,
char *name
) {
return category_create_internal (
id,
name
);
}

void category_free(category_t *category) {
if(NULL == category){
return ;
}
if(category->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "category_free");
return ;
}
listEntry_t *listEntry;
if (category->name) {
free(category->name);
Expand Down Expand Up @@ -87,7 +101,7 @@ category_t *category_parseFromJSON(cJSON *categoryJSON){
}


category_local_var = category_create (
category_local_var = category_create_internal (
id ? id->valuedouble : 0,
name && !cJSON_IsNull(name) ? strdup(name->valuestring) : NULL
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ typedef struct category_t {
long id; //numeric
char *name; // string

int _library_owned; // Is the library responsible for freeing this object?
} category_t;

category_t *category_create(
__attribute__((deprecated)) category_t *category_create(
long id,
char *name
);
Expand Down
18 changes: 16 additions & 2 deletions samples/client/petstore/c-useJsonUnformatted/model/mapped_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@



MappedModel_t *MappedModel_create(
static MappedModel_t *MappedModel_create_internal(
int another_property,
char *uuid_property
) {
Expand All @@ -16,14 +16,28 @@ MappedModel_t *MappedModel_create(
MappedModel_local_var->another_property = another_property;
MappedModel_local_var->uuid_property = uuid_property;

MappedModel_local_var->_library_owned = 1;
return MappedModel_local_var;
}

__attribute__((deprecated)) MappedModel_t *MappedModel_create(
int another_property,
char *uuid_property
) {
return MappedModel_create_internal (
another_property,
uuid_property
);
}

void MappedModel_free(MappedModel_t *MappedModel) {
if(NULL == MappedModel){
return ;
}
if(MappedModel->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "MappedModel_free");
return ;
}
listEntry_t *listEntry;
if (MappedModel->uuid_property) {
free(MappedModel->uuid_property);
Expand Down Expand Up @@ -87,7 +101,7 @@ MappedModel_t *MappedModel_parseFromJSON(cJSON *MappedModelJSON){
}


MappedModel_local_var = MappedModel_create (
MappedModel_local_var = MappedModel_create_internal (
another_property ? another_property->valuedouble : 0,
uuid_property && !cJSON_IsNull(uuid_property) ? strdup(uuid_property->valuestring) : NULL
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ typedef struct MappedModel_t {
int another_property; //numeric
char *uuid_property; // string

int _library_owned; // Is the library responsible for freeing this object?
} MappedModel_t;

MappedModel_t *MappedModel_create(
__attribute__((deprecated)) MappedModel_t *MappedModel_create(
int another_property,
char *uuid_property
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@



model_with_set_propertes_t *model_with_set_propertes_create(
static model_with_set_propertes_t *model_with_set_propertes_create_internal(
list_t *tag_set,
list_t *string_set
) {
Expand All @@ -16,14 +16,28 @@ model_with_set_propertes_t *model_with_set_propertes_create(
model_with_set_propertes_local_var->tag_set = tag_set;
model_with_set_propertes_local_var->string_set = string_set;

model_with_set_propertes_local_var->_library_owned = 1;
return model_with_set_propertes_local_var;
}

__attribute__((deprecated)) model_with_set_propertes_t *model_with_set_propertes_create(
list_t *tag_set,
list_t *string_set
) {
return model_with_set_propertes_create_internal (
tag_set,
string_set
);
}

void model_with_set_propertes_free(model_with_set_propertes_t *model_with_set_propertes) {
if(NULL == model_with_set_propertes){
return ;
}
if(model_with_set_propertes->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "model_with_set_propertes_free");
return ;
}
listEntry_t *listEntry;
if (model_with_set_propertes->tag_set) {
list_ForEach(listEntry, model_with_set_propertes->tag_set) {
Expand Down Expand Up @@ -146,7 +160,7 @@ model_with_set_propertes_t *model_with_set_propertes_parseFromJSON(cJSON *model_
}


model_with_set_propertes_local_var = model_with_set_propertes_create (
model_with_set_propertes_local_var = model_with_set_propertes_create_internal (
tag_set ? tag_setList : NULL,
string_set ? string_setList : NULL
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ typedef struct model_with_set_propertes_t {
list_t *tag_set; //nonprimitive container
list_t *string_set; //primitive container

int _library_owned; // Is the library responsible for freeing this object?
} model_with_set_propertes_t;

model_with_set_propertes_t *model_with_set_propertes_create(
__attribute__((deprecated)) model_with_set_propertes_t *model_with_set_propertes_create(
list_t *tag_set,
list_t *string_set
);
Expand Down
26 changes: 24 additions & 2 deletions samples/client/petstore/c-useJsonUnformatted/model/order.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ openapi_petstore_order_STATUS_e order_status_FromString(char* status){
return 0;
}

order_t *order_create(
static order_t *order_create_internal(
long id,
long pet_id,
int quantity,
Expand All @@ -41,14 +41,36 @@ order_t *order_create(
order_local_var->status = status;
order_local_var->complete = complete;

order_local_var->_library_owned = 1;
return order_local_var;
}

__attribute__((deprecated)) order_t *order_create(
long id,
long pet_id,
int quantity,
char *ship_date,
openapi_petstore_order_STATUS_e status,
int complete
) {
return order_create_internal (
id,
pet_id,
quantity,
ship_date,
status,
complete
);
}

void order_free(order_t *order) {
if(NULL == order){
return ;
}
if(order->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "order_free");
return ;
}
listEntry_t *listEntry;
if (order->ship_date) {
free(order->ship_date);
Expand Down Expand Up @@ -195,7 +217,7 @@ order_t *order_parseFromJSON(cJSON *orderJSON){
}


order_local_var = order_create (
order_local_var = order_create_internal (
id ? id->valuedouble : 0,
pet_id ? pet_id->valuedouble : 0,
quantity ? quantity->valuedouble : 0,
Expand Down
3 changes: 2 additions & 1 deletion samples/client/petstore/c-useJsonUnformatted/model/order.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ typedef struct order_t {
openapi_petstore_order_STATUS_e status; //enum
int complete; //boolean

int _library_owned; // Is the library responsible for freeing this object?
} order_t;

order_t *order_create(
__attribute__((deprecated)) order_t *order_create(
long id,
long pet_id,
int quantity,
Expand Down
26 changes: 24 additions & 2 deletions samples/client/petstore/c-useJsonUnformatted/model/pet.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ openapi_petstore_pet_STATUS_e pet_status_FromString(char* status){
return 0;
}

pet_t *pet_create(
static pet_t *pet_create_internal(
long id,
category_t *category,
char *name,
Expand All @@ -41,14 +41,36 @@ pet_t *pet_create(
pet_local_var->tags = tags;
pet_local_var->status = status;

pet_local_var->_library_owned = 1;
return pet_local_var;
}

__attribute__((deprecated)) pet_t *pet_create(
long id,
category_t *category,
char *name,
list_t *photo_urls,
list_t *tags,
openapi_petstore_pet_STATUS_e status
) {
return pet_create_internal (
id,
category,
name,
photo_urls,
tags,
status
);
}

void pet_free(pet_t *pet) {
if(NULL == pet){
return ;
}
if(pet->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "pet_free");
return ;
}
listEntry_t *listEntry;
if (pet->category) {
category_free(pet->category);
Expand Down Expand Up @@ -275,7 +297,7 @@ pet_t *pet_parseFromJSON(cJSON *petJSON){
}


pet_local_var = pet_create (
pet_local_var = pet_create_internal (
id ? id->valuedouble : 0,
category ? category_local_nonprim : NULL,
strdup(name->valuestring),
Expand Down
3 changes: 2 additions & 1 deletion samples/client/petstore/c-useJsonUnformatted/model/pet.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ typedef struct pet_t {
list_t *tags; //nonprimitive container
openapi_petstore_pet_STATUS_e status; //enum

int _library_owned; // Is the library responsible for freeing this object?
} pet_t;

pet_t *pet_create(
__attribute__((deprecated)) pet_t *pet_create(
long id,
category_t *category,
char *name,
Expand Down
Loading

0 comments on commit e8295e2

Please sign in to comment.