Skip to content

Commit ba044a6

Browse files
committed
[C-Curl] Client generator does not handle float properly (#21092)
- Generate samples - Fix generator for headers and path params
1 parent f99c5b0 commit ba044a6

File tree

13 files changed

+66
-52
lines changed

13 files changed

+66
-52
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ end:
126126
{{#pathParams}}
127127

128128
// Path Params
129-
long sizeOfPathParams_{{{paramName}}} = {{#pathParams}}{{#isLong}}sizeof({{paramName}})+3{{/isLong}}{{#isString}}strlen({{^isEnum}}{{paramName}}{{/isEnum}}{{#isEnum}}{{{operationId}}}_{{enumName}}_ToString({{paramName}}){{/isEnum}})+3{{/isString}}{{^-last}} + {{/-last}}{{/pathParams}} + sizeof("{ {{baseName}} }") - 1;
129+
long sizeOfPathParams_{{{paramName}}} = {{#pathParams}}{{#isLong}}sizeof(*{{paramName}})+3{{/isLong}}{{#isString}}strlen({{^isEnum}}{{paramName}}{{/isEnum}}{{#isEnum}}{{{operationId}}}_{{enumName}}_ToString({{paramName}}){{/isEnum}})+3{{/isString}}{{^-last}} + {{/-last}}{{/pathParams}} + sizeof("{ {{baseName}} }") - 1;
130130
{{#isNumeric}}
131131
if({{paramName}} == 0){
132132
goto end;
@@ -161,7 +161,7 @@ end:
161161
snprintf(localVarToReplace_{{paramName}}, sizeOfPathParams_{{paramName}}, "{%s}", "{{baseName}}");
162162

163163
char localVarBuff_{{paramName}}[256];
164-
snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", (long){{paramName}});
164+
snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", (long)*{{paramName}});
165165

166166
localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, localVarBuff_{{paramName}});
167167

@@ -174,7 +174,7 @@ end:
174174
snprintf(localVarToReplace_{{paramName}}, sizeOfPathParams_{{paramName}}, "{%s}", "{{baseName}}");
175175

176176
char localVarBuff_{{paramName}}[256];
177-
snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", {{paramName}});
177+
snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", *{{paramName}});
178178

179179
localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, localVarBuff_{{paramName}});
180180

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ typedef enum { {{projectName}}_{{operationId}}_{{enumName}}_NULL = 0{{#enumVars
3333
//
3434
{{/notes}}
3535
{{#returnType}}{{#returnTypeIsPrimitive}}{{#returnSimpleType}}{{{.}}}{{#returnProperty}}{{#isString}}*{{/isString}}{{/returnProperty}}{{/returnSimpleType}}{{^returnSimpleType}}{{#isArray}}{{{.}}}_t*{{/isArray}}{{#isMap}}{{{.}}}{{/isMap}}{{/returnSimpleType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}{{#returnProperty}}{{^isEnum}}{{{returnType}}}_t*{{/isEnum}}{{#isEnum}}{{projectName}}_{{{returnType}}}_{{returnEnumName}}_e{{/isEnum}}{{/returnProperty}}{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void{{/returnType}}
36-
{{{classname}}}_{{{operationId}}}(apiClient_t *apiClient{{#allParams}}, {{#isPrimitiveType}}{{#isNumber}}{{{dataType}}} {{/isNumber}}{{#isLong}}{{{dataType}}} {{/isLong}}{{#isInteger}}{{{dataType}}} *{{/isInteger}}{{#isDouble}}{{{dataType}}} {{/isDouble}}{{#isFloat}}{{{dataType}}} {{/isFloat}}{{#isBoolean}}{{dataType}} *{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e {{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}} *{{/isByteArray}}{{#isDate}}{{{dataType}}} {{/isDate}}{{#isDateTime}}{{{dataType}}} {{/isDateTime}}{{#isFile}}{{{dataType}}} {{/isFile}}{{#isFreeFormObject}}{{dataType}}_t *{{/isFreeFormObject}}{{/isPrimitiveType}}{{^isArray}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e {{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e {{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}} {{/isEmail}}{{/isPrimitiveType}}{{/isArray}}{{#isContainer}}{{#isArray}}{{dataType}}_t *{{/isArray}}{{#isMap}}{{dataType}} {{/isMap}}{{/isContainer}}{{{paramName}}}{{/allParams}});
36+
{{{classname}}}_{{{operationId}}}(apiClient_t *apiClient{{#allParams}}, {{#isPrimitiveType}}{{#isNumber}}{{{dataType}}} *{{/isNumber}}{{#isLong}}{{{dataType}}} *{{/isLong}}{{#isInteger}}{{{dataType}}} *{{/isInteger}}{{#isDouble}}{{{dataType}}} *{{/isDouble}}{{#isFloat}}{{{dataType}}} *{{/isFloat}}{{#isBoolean}}{{dataType}} *{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e {{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}} *{{/isByteArray}}{{#isDate}}{{{dataType}}} {{/isDate}}{{#isDateTime}}{{{dataType}}} {{/isDateTime}}{{#isFile}}{{{dataType}}} {{/isFile}}{{#isFreeFormObject}}{{dataType}}_t *{{/isFreeFormObject}}{{/isPrimitiveType}}{{^isArray}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e {{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e {{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}} {{/isEmail}}{{/isPrimitiveType}}{{/isArray}}{{#isContainer}}{{#isArray}}{{dataType}}_t *{{/isArray}}{{#isMap}}{{dataType}} {{/isMap}}{{/isContainer}}{{{paramName}}}{{/allParams}});
3737

3838

3939
{{/operation}}

samples/client/others/c/bearerAuth/api/DefaultAPI.c

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "DefaultAPI.h"
55

66
#define MAX_NUMBER_LENGTH 16
7+
#define MAX_NUMBER_LENGTH_FLOAT 32
8+
#define MAX_NUMBER_LENGTH_LONG 21
79
#define MAX_BUFFER_LENGTH 4096
810

911

samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c

+17-15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "PetAPI.h"
55

66
#define MAX_NUMBER_LENGTH 16
7+
#define MAX_NUMBER_LENGTH_FLOAT 32
8+
#define MAX_NUMBER_LENGTH_LONG 21
79
#define MAX_BUFFER_LENGTH 4096
810

911
// Functions for enum STATUS for PetAPI_findPetsByStatus
@@ -123,7 +125,7 @@ PetAPI_addPet(apiClient_t *apiClient, pet_t *body)
123125
// Deletes a pet
124126
//
125127
void
126-
PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key)
128+
PetAPI_deletePet(apiClient_t *apiClient, long *petId, char *api_key)
127129
{
128130
list_t *localVarQueryParameters = NULL;
129131
list_t *localVarHeaderParameters = list_createList();
@@ -142,15 +144,15 @@ PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key)
142144

143145

144146
// Path Params
145-
long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1;
147+
long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1;
146148
if(petId == 0){
147149
goto end;
148150
}
149151
char* localVarToReplace_petId = malloc(sizeOfPathParams_petId);
150152
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId");
151153

152154
char localVarBuff_petId[256];
153-
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId);
155+
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId);
154156

155157
localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId);
156158

@@ -457,7 +459,7 @@ PetAPI_getDaysWithoutIncident(apiClient_t *apiClient)
457459
// Returns a single pet
458460
//
459461
pet_t*
460-
PetAPI_getPetById(apiClient_t *apiClient, long petId)
462+
PetAPI_getPetById(apiClient_t *apiClient, long *petId)
461463
{
462464
list_t *localVarQueryParameters = NULL;
463465
list_t *localVarHeaderParameters = NULL;
@@ -476,15 +478,15 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId)
476478

477479

478480
// Path Params
479-
long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1;
481+
long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1;
480482
if(petId == 0){
481483
goto end;
482484
}
483485
char* localVarToReplace_petId = malloc(sizeOfPathParams_petId);
484486
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId");
485487

486488
char localVarBuff_petId[256];
487-
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId);
489+
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId);
488490

489491
localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId);
490492

@@ -610,7 +612,7 @@ PetAPI_getPicture(apiClient_t *apiClient)
610612
// Is this pet still available?
611613
//
612614
openapi_petstore_bit__e
613-
PetAPI_isPetAvailable(apiClient_t *apiClient, long petId)
615+
PetAPI_isPetAvailable(apiClient_t *apiClient, long *petId)
614616
{
615617
list_t *localVarQueryParameters = NULL;
616618
list_t *localVarHeaderParameters = NULL;
@@ -629,15 +631,15 @@ PetAPI_isPetAvailable(apiClient_t *apiClient, long petId)
629631

630632

631633
// Path Params
632-
long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1;
634+
long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1;
633635
if(petId == 0){
634636
goto end;
635637
}
636638
char* localVarToReplace_petId = malloc(sizeOfPathParams_petId);
637639
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId");
638640

639641
char localVarBuff_petId[256];
640-
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId);
642+
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId);
641643

642644
localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId);
643645

@@ -909,7 +911,7 @@ PetAPI_updatePet(apiClient_t *apiClient, pet_t *body)
909911
// Updates a pet in the store with form data
910912
//
911913
void
912-
PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *status)
914+
PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char *status)
913915
{
914916
list_t *localVarQueryParameters = NULL;
915917
list_t *localVarHeaderParameters = NULL;
@@ -928,15 +930,15 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *s
928930

929931

930932
// Path Params
931-
long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1;
933+
long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1;
932934
if(petId == 0){
933935
goto end;
934936
}
935937
char* localVarToReplace_petId = malloc(sizeOfPathParams_petId);
936938
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId");
937939

938940
char localVarBuff_petId[256];
939-
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId);
941+
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId);
940942

941943
localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId);
942944

@@ -1020,7 +1022,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *s
10201022
// uploads an image
10211023
//
10221024
api_response_t*
1023-
PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, binary_t* file)
1025+
PetAPI_uploadFile(apiClient_t *apiClient, long *petId, char *additionalMetadata, binary_t* file)
10241026
{
10251027
list_t *localVarQueryParameters = NULL;
10261028
list_t *localVarHeaderParameters = NULL;
@@ -1039,15 +1041,15 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata,
10391041

10401042

10411043
// Path Params
1042-
long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1;
1044+
long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1;
10431045
if(petId == 0){
10441046
goto end;
10451047
}
10461048
char* localVarToReplace_petId = malloc(sizeOfPathParams_petId);
10471049
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId");
10481050

10491051
char localVarBuff_petId[256];
1050-
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId);
1052+
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId);
10511053

10521054
localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId);
10531055

samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ PetAPI_addPet(apiClient_t *apiClient, pet_t *body);
2323
// Deletes a pet
2424
//
2525
void
26-
PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key);
26+
PetAPI_deletePet(apiClient_t *apiClient, long *petId, char *api_key);
2727

2828

2929
// Finds Pets by status
@@ -53,7 +53,7 @@ PetAPI_getDaysWithoutIncident(apiClient_t *apiClient);
5353
// Returns a single pet
5454
//
5555
pet_t*
56-
PetAPI_getPetById(apiClient_t *apiClient, long petId);
56+
PetAPI_getPetById(apiClient_t *apiClient, long *petId);
5757

5858

5959
// Get a random picture of someone else's pet
@@ -65,7 +65,7 @@ PetAPI_getPicture(apiClient_t *apiClient);
6565
// Is this pet still available?
6666
//
6767
openapi_petstore_bit__e
68-
PetAPI_isPetAvailable(apiClient_t *apiClient, long petId);
68+
PetAPI_isPetAvailable(apiClient_t *apiClient, long *petId);
6969

7070

7171
// Send a picture of your happy pet
@@ -91,12 +91,12 @@ PetAPI_updatePet(apiClient_t *apiClient, pet_t *body);
9191
// Updates a pet in the store with form data
9292
//
9393
void
94-
PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *status);
94+
PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char *status);
9595

