Skip to content

Commit ca2d452

Browse files
committed
[c]-useJsonUnformatted regenerate petstore samples
1 parent 613cbfe commit ca2d452

15 files changed

Lines changed: 349 additions & 77 deletions

File tree

samples/client/petstore/c-useJsonUnformatted/model/api_response.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@
66

77

88
static api_response_t *api_response_create_internal(
9-
int code,
9+
int *code,
1010
char *type,
1111
char *message
1212
) {
1313
api_response_t *api_response_local_var = malloc(sizeof(api_response_t));
1414
if (!api_response_local_var) {
1515
return NULL;
1616
}
17-
api_response_local_var->code = code;
17+
memset(api_response_local_var, 0, sizeof(api_response_t));
18+
if (code) {
19+
api_response_local_var->code = malloc(sizeof(int));
20+
if (!api_response_local_var->code) {
21+
api_response_free(api_response_local_var);
22+
return NULL;
23+
}
24+
*api_response_local_var->code = *code;
25+
}
1826
api_response_local_var->type = type;
1927
api_response_local_var->message = message;
2028

@@ -23,7 +31,7 @@ static api_response_t *api_response_create_internal(
2331
}
2432

2533
__attribute__((deprecated)) api_response_t *api_response_create(
26-
int code,
34+
int *code,
2735
char *type,
2836
char *message
2937
) {
@@ -43,6 +51,10 @@ void api_response_free(api_response_t *api_response) {
4351
return ;
4452
}
4553
listEntry_t *listEntry;
54+
if (api_response->code) {
55+
free(api_response->code);
56+
api_response->code = NULL;
57+
}
4658
if (api_response->type) {
4759
free(api_response->type);
4860
api_response->type = NULL;
@@ -59,7 +71,7 @@ cJSON *api_response_convertToJSON(api_response_t *api_response) {
5971

6072
// api_response->code
6173
if(api_response->code) {
62-
if(cJSON_AddNumberToObject(item, "code", api_response->code) == NULL) {
74+
if(cJSON_AddNumberToObject(item, "code", *api_response->code) == NULL) {
6375
goto fail; //Numeric
6476
}
6577
}
@@ -92,6 +104,9 @@ api_response_t *api_response_parseFromJSON(cJSON *api_responseJSON){
92104

93105
api_response_t *api_response_local_var = NULL;
94106

107+
// define the local variable for api_response->code
108+
int *code_local_var = NULL;
109+
95110
// api_response->code
96111
cJSON *code = cJSON_GetObjectItemCaseSensitive(api_responseJSON, "code");
97112
if (cJSON_IsNull(code)) {
@@ -102,6 +117,12 @@ api_response_t *api_response_parseFromJSON(cJSON *api_responseJSON){
102117
{
103118
goto end; //Numeric
104119
}
120+
code_local_var = malloc(sizeof(int));
121+
if(!code_local_var)
122+
{
123+
goto end;
124+
}
125+
*code_local_var = code->valuedouble;
105126
}
106127

107128
// api_response->type
@@ -130,13 +151,17 @@ api_response_t *api_response_parseFromJSON(cJSON *api_responseJSON){
130151

131152

132153
api_response_local_var = api_response_create_internal (
133-
code ? code->valuedouble : 0,
154+
code_local_var,
134155
type && !cJSON_IsNull(type) ? strdup(type->valuestring) : NULL,
135156
message && !cJSON_IsNull(message) ? strdup(message->valuestring) : NULL
136157
);
137158

138159
return api_response_local_var;
139160
end:
161+
if (code_local_var) {
162+
free(code_local_var);
163+
code_local_var = NULL;
164+
}
140165
return NULL;
141166

142167
}

samples/client/petstore/c-useJsonUnformatted/model/api_response.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ typedef struct api_response_t api_response_t;
1919

2020

2121
typedef struct api_response_t {
22-
int code; //numeric
22+
int *code; //numeric
2323
char *type; // string
2424
char *message; // string
2525

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

2929
__attribute__((deprecated)) api_response_t *api_response_create(
30-
int code,
30+
int *code,
3131
char *type,
3232
char *message
3333
);

samples/client/petstore/c-useJsonUnformatted/model/category.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,30 @@
66

77

88
static category_t *category_create_internal(
9-
long id,
9+
long *id,
1010
char *name
1111
) {
1212
category_t *category_local_var = malloc(sizeof(category_t));
1313
if (!category_local_var) {
1414
return NULL;
1515
}
16-
category_local_var->id = id;
16+
memset(category_local_var, 0, sizeof(category_t));
17+
if (id) {
18+
category_local_var->id = malloc(sizeof(long));
19+
if (!category_local_var->id) {
20+
category_free(category_local_var);
21+
return NULL;
22+
}
23+
*category_local_var->id = *id;
24+
}
1725
category_local_var->name = name;
1826

1927
category_local_var->_library_owned = 1;
2028
return category_local_var;
2129
}
2230

2331
__attribute__((deprecated)) category_t *category_create(
24-
long id,
32+
long *id,
2533
char *name
2634
) {
2735
return category_create_internal (
@@ -39,6 +47,10 @@ void category_free(category_t *category) {
3947
return ;
4048
}
4149
listEntry_t *listEntry;
50+
if (category->id) {
51+
free(category->id);
52+
category->id = NULL;
53+
}
4254
if (category->name) {
4355
free(category->name);
4456
category->name = NULL;
@@ -51,7 +63,7 @@ cJSON *category_convertToJSON(category_t *category) {
5163

5264
// category->id
5365
if(category->id) {
54-
if(cJSON_AddNumberToObject(item, "id", category->id) == NULL) {
66+
if(cJSON_AddNumberToObject(item, "id", *category->id) == NULL) {
5567
goto fail; //Numeric
5668
}
5769
}
@@ -76,6 +88,9 @@ category_t *category_parseFromJSON(cJSON *categoryJSON){
7688

7789
category_t *category_local_var = NULL;
7890

91+
// define the local variable for category->id
92+
long *id_local_var = NULL;
93+
7994
// category->id
8095
cJSON *id = cJSON_GetObjectItemCaseSensitive(categoryJSON, "id");
8196
if (cJSON_IsNull(id)) {
@@ -86,6 +101,12 @@ category_t *category_parseFromJSON(cJSON *categoryJSON){
86101
{
87102
goto end; //Numeric
88103
}
104+
id_local_var = malloc(sizeof(long));
105+
if(!id_local_var)
106+
{
107+
goto end;
108+
}
109+
*id_local_var = id->valuedouble;
89110
}
90111

91112
// category->name
@@ -102,12 +123,16 @@ category_t *category_parseFromJSON(cJSON *categoryJSON){
102123

103124

104125
category_local_var = category_create_internal (
105-
id ? id->valuedouble : 0,
126+
id_local_var,
106127
name && !cJSON_IsNull(name) ? strdup(name->valuestring) : NULL
107128
);
108129

109130
return category_local_var;
110131
end:
132+
if (id_local_var) {
133+
free(id_local_var);
134+
id_local_var = NULL;
135+
}
111136
return NULL;
112137

113138
}

samples/client/petstore/c-useJsonUnformatted/model/category.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ typedef struct category_t category_t;
1919

2020

2121
typedef struct category_t {
22-
long id; //numeric
22+
long *id; //numeric
2323
char *name; // string
2424

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

2828
__attribute__((deprecated)) category_t *category_create(
29-
long id,
29+
long *id,
3030
char *name
3131
);
3232

samples/client/petstore/c-useJsonUnformatted/model/mapped_model.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,30 @@
66

77

88
static MappedModel_t *MappedModel_create_internal(
9-
int another_property,
9+
int *another_property,
1010
char *uuid_property
1111
) {
1212
MappedModel_t *MappedModel_local_var = malloc(sizeof(MappedModel_t));
1313
if (!MappedModel_local_var) {
1414
return NULL;
1515
}
16-
MappedModel_local_var->another_property = another_property;
16+
memset(MappedModel_local_var, 0, sizeof(MappedModel_t));
17+
if (another_property) {
18+
MappedModel_local_var->another_property = malloc(sizeof(int));
19+
if (!MappedModel_local_var->another_property) {
20+
MappedModel_free(MappedModel_local_var);
21+
return NULL;
22+
}
23+
*MappedModel_local_var->another_property = *another_property;
24+
}
1725
MappedModel_local_var->uuid_property = uuid_property;
1826

1927
MappedModel_local_var->_library_owned = 1;
2028
return MappedModel_local_var;
2129
}
2230

2331
__attribute__((deprecated)) MappedModel_t *MappedModel_create(
24-
int another_property,
32+
int *another_property,
2533
char *uuid_property
2634
) {
2735
return MappedModel_create_internal (
@@ -39,6 +47,10 @@ void MappedModel_free(MappedModel_t *MappedModel) {
3947
return ;
4048
}
4149
listEntry_t *listEntry;
50+
if (MappedModel->another_property) {
51+
free(MappedModel->another_property);
52+
MappedModel->another_property = NULL;
53+
}
4254
if (MappedModel->uuid_property) {
4355
free(MappedModel->uuid_property);
4456
MappedModel->uuid_property = NULL;
@@ -51,7 +63,7 @@ cJSON *MappedModel_convertToJSON(MappedModel_t *MappedModel) {
5163

5264
// MappedModel->another_property
5365
if(MappedModel->another_property) {
54-
if(cJSON_AddNumberToObject(item, "another_property", MappedModel->another_property) == NULL) {
66+
if(cJSON_AddNumberToObject(item, "another_property", *MappedModel->another_property) == NULL) {
5567
goto fail; //Numeric
5668
}
5769
}
@@ -76,6 +88,9 @@ MappedModel_t *MappedModel_parseFromJSON(cJSON *MappedModelJSON){
7688

7789
MappedModel_t *MappedModel_local_var = NULL;
7890

91+
// define the local variable for MappedModel->another_property
92+
int *another_property_local_var = NULL;
93+
7994
// MappedModel->another_property
8095
cJSON *another_property = cJSON_GetObjectItemCaseSensitive(MappedModelJSON, "another_property");
8196
if (cJSON_IsNull(another_property)) {
@@ -86,6 +101,12 @@ MappedModel_t *MappedModel_parseFromJSON(cJSON *MappedModelJSON){
86101
{
87102
goto end; //Numeric
88103
}
104+
another_property_local_var = malloc(sizeof(int));
105+
if(!another_property_local_var)
106+
{
107+
goto end;
108+
}
109+
*another_property_local_var = another_property->valuedouble;
89110
}
90111

91112
// MappedModel->uuid_property
@@ -102,12 +123,16 @@ MappedModel_t *MappedModel_parseFromJSON(cJSON *MappedModelJSON){
102123

103124

104125
MappedModel_local_var = MappedModel_create_internal (
105-
another_property ? another_property->valuedouble : 0,
126+
another_property_local_var,
106127
uuid_property && !cJSON_IsNull(uuid_property) ? strdup(uuid_property->valuestring) : NULL
107128
);
108129

109130
return MappedModel_local_var;
110131
end:
132+
if (another_property_local_var) {
133+
free(another_property_local_var);
134+
another_property_local_var = NULL;
135+
}
111136
return NULL;
112137

113138
}

samples/client/petstore/c-useJsonUnformatted/model/mapped_model.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ typedef struct MappedModel_t MappedModel_t;
1919

2020

2121
typedef struct MappedModel_t {
22-
int another_property; //numeric
22+
int *another_property; //numeric
2323
char *uuid_property; // string
2424

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

2828
__attribute__((deprecated)) MappedModel_t *MappedModel_create(
29-
int another_property,
29+
int *another_property,
3030
char *uuid_property
3131
);
3232

samples/client/petstore/c-useJsonUnformatted/model/model_with_set_propertes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ static model_with_set_propertes_t *model_with_set_propertes_create_internal(
1313
if (!model_with_set_propertes_local_var) {
1414
return NULL;
1515
}
16+
memset(model_with_set_propertes_local_var, 0, sizeof(model_with_set_propertes_t));
1617
model_with_set_propertes_local_var->tag_set = tag_set;
1718
model_with_set_propertes_local_var->string_set = string_set;
1819

0 commit comments

Comments
 (0)