Skip to content

Commit 62bd4b5

Browse files
author
Matteo Ferrari
committed
wip
1 parent 815a732 commit 62bd4b5

2 files changed

Lines changed: 68 additions & 12 deletions

File tree

modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ static {{classname}}_t *{{classname}}_create_internal(
153153
{{/isPrimitiveType}}
154154
{{#isPrimitiveType}}
155155
{{#isNumeric}}
156-
{{datatype}} {{name}}{{^-last}},{{/-last}}
156+
{{datatype}} *{{name}}{{^-last}},{{/-last}}
157157
{{/isNumeric}}
158158
{{#isBoolean}}
159-
{{datatype}} {{name}}{{^-last}},{{/-last}}
159+
{{datatype}} *{{name}}{{^-last}},{{/-last}}
160160
{{/isBoolean}}
161161
{{#isEnum}}
162162
{{#isString}}
@@ -243,10 +243,10 @@ __attribute__((deprecated)) {{classname}}_t *{{classname}}_create(
243243
{{/isPrimitiveType}}
244244
{{#isPrimitiveType}}
245245
{{#isNumeric}}
246-
{{datatype}} {{name}}{{^-last}},{{/-last}}
246+
{{datatype}} *{{name}}{{^-last}},{{/-last}}
247247
{{/isNumeric}}
248248
{{#isBoolean}}
249-
{{datatype}} {{name}}{{^-last}},{{/-last}}
249+
{{datatype}} *{{name}}{{^-last}},{{/-last}}
250250
{{/isBoolean}}
251251
{{#isEnum}}
252252
{{#isString}}
@@ -344,6 +344,18 @@ void {{classname}}_free({{classname}}_t *{{classname}}) {
344344
{{/isFreeFormObject}}
345345
{{/isPrimitiveType}}
346346
{{#isPrimitiveType}}
347+
{{#isNumeric}}
348+
if ({{{classname}}}->{{{name}}}) {
349+
free({{{classname}}}->{{{name}}});
350+
{{classname}}->{{name}} = NULL;
351+
}
352+
{{/isNumeric}}
353+
{{#isBoolean}}
354+
if ({{{classname}}}->{{{name}}}) {
355+
free({{{classname}}}->{{{name}}});
356+
{{classname}}->{{name}} = NULL;
357+
}
358+
{{/isBoolean}}
347359
{{^isEnum}}
348360
{{#isString}}
349361
if ({{{classname}}}->{{{name}}}) {
@@ -454,12 +466,12 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
454466
{{^isContainer}}
455467
{{#isPrimitiveType}}
456468
{{#isNumeric}}
457-
if(cJSON_AddNumberToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
469+
if(cJSON_AddNumberToObject(item, "{{{baseName}}}", *{{{classname}}}->{{{name}}}) == NULL) {
458470
goto fail; //Numeric
459471
}
460472
{{/isNumeric}}
461473
{{#isBoolean}}
462-
if(cJSON_AddBoolToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
474+
if(cJSON_AddBoolToObject(item, "{{{baseName}}}", *{{{classname}}}->{{{name}}}) == NULL) {
463475
goto fail; //Bool
464476
}
465477
{{/isBoolean}}
@@ -700,6 +712,18 @@ fail:
700712
{{/isFreeFormObject}}
701713
{{/isModel}}
702714
{{/isPrimitiveType}}
715+
{{#isPrimitiveType}}
716+
{{#isNumeric}}
717+
// define the local variable for {{{classname}}}->{{{name}}}
718+
{{datatype}} *{{name}}_local_var = NULL;
719+
720+
{{/isNumeric}}
721+
{{#isBoolean}}
722+
// define the local variable for {{{classname}}}->{{{name}}}
723+
{{datatype}} *{{name}}_local_var = NULL;
724+
725+
{{/isBoolean}}
726+
{{/isPrimitiveType}}
703727
{{/isContainer}}
704728
{{/vars}}
705729
{{#vars}}
@@ -722,13 +746,31 @@ fail:
722746
{
723747
goto end; //Numeric
724748
}
749+
{{name}}_local_var = malloc(sizeof({{datatype}}));
750+
if(!{{name}}_local_var)
751+
{
752+
goto end;
753+
}
754+
*{{name}}_local_var = {{{name}}}->valuedouble;
755+
{{^required}}
756+
}
757+
{{/required}}
725758
{{/isNumeric}}
726759
{{#isBoolean}}
727760
{{^required}}if ({{{name}}}) { {{/required}}
728761
if(!cJSON_IsBool({{{name}}}))
729762
{
730763
goto end; //Bool
731764
}
765+
{{name}}_local_var = malloc(sizeof({{datatype}}));
766+
if(!{{name}}_local_var)
767+
{
768+
goto end;
769+
}
770+
*{{name}}_local_var = {{{name}}}->valueint;
771+
{{^required}}
772+
}
773+
{{/required}}
732774
{{/isBoolean}}
733775
{{#isEnum}}
734776
{{#isString}}
@@ -977,10 +1019,10 @@ fail:
9771019
{{/isPrimitiveType}}
9781020
{{#isPrimitiveType}}
9791021
{{#isNumeric}}
980-
{{^required}}{{{name}}} ? {{/required}}{{{name}}}->valuedouble{{^required}} : 0{{/required}}{{^-last}},{{/-last}}
1022+
{{name}}_local_var{{^-last}},{{/-last}}
9811023
{{/isNumeric}}
9821024
{{#isBoolean}}
983-
{{^required}}{{{name}}} ? {{/required}}{{{name}}}->valueint{{^required}} : 0{{/required}}{{^-last}},{{/-last}}
1025+
{{name}}_local_var{{^-last}},{{/-last}}
9841026
{{/isBoolean}}
9851027
{{#isEnum}}
9861028
{{#isString}}
@@ -1046,6 +1088,20 @@ end:
10461088
{{/isFreeFormObject}}
10471089
{{/isModel}}
10481090
{{/isPrimitiveType}}
1091+
{{#isPrimitiveType}}
1092+
{{#isNumeric}}
1093+
if ({{{name}}}_local_var) {
1094+
free({{{name}}}_local_var);
1095+
{{{name}}}_local_var = NULL;
1096+
}
1097+
{{/isNumeric}}
1098+
{{#isBoolean}}
1099+
if ({{{name}}}_local_var) {
1100+
free({{{name}}}_local_var);
1101+
{{{name}}}_local_var = NULL;
1102+
}
1103+
{{/isBoolean}}
1104+
{{/isPrimitiveType}}
10491105
{{/isContainer}}
10501106
{{#isContainer}}
10511107
{{#isArray}}

modules/openapi-generator/src/main/resources/C-libcurl/model-header.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ typedef struct {{classname}}_t {
110110
{{/isPrimitiveType}}
111111
{{#isPrimitiveType}}
112112
{{#isNumeric}}
113-
{{datatype}} {{name}}; //numeric
113+
{{datatype}} *{{name}}; //numeric
114114
{{/isNumeric}}
115115
{{#isBoolean}}
116-
{{datatype}} {{name}}; //boolean
116+
{{datatype}} *{{name}}; //boolean
117117
{{/isBoolean}}
118118
{{#isEnum}}
119119
{{#isString}}
@@ -191,10 +191,10 @@ __attribute__((deprecated)) {{classname}}_t *{{classname}}_create(
191191
{{/isPrimitiveType}}
192192
{{#isPrimitiveType}}
193193
{{#isNumeric}}
194-
{{datatype}} {{name}}{{^-last}},{{/-last}}
194+
{{datatype}} *{{name}}{{^-last}},{{/-last}}
195195
{{/isNumeric}}
196196
{{#isBoolean}}
197-
{{datatype}} {{name}}{{^-last}},{{/-last}}
197+
{{datatype}} *{{name}}{{^-last}},{{/-last}}
198198
{{/isBoolean}}
199199
{{#isEnum}}
200200
{{#isString}}

0 commit comments

Comments
 (0)