9696

9797
// uploads an image
9898
//
9999
api_response_t*
100-
PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, binary_t* file);
100+
PetAPI_uploadFile(apiClient_t *apiClient, long *petId, char *additionalMetadata, binary_t* file);
101101

102102

samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "StoreAPI.h"
55

66
#define MAX_NUMBER_LENGTH 16
7+
#define MAX_NUMBER_LENGTH_FLOAT 32
8+
#define MAX_NUMBER_LENGTH_LONG 21
79
#define MAX_BUFFER_LENGTH 4096
810

911
// Functions for enum RATING for StoreAPI_sendRating
@@ -207,7 +209,7 @@ StoreAPI_getInventory(apiClient_t *apiClient)
207209
// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions
208210
//
209211
order_t*
210-
StoreAPI_getOrderById(apiClient_t *apiClient, long orderId)
212+
StoreAPI_getOrderById(apiClient_t *apiClient, long *orderId)
211213
{
212214
list_t *localVarQueryParameters = NULL;
213215
list_t *localVarHeaderParameters = NULL;
@@ -226,15 +228,15 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long orderId)
226228

227229

228230
// Path Params
229-
long sizeOfPathParams_orderId = sizeof(orderId)+3 + sizeof("{ orderId }") - 1;
231+
long sizeOfPathParams_orderId = sizeof(*orderId)+3 + sizeof("{ orderId }") - 1;
230232
if(orderId == 0){
231233
goto end;
232234
}
233235
char* localVarToReplace_orderId = malloc(sizeOfPathParams_orderId);
234236
snprintf(localVarToReplace_orderId, sizeOfPathParams_orderId, "{%s}", "orderId");
235237

236238
char localVarBuff_orderId[256];
237-
snprintf(localVarBuff_orderId, sizeof localVarBuff_orderId, "%ld", orderId);
239+
snprintf(localVarBuff_orderId, sizeof localVarBuff_orderId, "%ld", *orderId);
238240

239241
localVarPath = strReplace(localVarPath, localVarToReplace_orderId, localVarBuff_orderId);
240242

samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ StoreAPI_getInventory(apiClient_t *apiClient);
3232
// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions
3333
//
3434
order_t*
35-
StoreAPI_getOrderById(apiClient_t *apiClient, long orderId);
35+
StoreAPI_getOrderById(apiClient_t *apiClient, long *orderId);
3636

3737

3838
// Place an order for a pet

samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "UserAPI.h"
55

66
#define MAX_NUMBER_LENGTH 16
7+
#define MAX_NUMBER_LENGTH_FLOAT 32
8+
#define MAX_NUMBER_LENGTH_LONG 21
79
#define MAX_BUFFER_LENGTH 4096
810

911

0 commit comments

Comments
 (0)