From f99c5b038276aed511f4e81cc8cec16acc6f085f Mon Sep 17 00:00:00 2001 From: Amaury Graillat Date: Thu, 17 Apr 2025 10:46:51 +0200 Subject: [PATCH 1/6] [C-Curl] Client generator does not handle float properly (#21092) - Change function signature to float* - Change generator to convert float to string - Similar change for double and long --- .../resources/C-libcurl/api-body.mustache | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache index 91277d21dc54..3362c7e74a8c 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache @@ -4,6 +4,8 @@ #include "{{classname}}.h" #define MAX_NUMBER_LENGTH 16 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 {{#operations}} @@ -94,7 +96,7 @@ end: // {{/notes}} {{#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}} -{{{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}}) +{{{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}}) { list_t *localVarQueryParameters = {{#hasQueryParams}}list_createList();{{/hasQueryParams}}{{^hasQueryParams}}NULL;{{/hasQueryParams}} list_t *localVarHeaderParameters = {{#hasHeaderParams}}list_createList();{{/hasHeaderParams}}{{^hasHeaderParams}}NULL;{{/hasHeaderParams}} @@ -239,6 +241,22 @@ end: {{/isArray}} {{^isArray}} keyQuery_{{{paramName}}} = strdup("{{{baseName}}}"); + {{#isNumber}} + valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH_FLOAT); + snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH_FLOAT, "%f", *{{{paramName}}}); + {{/isNumber}} + {{#isLong}} + valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH_LONG); + snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH_LONG, "%ld", *{{{paramName}}}); + {{/isLong}} + {{#isDouble}} + valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH_FLOAT); + snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH_FLOAT, "%f", *{{{paramName}}}); + {{/isDouble}} + {{#isFloat}} + valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH_FLOAT); + snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH_FLOAT, "%f", *{{{paramName}}}); + {{/isFloat}} {{#isInteger}} valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH); snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH, "%d", *{{{paramName}}}); @@ -249,7 +267,15 @@ end: {{/isBoolean}} {{^isInteger}} {{^isBoolean}} + {{^isNumber}} + {{^isLong}} + {{^isDouble}} + {{^isFloat}} valueQuery_{{{paramName}}} = {{#isString}}{{^isEnum}}strdup({{/isEnum}}{{/isString}}({{{paramName}}}){{#isString}}{{^isEnum}}){{/isEnum}}{{/isString}}; + {{/isFloat}} + {{/isDouble}} + {{/isLong}} + {{/isNumber}} {{/isBoolean}} {{/isInteger}} keyPairQuery_{{paramName}} = keyValuePair_create(keyQuery_{{{paramName}}}, {{#isEnum}}strdup({{{operationId}}}_{{enumName}}_ToString( From ba044a65d51d427fbccea8e8c0d14c50fab0579b Mon Sep 17 00:00:00 2001 From: Amaury Graillat Date: Thu, 17 Apr 2025 13:44:09 +0200 Subject: [PATCH 2/6] [C-Curl] Client generator does not handle float properly (#21092) - Generate samples - Fix generator for headers and path params --- .../resources/C-libcurl/api-body.mustache | 6 ++-- .../resources/C-libcurl/api-header.mustache | 2 +- .../others/c/bearerAuth/api/DefaultAPI.c | 2 ++ .../c-useJsonUnformatted/api/PetAPI.c | 32 ++++++++++--------- .../c-useJsonUnformatted/api/PetAPI.h | 10 +++--- .../c-useJsonUnformatted/api/StoreAPI.c | 8 +++-- .../c-useJsonUnformatted/api/StoreAPI.h | 2 +- .../c-useJsonUnformatted/api/UserAPI.c | 2 ++ samples/client/petstore/c/api/PetAPI.c | 32 ++++++++++--------- samples/client/petstore/c/api/PetAPI.h | 10 +++--- samples/client/petstore/c/api/StoreAPI.c | 8 +++-- samples/client/petstore/c/api/StoreAPI.h | 2 +- samples/client/petstore/c/api/UserAPI.c | 2 ++ 13 files changed, 66 insertions(+), 52 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache index 3362c7e74a8c..8f6ec45f1fdb 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache @@ -126,7 +126,7 @@ end: {{#pathParams}} // Path Params - 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; + 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; {{#isNumeric}} if({{paramName}} == 0){ goto end; @@ -161,7 +161,7 @@ end: snprintf(localVarToReplace_{{paramName}}, sizeOfPathParams_{{paramName}}, "{%s}", "{{baseName}}"); char localVarBuff_{{paramName}}[256]; - snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", (long){{paramName}}); + snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", (long)*{{paramName}}); localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, localVarBuff_{{paramName}}); @@ -174,7 +174,7 @@ end: snprintf(localVarToReplace_{{paramName}}, sizeOfPathParams_{{paramName}}, "{%s}", "{{baseName}}"); char localVarBuff_{{paramName}}[256]; - snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", {{paramName}}); + snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", *{{paramName}}); localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, localVarBuff_{{paramName}}); diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache index 4feb6ec9e10f..29cff6ca2d33 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache @@ -33,7 +33,7 @@ typedef enum { {{projectName}}_{{operationId}}_{{enumName}}_NULL = 0{{#enumVars // {{/notes}} {{#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}} -{{{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}}); +{{{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}}); {{/operation}} diff --git a/samples/client/others/c/bearerAuth/api/DefaultAPI.c b/samples/client/others/c/bearerAuth/api/DefaultAPI.c index b3e5c7709bf3..8e561456ce55 100644 --- a/samples/client/others/c/bearerAuth/api/DefaultAPI.c +++ b/samples/client/others/c/bearerAuth/api/DefaultAPI.c @@ -4,6 +4,8 @@ #include "DefaultAPI.h" #define MAX_NUMBER_LENGTH 16 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 diff --git a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c index 5002790c018f..812cc0db7d65 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c +++ b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c @@ -4,6 +4,8 @@ #include "PetAPI.h" #define MAX_NUMBER_LENGTH 16 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 // Functions for enum STATUS for PetAPI_findPetsByStatus @@ -123,7 +125,7 @@ PetAPI_addPet(apiClient_t *apiClient, pet_t *body) // Deletes a pet // void -PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key) +PetAPI_deletePet(apiClient_t *apiClient, long *petId, char *api_key) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = list_createList(); @@ -142,7 +144,7 @@ PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key) // Path Params - long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -150,7 +152,7 @@ PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key) snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -457,7 +459,7 @@ PetAPI_getDaysWithoutIncident(apiClient_t *apiClient) // Returns a single pet // pet_t* -PetAPI_getPetById(apiClient_t *apiClient, long petId) +PetAPI_getPetById(apiClient_t *apiClient, long *petId) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -476,7 +478,7 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId) // Path Params - long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -484,7 +486,7 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId) snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -610,7 +612,7 @@ PetAPI_getPicture(apiClient_t *apiClient) // Is this pet still available? // openapi_petstore_bit__e -PetAPI_isPetAvailable(apiClient_t *apiClient, long petId) +PetAPI_isPetAvailable(apiClient_t *apiClient, long *petId) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -629,7 +631,7 @@ PetAPI_isPetAvailable(apiClient_t *apiClient, long petId) // Path Params - long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -637,7 +639,7 @@ PetAPI_isPetAvailable(apiClient_t *apiClient, long petId) snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -909,7 +911,7 @@ PetAPI_updatePet(apiClient_t *apiClient, pet_t *body) // Updates a pet in the store with form data // void -PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *status) +PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char *status) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -928,7 +930,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *s // Path Params - long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -936,7 +938,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *s snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -1020,7 +1022,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *s // uploads an image // api_response_t* -PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, binary_t* file) +PetAPI_uploadFile(apiClient_t *apiClient, long *petId, char *additionalMetadata, binary_t* file) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -1039,7 +1041,7 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, // Path Params - long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -1047,7 +1049,7 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); diff --git a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h index 3dc0c570c29e..37e51d4aba50 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h +++ b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h @@ -23,7 +23,7 @@ PetAPI_addPet(apiClient_t *apiClient, pet_t *body); // Deletes a pet // void -PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key); +PetAPI_deletePet(apiClient_t *apiClient, long *petId, char *api_key); // Finds Pets by status @@ -53,7 +53,7 @@ PetAPI_getDaysWithoutIncident(apiClient_t *apiClient); // Returns a single pet // pet_t* -PetAPI_getPetById(apiClient_t *apiClient, long petId); +PetAPI_getPetById(apiClient_t *apiClient, long *petId); // Get a random picture of someone else's pet @@ -65,7 +65,7 @@ PetAPI_getPicture(apiClient_t *apiClient); // Is this pet still available? // openapi_petstore_bit__e -PetAPI_isPetAvailable(apiClient_t *apiClient, long petId); +PetAPI_isPetAvailable(apiClient_t *apiClient, long *petId); // Send a picture of your happy pet @@ -91,12 +91,12 @@ PetAPI_updatePet(apiClient_t *apiClient, pet_t *body); // Updates a pet in the store with form data // void -PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *status); +PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char *status); // uploads an image // api_response_t* -PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, binary_t* file); +PetAPI_uploadFile(apiClient_t *apiClient, long *petId, char *additionalMetadata, binary_t* file); diff --git a/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c b/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c index 426f3b0d73b1..c93d4445ea99 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c +++ b/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c @@ -4,6 +4,8 @@ #include "StoreAPI.h" #define MAX_NUMBER_LENGTH 16 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 // Functions for enum RATING for StoreAPI_sendRating @@ -207,7 +209,7 @@ StoreAPI_getInventory(apiClient_t *apiClient) // For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions // order_t* -StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) +StoreAPI_getOrderById(apiClient_t *apiClient, long *orderId) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -226,7 +228,7 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) // Path Params - long sizeOfPathParams_orderId = sizeof(orderId)+3 + sizeof("{ orderId }") - 1; + long sizeOfPathParams_orderId = sizeof(*orderId)+3 + sizeof("{ orderId }") - 1; if(orderId == 0){ goto end; } @@ -234,7 +236,7 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) snprintf(localVarToReplace_orderId, sizeOfPathParams_orderId, "{%s}", "orderId"); char localVarBuff_orderId[256]; - snprintf(localVarBuff_orderId, sizeof localVarBuff_orderId, "%ld", orderId); + snprintf(localVarBuff_orderId, sizeof localVarBuff_orderId, "%ld", *orderId); localVarPath = strReplace(localVarPath, localVarToReplace_orderId, localVarBuff_orderId); diff --git a/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.h b/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.h index 693d21b7dd64..dafd86bc0a48 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.h +++ b/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.h @@ -32,7 +32,7 @@ StoreAPI_getInventory(apiClient_t *apiClient); // For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions // order_t* -StoreAPI_getOrderById(apiClient_t *apiClient, long orderId); +StoreAPI_getOrderById(apiClient_t *apiClient, long *orderId); // Place an order for a pet diff --git a/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c b/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c index 3f20e0114cff..09925e9ac951 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c +++ b/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c @@ -4,6 +4,8 @@ #include "UserAPI.h" #define MAX_NUMBER_LENGTH 16 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 diff --git a/samples/client/petstore/c/api/PetAPI.c b/samples/client/petstore/c/api/PetAPI.c index 0037e2fdcf21..a3a8738e7fc6 100644 --- a/samples/client/petstore/c/api/PetAPI.c +++ b/samples/client/petstore/c/api/PetAPI.c @@ -4,6 +4,8 @@ #include "PetAPI.h" #define MAX_NUMBER_LENGTH 16 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 // Functions for enum STATUS for PetAPI_findPetsByStatus @@ -123,7 +125,7 @@ PetAPI_addPet(apiClient_t *apiClient, pet_t *body) // Deletes a pet // void -PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key) +PetAPI_deletePet(apiClient_t *apiClient, long *petId, char *api_key) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = list_createList(); @@ -142,7 +144,7 @@ PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key) // Path Params - long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -150,7 +152,7 @@ PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key) snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -457,7 +459,7 @@ PetAPI_getDaysWithoutIncident(apiClient_t *apiClient) // Returns a single pet // pet_t* -PetAPI_getPetById(apiClient_t *apiClient, long petId) +PetAPI_getPetById(apiClient_t *apiClient, long *petId) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -476,7 +478,7 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId) // Path Params - long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -484,7 +486,7 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId) snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -610,7 +612,7 @@ PetAPI_getPicture(apiClient_t *apiClient) // Is this pet still available? // openapi_petstore_bit__e -PetAPI_isPetAvailable(apiClient_t *apiClient, long petId) +PetAPI_isPetAvailable(apiClient_t *apiClient, long *petId) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -629,7 +631,7 @@ PetAPI_isPetAvailable(apiClient_t *apiClient, long petId) // Path Params - long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -637,7 +639,7 @@ PetAPI_isPetAvailable(apiClient_t *apiClient, long petId) snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -909,7 +911,7 @@ PetAPI_updatePet(apiClient_t *apiClient, pet_t *body) // Updates a pet in the store with form data // void -PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *status) +PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char *status) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -928,7 +930,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *s // Path Params - long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -936,7 +938,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *s snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -1020,7 +1022,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *s // uploads an image // api_response_t* -PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, binary_t* file) +PetAPI_uploadFile(apiClient_t *apiClient, long *petId, char *additionalMetadata, binary_t* file) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -1039,7 +1041,7 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, // Path Params - long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -1047,7 +1049,7 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); diff --git a/samples/client/petstore/c/api/PetAPI.h b/samples/client/petstore/c/api/PetAPI.h index 3dc0c570c29e..37e51d4aba50 100644 --- a/samples/client/petstore/c/api/PetAPI.h +++ b/samples/client/petstore/c/api/PetAPI.h @@ -23,7 +23,7 @@ PetAPI_addPet(apiClient_t *apiClient, pet_t *body); // Deletes a pet // void -PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key); +PetAPI_deletePet(apiClient_t *apiClient, long *petId, char *api_key); // Finds Pets by status @@ -53,7 +53,7 @@ PetAPI_getDaysWithoutIncident(apiClient_t *apiClient); // Returns a single pet // pet_t* -PetAPI_getPetById(apiClient_t *apiClient, long petId); +PetAPI_getPetById(apiClient_t *apiClient, long *petId); // Get a random picture of someone else's pet @@ -65,7 +65,7 @@ PetAPI_getPicture(apiClient_t *apiClient); // Is this pet still available? // openapi_petstore_bit__e -PetAPI_isPetAvailable(apiClient_t *apiClient, long petId); +PetAPI_isPetAvailable(apiClient_t *apiClient, long *petId); // Send a picture of your happy pet @@ -91,12 +91,12 @@ PetAPI_updatePet(apiClient_t *apiClient, pet_t *body); // Updates a pet in the store with form data // void -PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *status); +PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char *status); // uploads an image // api_response_t* -PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, binary_t* file); +PetAPI_uploadFile(apiClient_t *apiClient, long *petId, char *additionalMetadata, binary_t* file); diff --git a/samples/client/petstore/c/api/StoreAPI.c b/samples/client/petstore/c/api/StoreAPI.c index 473de05e28c9..81a40c751b03 100644 --- a/samples/client/petstore/c/api/StoreAPI.c +++ b/samples/client/petstore/c/api/StoreAPI.c @@ -4,6 +4,8 @@ #include "StoreAPI.h" #define MAX_NUMBER_LENGTH 16 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 // Functions for enum RATING for StoreAPI_sendRating @@ -207,7 +209,7 @@ StoreAPI_getInventory(apiClient_t *apiClient) // For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions // order_t* -StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) +StoreAPI_getOrderById(apiClient_t *apiClient, long *orderId) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -226,7 +228,7 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) // Path Params - long sizeOfPathParams_orderId = sizeof(orderId)+3 + sizeof("{ orderId }") - 1; + long sizeOfPathParams_orderId = sizeof(*orderId)+3 + sizeof("{ orderId }") - 1; if(orderId == 0){ goto end; } @@ -234,7 +236,7 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) snprintf(localVarToReplace_orderId, sizeOfPathParams_orderId, "{%s}", "orderId"); char localVarBuff_orderId[256]; - snprintf(localVarBuff_orderId, sizeof localVarBuff_orderId, "%ld", orderId); + snprintf(localVarBuff_orderId, sizeof localVarBuff_orderId, "%ld", *orderId); localVarPath = strReplace(localVarPath, localVarToReplace_orderId, localVarBuff_orderId); diff --git a/samples/client/petstore/c/api/StoreAPI.h b/samples/client/petstore/c/api/StoreAPI.h index 693d21b7dd64..dafd86bc0a48 100644 --- a/samples/client/petstore/c/api/StoreAPI.h +++ b/samples/client/petstore/c/api/StoreAPI.h @@ -32,7 +32,7 @@ StoreAPI_getInventory(apiClient_t *apiClient); // For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions // order_t* -StoreAPI_getOrderById(apiClient_t *apiClient, long orderId); +StoreAPI_getOrderById(apiClient_t *apiClient, long *orderId); // Place an order for a pet diff --git a/samples/client/petstore/c/api/UserAPI.c b/samples/client/petstore/c/api/UserAPI.c index 62b520c4034d..37c80b3d4086 100644 --- a/samples/client/petstore/c/api/UserAPI.c +++ b/samples/client/petstore/c/api/UserAPI.c @@ -4,6 +4,8 @@ #include "UserAPI.h" #define MAX_NUMBER_LENGTH 16 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 From 55c66268bac5ed8a46e97e14f4d23780b7c4fba8 Mon Sep 17 00:00:00 2001 From: Amaury Graillat Date: Mon, 28 Apr 2025 13:39:31 +0200 Subject: [PATCH 3/6] Revert "[C-Curl] Client generator does not handle float properly (#21092)" This reverts commit ba044a65d51d427fbccea8e8c0d14c50fab0579b. --- .../resources/C-libcurl/api-body.mustache | 6 ++-- .../resources/C-libcurl/api-header.mustache | 2 +- .../others/c/bearerAuth/api/DefaultAPI.c | 2 -- .../c-useJsonUnformatted/api/PetAPI.c | 32 +++++++++---------- .../c-useJsonUnformatted/api/PetAPI.h | 10 +++--- .../c-useJsonUnformatted/api/StoreAPI.c | 8 ++--- .../c-useJsonUnformatted/api/StoreAPI.h | 2 +- .../c-useJsonUnformatted/api/UserAPI.c | 2 -- samples/client/petstore/c/api/PetAPI.c | 32 +++++++++---------- samples/client/petstore/c/api/PetAPI.h | 10 +++--- samples/client/petstore/c/api/StoreAPI.c | 8 ++--- samples/client/petstore/c/api/StoreAPI.h | 2 +- samples/client/petstore/c/api/UserAPI.c | 2 -- 13 files changed, 52 insertions(+), 66 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache index 8f6ec45f1fdb..3362c7e74a8c 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache @@ -126,7 +126,7 @@ end: {{#pathParams}} // Path Params - 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; + 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; {{#isNumeric}} if({{paramName}} == 0){ goto end; @@ -161,7 +161,7 @@ end: snprintf(localVarToReplace_{{paramName}}, sizeOfPathParams_{{paramName}}, "{%s}", "{{baseName}}"); char localVarBuff_{{paramName}}[256]; - snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", (long)*{{paramName}}); + snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", (long){{paramName}}); localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, localVarBuff_{{paramName}}); @@ -174,7 +174,7 @@ end: snprintf(localVarToReplace_{{paramName}}, sizeOfPathParams_{{paramName}}, "{%s}", "{{baseName}}"); char localVarBuff_{{paramName}}[256]; - snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", *{{paramName}}); + snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", {{paramName}}); localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, localVarBuff_{{paramName}}); diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache index 29cff6ca2d33..4feb6ec9e10f 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache @@ -33,7 +33,7 @@ typedef enum { {{projectName}}_{{operationId}}_{{enumName}}_NULL = 0{{#enumVars // {{/notes}} {{#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}} -{{{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}}); +{{{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}}); {{/operation}} diff --git a/samples/client/others/c/bearerAuth/api/DefaultAPI.c b/samples/client/others/c/bearerAuth/api/DefaultAPI.c index 8e561456ce55..b3e5c7709bf3 100644 --- a/samples/client/others/c/bearerAuth/api/DefaultAPI.c +++ b/samples/client/others/c/bearerAuth/api/DefaultAPI.c @@ -4,8 +4,6 @@ #include "DefaultAPI.h" #define MAX_NUMBER_LENGTH 16 -#define MAX_NUMBER_LENGTH_FLOAT 32 -#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 diff --git a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c index 812cc0db7d65..5002790c018f 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c +++ b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c @@ -4,8 +4,6 @@ #include "PetAPI.h" #define MAX_NUMBER_LENGTH 16 -#define MAX_NUMBER_LENGTH_FLOAT 32 -#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 // Functions for enum STATUS for PetAPI_findPetsByStatus @@ -125,7 +123,7 @@ PetAPI_addPet(apiClient_t *apiClient, pet_t *body) // Deletes a pet // void -PetAPI_deletePet(apiClient_t *apiClient, long *petId, char *api_key) +PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = list_createList(); @@ -144,7 +142,7 @@ PetAPI_deletePet(apiClient_t *apiClient, long *petId, char *api_key) // Path Params - long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -152,7 +150,7 @@ PetAPI_deletePet(apiClient_t *apiClient, long *petId, char *api_key) snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -459,7 +457,7 @@ PetAPI_getDaysWithoutIncident(apiClient_t *apiClient) // Returns a single pet // pet_t* -PetAPI_getPetById(apiClient_t *apiClient, long *petId) +PetAPI_getPetById(apiClient_t *apiClient, long petId) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -478,7 +476,7 @@ PetAPI_getPetById(apiClient_t *apiClient, long *petId) // Path Params - long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -486,7 +484,7 @@ PetAPI_getPetById(apiClient_t *apiClient, long *petId) snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -612,7 +610,7 @@ PetAPI_getPicture(apiClient_t *apiClient) // Is this pet still available? // openapi_petstore_bit__e -PetAPI_isPetAvailable(apiClient_t *apiClient, long *petId) +PetAPI_isPetAvailable(apiClient_t *apiClient, long petId) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -631,7 +629,7 @@ PetAPI_isPetAvailable(apiClient_t *apiClient, long *petId) // Path Params - long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -639,7 +637,7 @@ PetAPI_isPetAvailable(apiClient_t *apiClient, long *petId) snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -911,7 +909,7 @@ PetAPI_updatePet(apiClient_t *apiClient, pet_t *body) // Updates a pet in the store with form data // void -PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char *status) +PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *status) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -930,7 +928,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char * // Path Params - long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -938,7 +936,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char * snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -1022,7 +1020,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char * // uploads an image // api_response_t* -PetAPI_uploadFile(apiClient_t *apiClient, long *petId, char *additionalMetadata, binary_t* file) +PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, binary_t* file) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -1041,7 +1039,7 @@ PetAPI_uploadFile(apiClient_t *apiClient, long *petId, char *additionalMetadata, // Path Params - long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -1049,7 +1047,7 @@ PetAPI_uploadFile(apiClient_t *apiClient, long *petId, char *additionalMetadata, snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); diff --git a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h index 37e51d4aba50..3dc0c570c29e 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h +++ b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h @@ -23,7 +23,7 @@ PetAPI_addPet(apiClient_t *apiClient, pet_t *body); // Deletes a pet // void -PetAPI_deletePet(apiClient_t *apiClient, long *petId, char *api_key); +PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key); // Finds Pets by status @@ -53,7 +53,7 @@ PetAPI_getDaysWithoutIncident(apiClient_t *apiClient); // Returns a single pet // pet_t* -PetAPI_getPetById(apiClient_t *apiClient, long *petId); +PetAPI_getPetById(apiClient_t *apiClient, long petId); // Get a random picture of someone else's pet @@ -65,7 +65,7 @@ PetAPI_getPicture(apiClient_t *apiClient); // Is this pet still available? // openapi_petstore_bit__e -PetAPI_isPetAvailable(apiClient_t *apiClient, long *petId); +PetAPI_isPetAvailable(apiClient_t *apiClient, long petId); // Send a picture of your happy pet @@ -91,12 +91,12 @@ PetAPI_updatePet(apiClient_t *apiClient, pet_t *body); // Updates a pet in the store with form data // void -PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char *status); +PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *status); // uploads an image // api_response_t* -PetAPI_uploadFile(apiClient_t *apiClient, long *petId, char *additionalMetadata, binary_t* file); +PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, binary_t* file); diff --git a/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c b/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c index c93d4445ea99..426f3b0d73b1 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c +++ b/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c @@ -4,8 +4,6 @@ #include "StoreAPI.h" #define MAX_NUMBER_LENGTH 16 -#define MAX_NUMBER_LENGTH_FLOAT 32 -#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 // Functions for enum RATING for StoreAPI_sendRating @@ -209,7 +207,7 @@ StoreAPI_getInventory(apiClient_t *apiClient) // For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions // order_t* -StoreAPI_getOrderById(apiClient_t *apiClient, long *orderId) +StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -228,7 +226,7 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long *orderId) // Path Params - long sizeOfPathParams_orderId = sizeof(*orderId)+3 + sizeof("{ orderId }") - 1; + long sizeOfPathParams_orderId = sizeof(orderId)+3 + sizeof("{ orderId }") - 1; if(orderId == 0){ goto end; } @@ -236,7 +234,7 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long *orderId) snprintf(localVarToReplace_orderId, sizeOfPathParams_orderId, "{%s}", "orderId"); char localVarBuff_orderId[256]; - snprintf(localVarBuff_orderId, sizeof localVarBuff_orderId, "%ld", *orderId); + snprintf(localVarBuff_orderId, sizeof localVarBuff_orderId, "%ld", orderId); localVarPath = strReplace(localVarPath, localVarToReplace_orderId, localVarBuff_orderId); diff --git a/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.h b/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.h index dafd86bc0a48..693d21b7dd64 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.h +++ b/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.h @@ -32,7 +32,7 @@ StoreAPI_getInventory(apiClient_t *apiClient); // For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions // order_t* -StoreAPI_getOrderById(apiClient_t *apiClient, long *orderId); +StoreAPI_getOrderById(apiClient_t *apiClient, long orderId); // Place an order for a pet diff --git a/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c b/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c index 09925e9ac951..3f20e0114cff 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c +++ b/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c @@ -4,8 +4,6 @@ #include "UserAPI.h" #define MAX_NUMBER_LENGTH 16 -#define MAX_NUMBER_LENGTH_FLOAT 32 -#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 diff --git a/samples/client/petstore/c/api/PetAPI.c b/samples/client/petstore/c/api/PetAPI.c index a3a8738e7fc6..0037e2fdcf21 100644 --- a/samples/client/petstore/c/api/PetAPI.c +++ b/samples/client/petstore/c/api/PetAPI.c @@ -4,8 +4,6 @@ #include "PetAPI.h" #define MAX_NUMBER_LENGTH 16 -#define MAX_NUMBER_LENGTH_FLOAT 32 -#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 // Functions for enum STATUS for PetAPI_findPetsByStatus @@ -125,7 +123,7 @@ PetAPI_addPet(apiClient_t *apiClient, pet_t *body) // Deletes a pet // void -PetAPI_deletePet(apiClient_t *apiClient, long *petId, char *api_key) +PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = list_createList(); @@ -144,7 +142,7 @@ PetAPI_deletePet(apiClient_t *apiClient, long *petId, char *api_key) // Path Params - long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -152,7 +150,7 @@ PetAPI_deletePet(apiClient_t *apiClient, long *petId, char *api_key) snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -459,7 +457,7 @@ PetAPI_getDaysWithoutIncident(apiClient_t *apiClient) // Returns a single pet // pet_t* -PetAPI_getPetById(apiClient_t *apiClient, long *petId) +PetAPI_getPetById(apiClient_t *apiClient, long petId) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -478,7 +476,7 @@ PetAPI_getPetById(apiClient_t *apiClient, long *petId) // Path Params - long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -486,7 +484,7 @@ PetAPI_getPetById(apiClient_t *apiClient, long *petId) snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -612,7 +610,7 @@ PetAPI_getPicture(apiClient_t *apiClient) // Is this pet still available? // openapi_petstore_bit__e -PetAPI_isPetAvailable(apiClient_t *apiClient, long *petId) +PetAPI_isPetAvailable(apiClient_t *apiClient, long petId) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -631,7 +629,7 @@ PetAPI_isPetAvailable(apiClient_t *apiClient, long *petId) // Path Params - long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -639,7 +637,7 @@ PetAPI_isPetAvailable(apiClient_t *apiClient, long *petId) snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -911,7 +909,7 @@ PetAPI_updatePet(apiClient_t *apiClient, pet_t *body) // Updates a pet in the store with form data // void -PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char *status) +PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *status) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -930,7 +928,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char * // Path Params - long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -938,7 +936,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char * snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); @@ -1022,7 +1020,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char * // uploads an image // api_response_t* -PetAPI_uploadFile(apiClient_t *apiClient, long *petId, char *additionalMetadata, binary_t* file) +PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, binary_t* file) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -1041,7 +1039,7 @@ PetAPI_uploadFile(apiClient_t *apiClient, long *petId, char *additionalMetadata, // Path Params - long sizeOfPathParams_petId = sizeof(*petId)+3 + sizeof("{ petId }") - 1; + long sizeOfPathParams_petId = sizeof(petId)+3 + sizeof("{ petId }") - 1; if(petId == 0){ goto end; } @@ -1049,7 +1047,7 @@ PetAPI_uploadFile(apiClient_t *apiClient, long *petId, char *additionalMetadata, snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId"); char localVarBuff_petId[256]; - snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", *petId); + snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId); localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId); diff --git a/samples/client/petstore/c/api/PetAPI.h b/samples/client/petstore/c/api/PetAPI.h index 37e51d4aba50..3dc0c570c29e 100644 --- a/samples/client/petstore/c/api/PetAPI.h +++ b/samples/client/petstore/c/api/PetAPI.h @@ -23,7 +23,7 @@ PetAPI_addPet(apiClient_t *apiClient, pet_t *body); // Deletes a pet // void -PetAPI_deletePet(apiClient_t *apiClient, long *petId, char *api_key); +PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key); // Finds Pets by status @@ -53,7 +53,7 @@ PetAPI_getDaysWithoutIncident(apiClient_t *apiClient); // Returns a single pet // pet_t* -PetAPI_getPetById(apiClient_t *apiClient, long *petId); +PetAPI_getPetById(apiClient_t *apiClient, long petId); // Get a random picture of someone else's pet @@ -65,7 +65,7 @@ PetAPI_getPicture(apiClient_t *apiClient); // Is this pet still available? // openapi_petstore_bit__e -PetAPI_isPetAvailable(apiClient_t *apiClient, long *petId); +PetAPI_isPetAvailable(apiClient_t *apiClient, long petId); // Send a picture of your happy pet @@ -91,12 +91,12 @@ PetAPI_updatePet(apiClient_t *apiClient, pet_t *body); // Updates a pet in the store with form data // void -PetAPI_updatePetWithForm(apiClient_t *apiClient, long *petId, char *name, char *status); +PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *status); // uploads an image // api_response_t* -PetAPI_uploadFile(apiClient_t *apiClient, long *petId, char *additionalMetadata, binary_t* file); +PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, binary_t* file); diff --git a/samples/client/petstore/c/api/StoreAPI.c b/samples/client/petstore/c/api/StoreAPI.c index 81a40c751b03..473de05e28c9 100644 --- a/samples/client/petstore/c/api/StoreAPI.c +++ b/samples/client/petstore/c/api/StoreAPI.c @@ -4,8 +4,6 @@ #include "StoreAPI.h" #define MAX_NUMBER_LENGTH 16 -#define MAX_NUMBER_LENGTH_FLOAT 32 -#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 // Functions for enum RATING for StoreAPI_sendRating @@ -209,7 +207,7 @@ StoreAPI_getInventory(apiClient_t *apiClient) // For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions // order_t* -StoreAPI_getOrderById(apiClient_t *apiClient, long *orderId) +StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) { list_t *localVarQueryParameters = NULL; list_t *localVarHeaderParameters = NULL; @@ -228,7 +226,7 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long *orderId) // Path Params - long sizeOfPathParams_orderId = sizeof(*orderId)+3 + sizeof("{ orderId }") - 1; + long sizeOfPathParams_orderId = sizeof(orderId)+3 + sizeof("{ orderId }") - 1; if(orderId == 0){ goto end; } @@ -236,7 +234,7 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long *orderId) snprintf(localVarToReplace_orderId, sizeOfPathParams_orderId, "{%s}", "orderId"); char localVarBuff_orderId[256]; - snprintf(localVarBuff_orderId, sizeof localVarBuff_orderId, "%ld", *orderId); + snprintf(localVarBuff_orderId, sizeof localVarBuff_orderId, "%ld", orderId); localVarPath = strReplace(localVarPath, localVarToReplace_orderId, localVarBuff_orderId); diff --git a/samples/client/petstore/c/api/StoreAPI.h b/samples/client/petstore/c/api/StoreAPI.h index dafd86bc0a48..693d21b7dd64 100644 --- a/samples/client/petstore/c/api/StoreAPI.h +++ b/samples/client/petstore/c/api/StoreAPI.h @@ -32,7 +32,7 @@ StoreAPI_getInventory(apiClient_t *apiClient); // For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions // order_t* -StoreAPI_getOrderById(apiClient_t *apiClient, long *orderId); +StoreAPI_getOrderById(apiClient_t *apiClient, long orderId); // Place an order for a pet diff --git a/samples/client/petstore/c/api/UserAPI.c b/samples/client/petstore/c/api/UserAPI.c index 37c80b3d4086..62b520c4034d 100644 --- a/samples/client/petstore/c/api/UserAPI.c +++ b/samples/client/petstore/c/api/UserAPI.c @@ -4,8 +4,6 @@ #include "UserAPI.h" #define MAX_NUMBER_LENGTH 16 -#define MAX_NUMBER_LENGTH_FLOAT 32 -#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 From e2f4b2fd7a564af1172091c9679dc38133fffa26 Mon Sep 17 00:00:00 2001 From: Amaury Graillat Date: Mon, 28 Apr 2025 13:39:39 +0200 Subject: [PATCH 4/6] Revert "[C-Curl] Client generator does not handle float properly (#21092)" This reverts commit f99c5b038276aed511f4e81cc8cec16acc6f085f. --- .../resources/C-libcurl/api-body.mustache | 28 +------------------ 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache index 3362c7e74a8c..91277d21dc54 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache @@ -4,8 +4,6 @@ #include "{{classname}}.h" #define MAX_NUMBER_LENGTH 16 -#define MAX_NUMBER_LENGTH_FLOAT 32 -#define MAX_NUMBER_LENGTH_LONG 21 #define MAX_BUFFER_LENGTH 4096 {{#operations}} @@ -96,7 +94,7 @@ end: // {{/notes}} {{#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}} -{{{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}}) +{{{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}}) { list_t *localVarQueryParameters = {{#hasQueryParams}}list_createList();{{/hasQueryParams}}{{^hasQueryParams}}NULL;{{/hasQueryParams}} list_t *localVarHeaderParameters = {{#hasHeaderParams}}list_createList();{{/hasHeaderParams}}{{^hasHeaderParams}}NULL;{{/hasHeaderParams}} @@ -241,22 +239,6 @@ end: {{/isArray}} {{^isArray}} keyQuery_{{{paramName}}} = strdup("{{{baseName}}}"); - {{#isNumber}} - valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH_FLOAT); - snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH_FLOAT, "%f", *{{{paramName}}}); - {{/isNumber}} - {{#isLong}} - valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH_LONG); - snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH_LONG, "%ld", *{{{paramName}}}); - {{/isLong}} - {{#isDouble}} - valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH_FLOAT); - snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH_FLOAT, "%f", *{{{paramName}}}); - {{/isDouble}} - {{#isFloat}} - valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH_FLOAT); - snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH_FLOAT, "%f", *{{{paramName}}}); - {{/isFloat}} {{#isInteger}} valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH); snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH, "%d", *{{{paramName}}}); @@ -267,15 +249,7 @@ end: {{/isBoolean}} {{^isInteger}} {{^isBoolean}} - {{^isNumber}} - {{^isLong}} - {{^isDouble}} - {{^isFloat}} valueQuery_{{{paramName}}} = {{#isString}}{{^isEnum}}strdup({{/isEnum}}{{/isString}}({{{paramName}}}){{#isString}}{{^isEnum}}){{/isEnum}}{{/isString}}; - {{/isFloat}} - {{/isDouble}} - {{/isLong}} - {{/isNumber}} {{/isBoolean}} {{/isInteger}} keyPairQuery_{{paramName}} = keyValuePair_create(keyQuery_{{{paramName}}}, {{#isEnum}}strdup({{{operationId}}}_{{enumName}}_ToString( From b8721a6749306319ac46388ed9a28e2e0e574914 Mon Sep 17 00:00:00 2001 From: Amaury Graillat Date: Mon, 28 Apr 2025 18:08:53 +0200 Subject: [PATCH 5/6] [C-Curl] Client generator does not handle float properly (#21092) - Convert float, double and long to string - Generate samples --- .../resources/C-libcurl/api-body.mustache | 31 ++++- .../others/c/bearerAuth/api/DefaultAPI.c | 3 + .../petstore/c-useJsonUnformatted/README.md | 1 + .../c-useJsonUnformatted/api/PetAPI.c | 3 + .../c-useJsonUnformatted/api/StoreAPI.c | 3 + .../c-useJsonUnformatted/api/UserAPI.c | 107 ++++++++++++++++++ .../c-useJsonUnformatted/api/UserAPI.h | 8 ++ .../c-useJsonUnformatted/docs/UserAPI.md | 34 ++++++ samples/client/petstore/c/README.md | 1 + samples/client/petstore/c/api/PetAPI.c | 3 + samples/client/petstore/c/api/StoreAPI.c | 3 + samples/client/petstore/c/api/UserAPI.c | 107 ++++++++++++++++++ samples/client/petstore/c/api/UserAPI.h | 8 ++ samples/client/petstore/c/docs/UserAPI.md | 34 ++++++ 14 files changed, 344 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache index 91277d21dc54..bf633e5ae265 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache @@ -1,10 +1,13 @@ #include #include #include + #include "{{classname}}.h" #define MAX_NUMBER_LENGTH 16 #define MAX_BUFFER_LENGTH 4096 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 {{#operations}} {{#operation}} @@ -229,10 +232,16 @@ end: // query parameters {{^isArray}} char *keyQuery_{{{paramName}}} = NULL; - {{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}{{{dataType}}}{{/isLong}}{{#isInteger}}char *{{/isInteger}}{{#isDouble}}{{{dataType}}}{{/isDouble}}{{#isFloat}}{{{dataType}}}{{/isFloat}}{{#isBoolean}}char *{{/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}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueQuery_{{{paramName}}} {{#isString}}{{^isEnum}}= NULL{{/isEnum}}{{/isString}}{{#isInteger}}= NULL{{/isInteger}}{{#isBoolean}}= NULL{{/isBoolean}}; + {{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}char *{{/isLong}}{{#isInteger}}char *{{/isInteger}}{{#isDouble}}char *{{/isDouble}}{{#isFloat}}char *{{/isFloat}}{{#isBoolean}}char *{{/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}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueQuery_{{{paramName}}} {{#isString}}{{^isEnum}}= NULL{{/isEnum}}{{/isString}}{{#isInteger}}= NULL{{/isInteger}}{{#isBoolean}}= NULL{{/isBoolean}}; keyValuePair_t *keyPairQuery_{{paramName}} = 0; {{/isArray}} + {{^isLong}} + {{^isFloat}} + {{^isDouble}} if ({{paramName}}) + {{/isDouble}} + {{/isFloat}} + {{/isLong}} { {{#isArray}} list_addElement(localVarQueryParameters,{{paramName}}); @@ -243,17 +252,35 @@ end: valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH); snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH, "%d", *{{{paramName}}}); {{/isInteger}} + {{#isFloat}} + valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH_FLOAT); + snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH_FLOAT, "%f", {{{paramName}}}); + {{/isFloat}} + {{#isDouble}} + valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH_FLOAT); + snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH_FLOAT, "%f", {{{paramName}}}); + {{/isDouble}} + {{#isLong}} + valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH_LONG); + snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH_LONG, "%d", {{{paramName}}}); + {{/isLong}} {{#isBoolean}} valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH); snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH, "%d", *{{{paramName}}}); {{/isBoolean}} {{^isInteger}} {{^isBoolean}} + {{^isFloat}} + {{^isDouble}} + {{^isLong}} valueQuery_{{{paramName}}} = {{#isString}}{{^isEnum}}strdup({{/isEnum}}{{/isString}}({{{paramName}}}){{#isString}}{{^isEnum}}){{/isEnum}}{{/isString}}; + {{/isLong}} + {{/isDouble}} + {{/isFloat}} {{/isBoolean}} {{/isInteger}} keyPairQuery_{{paramName}} = keyValuePair_create(keyQuery_{{{paramName}}}, {{#isEnum}}strdup({{{operationId}}}_{{enumName}}_ToString( - {{/isEnum}}{{^isString}}{{^isInteger}}{{^isBoolean}}&{{/isBoolean}}{{/isInteger}}{{/isString}}valueQuery_{{{paramName}}}{{#isEnum}})){{/isEnum}}); + {{/isEnum}}{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}{{^isLong}}{{^isBoolean}}&{{/isBoolean}}{{/isLong}}{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}valueQuery_{{{paramName}}}{{#isEnum}})){{/isEnum}}); list_addElement(localVarQueryParameters,keyPairQuery_{{paramName}}); {{/isArray}} } diff --git a/samples/client/others/c/bearerAuth/api/DefaultAPI.c b/samples/client/others/c/bearerAuth/api/DefaultAPI.c index b3e5c7709bf3..b22c89917cd0 100644 --- a/samples/client/others/c/bearerAuth/api/DefaultAPI.c +++ b/samples/client/others/c/bearerAuth/api/DefaultAPI.c @@ -1,10 +1,13 @@ #include #include #include + #include "DefaultAPI.h" #define MAX_NUMBER_LENGTH 16 #define MAX_BUFFER_LENGTH 4096 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 // Returns private information. diff --git a/samples/client/petstore/c-useJsonUnformatted/README.md b/samples/client/petstore/c-useJsonUnformatted/README.md index d49d6ebda9b9..9aa17dad78e6 100644 --- a/samples/client/petstore/c-useJsonUnformatted/README.md +++ b/samples/client/petstore/c-useJsonUnformatted/README.md @@ -92,6 +92,7 @@ Category | Method | HTTP request | Description *UserAPI* | [**UserAPI_getUserByName**](docs/UserAPI.md#UserAPI_getUserByName) | **GET** /user/{username} | Get user by user name *UserAPI* | [**UserAPI_loginUser**](docs/UserAPI.md#UserAPI_loginUser) | **GET** /user/login | Logs user into the system *UserAPI* | [**UserAPI_logoutUser**](docs/UserAPI.md#UserAPI_logoutUser) | **GET** /user/logout | Logs out current logged in user session +*UserAPI* | [**UserAPI_testInt32Int64FloatDouble**](docs/UserAPI.md#UserAPI_testInt32Int64FloatDouble) | **GET** /user/test_int32_int64_float_double | test int32, int64 float and double query parameters in API *UserAPI* | [**UserAPI_testIntAndBool**](docs/UserAPI.md#UserAPI_testIntAndBool) | **GET** /user/testIntAndBool | test integer and boolean query parameters in API *UserAPI* | [**UserAPI_updateUser**](docs/UserAPI.md#UserAPI_updateUser) | **PUT** /user/{username} | Updated user diff --git a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c index 5002790c018f..0cc0fc690c7c 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c +++ b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c @@ -1,10 +1,13 @@ #include #include #include + #include "PetAPI.h" #define MAX_NUMBER_LENGTH 16 #define MAX_BUFFER_LENGTH 4096 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 // Functions for enum STATUS for PetAPI_findPetsByStatus diff --git a/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c b/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c index 426f3b0d73b1..1f72056761e3 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c +++ b/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c @@ -1,10 +1,13 @@ #include #include #include + #include "StoreAPI.h" #define MAX_NUMBER_LENGTH 16 #define MAX_BUFFER_LENGTH 4096 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 // Functions for enum RATING for StoreAPI_sendRating diff --git a/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c b/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c index 3f20e0114cff..89c00dc100f3 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c +++ b/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c @@ -1,10 +1,13 @@ #include #include #include + #include "UserAPI.h" #define MAX_NUMBER_LENGTH 16 #define MAX_BUFFER_LENGTH 4096 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 // Create user @@ -594,6 +597,110 @@ UserAPI_logoutUser(apiClient_t *apiClient) + free(localVarPath); + +} + +// test int32, int64 float and double query parameters in API +// +// This can test int32, int64 float and double query parameters in API. +// +void +UserAPI_testInt32Int64FloatDouble(apiClient_t *apiClient, float floatnum, double doublenum, int *int32num, long int64num) +{ + list_t *localVarQueryParameters = list_createList(); + list_t *localVarHeaderParameters = NULL; + list_t *localVarFormParameters = NULL; + list_t *localVarHeaderType = NULL; + list_t *localVarContentType = NULL; + char *localVarBodyParameters = NULL; + size_t localVarBodyLength = 0; + + // clear the error code from the previous api call + apiClient->response_code = 0; + + // create the path + char *localVarPath = strdup("/user/test_int32_int64_float_double"); + + + + + + // query parameters + char *keyQuery_floatnum = NULL; + char * valueQuery_floatnum ; + keyValuePair_t *keyPairQuery_floatnum = 0; + { + keyQuery_floatnum = strdup("floatnum"); + valueQuery_floatnum = calloc(1,MAX_NUMBER_LENGTH_FLOAT); + snprintf(valueQuery_floatnum, MAX_NUMBER_LENGTH_FLOAT, "%f", floatnum); + keyPairQuery_floatnum = keyValuePair_create(keyQuery_floatnum, valueQuery_floatnum); + list_addElement(localVarQueryParameters,keyPairQuery_floatnum); + } + + // query parameters + char *keyQuery_doublenum = NULL; + char * valueQuery_doublenum ; + keyValuePair_t *keyPairQuery_doublenum = 0; + { + keyQuery_doublenum = strdup("doublenum"); + valueQuery_doublenum = calloc(1,MAX_NUMBER_LENGTH_FLOAT); + snprintf(valueQuery_doublenum, MAX_NUMBER_LENGTH_FLOAT, "%f", doublenum); + keyPairQuery_doublenum = keyValuePair_create(keyQuery_doublenum, valueQuery_doublenum); + list_addElement(localVarQueryParameters,keyPairQuery_doublenum); + } + + // query parameters + char *keyQuery_int32num = NULL; + char * valueQuery_int32num = NULL; + keyValuePair_t *keyPairQuery_int32num = 0; + if (int32num) + { + keyQuery_int32num = strdup("int32num"); + valueQuery_int32num = calloc(1,MAX_NUMBER_LENGTH); + snprintf(valueQuery_int32num, MAX_NUMBER_LENGTH, "%d", *int32num); + keyPairQuery_int32num = keyValuePair_create(keyQuery_int32num, valueQuery_int32num); + list_addElement(localVarQueryParameters,keyPairQuery_int32num); + } + + // query parameters + char *keyQuery_int64num = NULL; + char * valueQuery_int64num ; + keyValuePair_t *keyPairQuery_int64num = 0; + { + keyQuery_int64num = strdup("int64num"); + valueQuery_int64num = calloc(1,MAX_NUMBER_LENGTH_LONG); + snprintf(valueQuery_int64num, MAX_NUMBER_LENGTH_LONG, "%d", int64num); + keyPairQuery_int64num = keyValuePair_create(keyQuery_int64num, valueQuery_int64num); + list_addElement(localVarQueryParameters,keyPairQuery_int64num); + } + apiClient_invoke(apiClient, + localVarPath, + localVarQueryParameters, + localVarHeaderParameters, + localVarFormParameters, + localVarHeaderType, + localVarContentType, + localVarBodyParameters, + localVarBodyLength, + "GET"); + + // uncomment below to debug the error response + //if (apiClient->response_code == 200) { + // printf("%s\n","successful operation"); + //} + //No return type +end: + if (apiClient->dataReceived) { + free(apiClient->dataReceived); + apiClient->dataReceived = NULL; + apiClient->dataReceivedLen = 0; + } + list_freeList(localVarQueryParameters); + + + + free(localVarPath); } diff --git a/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.h b/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.h index ed59519a639a..df82c7ad9ca2 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.h +++ b/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.h @@ -54,6 +54,14 @@ void UserAPI_logoutUser(apiClient_t *apiClient); +// test int32, int64 float and double query parameters in API +// +// This can test int32, int64 float and double query parameters in API. +// +void +UserAPI_testInt32Int64FloatDouble(apiClient_t *apiClient, float floatnum, double doublenum, int *int32num, long int64num); + + // test integer and boolean query parameters in API // // This can test integer and boolean query parameters in API. diff --git a/samples/client/petstore/c-useJsonUnformatted/docs/UserAPI.md b/samples/client/petstore/c-useJsonUnformatted/docs/UserAPI.md index de82b9f10ab6..d03b28954b61 100644 --- a/samples/client/petstore/c-useJsonUnformatted/docs/UserAPI.md +++ b/samples/client/petstore/c-useJsonUnformatted/docs/UserAPI.md @@ -11,6 +11,7 @@ Method | HTTP request | Description [**UserAPI_getUserByName**](UserAPI.md#UserAPI_getUserByName) | **GET** /user/{username} | Get user by user name [**UserAPI_loginUser**](UserAPI.md#UserAPI_loginUser) | **GET** /user/login | Logs user into the system [**UserAPI_logoutUser**](UserAPI.md#UserAPI_logoutUser) | **GET** /user/logout | Logs out current logged in user session +[**UserAPI_testInt32Int64FloatDouble**](UserAPI.md#UserAPI_testInt32Int64FloatDouble) | **GET** /user/test_int32_int64_float_double | test int32, int64 float and double query parameters in API [**UserAPI_testIntAndBool**](UserAPI.md#UserAPI_testIntAndBool) | **GET** /user/testIntAndBool | test integer and boolean query parameters in API [**UserAPI_updateUser**](UserAPI.md#UserAPI_updateUser) | **PUT** /user/{username} | Updated user @@ -218,6 +219,39 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +# **UserAPI_testInt32Int64FloatDouble** +```c +// test int32, int64 float and double query parameters in API +// +// This can test int32, int64 float and double query parameters in API. +// +void UserAPI_testInt32Int64FloatDouble(apiClient_t *apiClient, float floatnum, double doublenum, int *int32num, long int64num); +``` + +### Parameters +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**apiClient** | **apiClient_t \*** | context containing the client configuration | +**floatnum** | **float** | A float number | [optional] +**doublenum** | **double** | A double number | [optional] +**int32num** | **int \*** | An int32 number | [optional] +**int64num** | **long** | An int64 number | [optional] + +### Return type + +void + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **UserAPI_testIntAndBool** ```c // test integer and boolean query parameters in API diff --git a/samples/client/petstore/c/README.md b/samples/client/petstore/c/README.md index d49d6ebda9b9..9aa17dad78e6 100644 --- a/samples/client/petstore/c/README.md +++ b/samples/client/petstore/c/README.md @@ -92,6 +92,7 @@ Category | Method | HTTP request | Description *UserAPI* | [**UserAPI_getUserByName**](docs/UserAPI.md#UserAPI_getUserByName) | **GET** /user/{username} | Get user by user name *UserAPI* | [**UserAPI_loginUser**](docs/UserAPI.md#UserAPI_loginUser) | **GET** /user/login | Logs user into the system *UserAPI* | [**UserAPI_logoutUser**](docs/UserAPI.md#UserAPI_logoutUser) | **GET** /user/logout | Logs out current logged in user session +*UserAPI* | [**UserAPI_testInt32Int64FloatDouble**](docs/UserAPI.md#UserAPI_testInt32Int64FloatDouble) | **GET** /user/test_int32_int64_float_double | test int32, int64 float and double query parameters in API *UserAPI* | [**UserAPI_testIntAndBool**](docs/UserAPI.md#UserAPI_testIntAndBool) | **GET** /user/testIntAndBool | test integer and boolean query parameters in API *UserAPI* | [**UserAPI_updateUser**](docs/UserAPI.md#UserAPI_updateUser) | **PUT** /user/{username} | Updated user diff --git a/samples/client/petstore/c/api/PetAPI.c b/samples/client/petstore/c/api/PetAPI.c index 0037e2fdcf21..b0f3c1da5fad 100644 --- a/samples/client/petstore/c/api/PetAPI.c +++ b/samples/client/petstore/c/api/PetAPI.c @@ -1,10 +1,13 @@ #include #include #include + #include "PetAPI.h" #define MAX_NUMBER_LENGTH 16 #define MAX_BUFFER_LENGTH 4096 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 // Functions for enum STATUS for PetAPI_findPetsByStatus diff --git a/samples/client/petstore/c/api/StoreAPI.c b/samples/client/petstore/c/api/StoreAPI.c index 473de05e28c9..65b96b8c7d18 100644 --- a/samples/client/petstore/c/api/StoreAPI.c +++ b/samples/client/petstore/c/api/StoreAPI.c @@ -1,10 +1,13 @@ #include #include #include + #include "StoreAPI.h" #define MAX_NUMBER_LENGTH 16 #define MAX_BUFFER_LENGTH 4096 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 // Functions for enum RATING for StoreAPI_sendRating diff --git a/samples/client/petstore/c/api/UserAPI.c b/samples/client/petstore/c/api/UserAPI.c index 62b520c4034d..a21e8d245700 100644 --- a/samples/client/petstore/c/api/UserAPI.c +++ b/samples/client/petstore/c/api/UserAPI.c @@ -1,10 +1,13 @@ #include #include #include + #include "UserAPI.h" #define MAX_NUMBER_LENGTH 16 #define MAX_BUFFER_LENGTH 4096 +#define MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 // Create user @@ -594,6 +597,110 @@ UserAPI_logoutUser(apiClient_t *apiClient) + free(localVarPath); + +} + +// test int32, int64 float and double query parameters in API +// +// This can test int32, int64 float and double query parameters in API. +// +void +UserAPI_testInt32Int64FloatDouble(apiClient_t *apiClient, float floatnum, double doublenum, int *int32num, long int64num) +{ + list_t *localVarQueryParameters = list_createList(); + list_t *localVarHeaderParameters = NULL; + list_t *localVarFormParameters = NULL; + list_t *localVarHeaderType = NULL; + list_t *localVarContentType = NULL; + char *localVarBodyParameters = NULL; + size_t localVarBodyLength = 0; + + // clear the error code from the previous api call + apiClient->response_code = 0; + + // create the path + char *localVarPath = strdup("/user/test_int32_int64_float_double"); + + + + + + // query parameters + char *keyQuery_floatnum = NULL; + char * valueQuery_floatnum ; + keyValuePair_t *keyPairQuery_floatnum = 0; + { + keyQuery_floatnum = strdup("floatnum"); + valueQuery_floatnum = calloc(1,MAX_NUMBER_LENGTH_FLOAT); + snprintf(valueQuery_floatnum, MAX_NUMBER_LENGTH_FLOAT, "%f", floatnum); + keyPairQuery_floatnum = keyValuePair_create(keyQuery_floatnum, valueQuery_floatnum); + list_addElement(localVarQueryParameters,keyPairQuery_floatnum); + } + + // query parameters + char *keyQuery_doublenum = NULL; + char * valueQuery_doublenum ; + keyValuePair_t *keyPairQuery_doublenum = 0; + { + keyQuery_doublenum = strdup("doublenum"); + valueQuery_doublenum = calloc(1,MAX_NUMBER_LENGTH_FLOAT); + snprintf(valueQuery_doublenum, MAX_NUMBER_LENGTH_FLOAT, "%f", doublenum); + keyPairQuery_doublenum = keyValuePair_create(keyQuery_doublenum, valueQuery_doublenum); + list_addElement(localVarQueryParameters,keyPairQuery_doublenum); + } + + // query parameters + char *keyQuery_int32num = NULL; + char * valueQuery_int32num = NULL; + keyValuePair_t *keyPairQuery_int32num = 0; + if (int32num) + { + keyQuery_int32num = strdup("int32num"); + valueQuery_int32num = calloc(1,MAX_NUMBER_LENGTH); + snprintf(valueQuery_int32num, MAX_NUMBER_LENGTH, "%d", *int32num); + keyPairQuery_int32num = keyValuePair_create(keyQuery_int32num, valueQuery_int32num); + list_addElement(localVarQueryParameters,keyPairQuery_int32num); + } + + // query parameters + char *keyQuery_int64num = NULL; + char * valueQuery_int64num ; + keyValuePair_t *keyPairQuery_int64num = 0; + { + keyQuery_int64num = strdup("int64num"); + valueQuery_int64num = calloc(1,MAX_NUMBER_LENGTH_LONG); + snprintf(valueQuery_int64num, MAX_NUMBER_LENGTH_LONG, "%d", int64num); + keyPairQuery_int64num = keyValuePair_create(keyQuery_int64num, valueQuery_int64num); + list_addElement(localVarQueryParameters,keyPairQuery_int64num); + } + apiClient_invoke(apiClient, + localVarPath, + localVarQueryParameters, + localVarHeaderParameters, + localVarFormParameters, + localVarHeaderType, + localVarContentType, + localVarBodyParameters, + localVarBodyLength, + "GET"); + + // uncomment below to debug the error response + //if (apiClient->response_code == 200) { + // printf("%s\n","successful operation"); + //} + //No return type +end: + if (apiClient->dataReceived) { + free(apiClient->dataReceived); + apiClient->dataReceived = NULL; + apiClient->dataReceivedLen = 0; + } + list_freeList(localVarQueryParameters); + + + + free(localVarPath); } diff --git a/samples/client/petstore/c/api/UserAPI.h b/samples/client/petstore/c/api/UserAPI.h index ed59519a639a..df82c7ad9ca2 100644 --- a/samples/client/petstore/c/api/UserAPI.h +++ b/samples/client/petstore/c/api/UserAPI.h @@ -54,6 +54,14 @@ void UserAPI_logoutUser(apiClient_t *apiClient); +// test int32, int64 float and double query parameters in API +// +// This can test int32, int64 float and double query parameters in API. +// +void +UserAPI_testInt32Int64FloatDouble(apiClient_t *apiClient, float floatnum, double doublenum, int *int32num, long int64num); + + // test integer and boolean query parameters in API // // This can test integer and boolean query parameters in API. diff --git a/samples/client/petstore/c/docs/UserAPI.md b/samples/client/petstore/c/docs/UserAPI.md index de82b9f10ab6..d03b28954b61 100644 --- a/samples/client/petstore/c/docs/UserAPI.md +++ b/samples/client/petstore/c/docs/UserAPI.md @@ -11,6 +11,7 @@ Method | HTTP request | Description [**UserAPI_getUserByName**](UserAPI.md#UserAPI_getUserByName) | **GET** /user/{username} | Get user by user name [**UserAPI_loginUser**](UserAPI.md#UserAPI_loginUser) | **GET** /user/login | Logs user into the system [**UserAPI_logoutUser**](UserAPI.md#UserAPI_logoutUser) | **GET** /user/logout | Logs out current logged in user session +[**UserAPI_testInt32Int64FloatDouble**](UserAPI.md#UserAPI_testInt32Int64FloatDouble) | **GET** /user/test_int32_int64_float_double | test int32, int64 float and double query parameters in API [**UserAPI_testIntAndBool**](UserAPI.md#UserAPI_testIntAndBool) | **GET** /user/testIntAndBool | test integer and boolean query parameters in API [**UserAPI_updateUser**](UserAPI.md#UserAPI_updateUser) | **PUT** /user/{username} | Updated user @@ -218,6 +219,39 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +# **UserAPI_testInt32Int64FloatDouble** +```c +// test int32, int64 float and double query parameters in API +// +// This can test int32, int64 float and double query parameters in API. +// +void UserAPI_testInt32Int64FloatDouble(apiClient_t *apiClient, float floatnum, double doublenum, int *int32num, long int64num); +``` + +### Parameters +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**apiClient** | **apiClient_t \*** | context containing the client configuration | +**floatnum** | **float** | A float number | [optional] +**doublenum** | **double** | A double number | [optional] +**int32num** | **int \*** | An int32 number | [optional] +**int64num** | **long** | An int64 number | [optional] + +### Return type + +void + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **UserAPI_testIntAndBool** ```c // test integer and boolean query parameters in API From 369a39abb0eadf8cfc2c0a0659077514f2f6a5ff Mon Sep 17 00:00:00 2001 From: Amaury Graillat Date: Tue, 29 Apr 2025 09:55:32 +0200 Subject: [PATCH 6/6] [C-Curl] Client generator does not handle float properly (#21092) - Add missing yaml example file --- .../src/test/resources/2_0/c/petstore.yaml | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/modules/openapi-generator/src/test/resources/2_0/c/petstore.yaml b/modules/openapi-generator/src/test/resources/2_0/c/petstore.yaml index d8d01947081c..a34f00cab472 100644 --- a/modules/openapi-generator/src/test/resources/2_0/c/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/2_0/c/petstore.yaml @@ -727,6 +727,40 @@ paths: responses: '200': description: successful operation + '/user/test_int32_int64_float_double': + get: + tags: + - user + summary: test int32, int64 float and double query parameters in API + description: This can test int32, int64 float and double query parameters in API. + operationId: test_int32_int64_float_double + produces: + - application/xml + - application/json + parameters: + - name: floatnum + in: query + description: A float number + type: number + format: float + - name: doublenum + in: query + description: A double number + type: number + format: double + - name: int32num + in: query + description: An int32 number + type: integer + format: int32 + - name: int64num + in: query + description: An int64 number + type: integer + format: int64 + responses: + '200': + description: successful operation securityDefinitions: petstore_auth: type: oauth2