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..a10a7f02c685 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 TYPICAL_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}}); @@ -241,19 +250,47 @@ end: keyQuery_{{{paramName}}} = strdup("{{{baseName}}}"); {{#isInteger}} valueQuery_{{{paramName}}} = calloc(1,MAX_NUMBER_LENGTH); - snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH, "%d", *{{{paramName}}}); + int s = snprintf(valueQuery_{{{paramName}}}, MAX_NUMBER_LENGTH, "%d", *{{{paramName}}}); {{/isInteger}} + {{#isFloat}} + valueQuery_{{{paramName}}} = calloc(1,TYPICAL_MAX_NUMBER_LENGTH_FLOAT); + int s = snprintf(valueQuery_{{{paramName}}}, TYPICAL_MAX_NUMBER_LENGTH_FLOAT, "%.7e", {{{paramName}}}); + if (s >= 0 && s >= TYPICAL_MAX_NUMBER_LENGTH_FLOAT) + { + valueQuery_{{{paramName}}} = realloc(valueQuery_{{{paramName}}}, s+1); + snprintf(valueQuery_{{{paramName}}}, s+1, "%f", {{{paramName}}}); + } + {{/isFloat}} + {{#isDouble}} + valueQuery_{{{paramName}}} = calloc(1,TYPICAL_MAX_NUMBER_LENGTH_FLOAT); + int s = snprintf(valueQuery_{{{paramName}}}, TYPICAL_MAX_NUMBER_LENGTH_FLOAT, "%.16e", {{{paramName}}}); + if (s >= 0 && s >= TYPICAL_MAX_NUMBER_LENGTH_FLOAT) + { + valueQuery_{{{paramName}}} = realloc(valueQuery_{{{paramName}}}, s+1); + snprintf(valueQuery_{{{paramName}}}, s+1, "%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/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 diff --git a/samples/client/others/c/bearerAuth/api/DefaultAPI.c b/samples/client/others/c/bearerAuth/api/DefaultAPI.c index b3e5c7709bf3..26d5f7bd516f 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 TYPICAL_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..437bf8d100ad 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 TYPICAL_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..46f1224fc1df 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 TYPICAL_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..2bdfb4b64440 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 TYPICAL_MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 // Create user @@ -594,6 +597,120 @@ 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,TYPICAL_MAX_NUMBER_LENGTH_FLOAT); + int s = snprintf(valueQuery_floatnum, TYPICAL_MAX_NUMBER_LENGTH_FLOAT, "%.7e", floatnum); + if (s >= 0 && s >= TYPICAL_MAX_NUMBER_LENGTH_FLOAT) + { + valueQuery_floatnum = realloc(valueQuery_floatnum, s+1); + snprintf(valueQuery_floatnum, s+1, "%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,TYPICAL_MAX_NUMBER_LENGTH_FLOAT); + int s = snprintf(valueQuery_doublenum, TYPICAL_MAX_NUMBER_LENGTH_FLOAT, "%.16e", doublenum); + if (s >= 0 && s >= TYPICAL_MAX_NUMBER_LENGTH_FLOAT) + { + valueQuery_doublenum = realloc(valueQuery_doublenum, s+1); + snprintf(valueQuery_doublenum, s+1, "%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); + int s = 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); } @@ -644,7 +761,7 @@ UserAPI_testIntAndBool(apiClient_t *apiClient, int *keep, int *keepDay) { keyQuery_keepDay = strdup("keepDay"); valueQuery_keepDay = calloc(1,MAX_NUMBER_LENGTH); - snprintf(valueQuery_keepDay, MAX_NUMBER_LENGTH, "%d", *keepDay); + int s = snprintf(valueQuery_keepDay, MAX_NUMBER_LENGTH, "%d", *keepDay); keyPairQuery_keepDay = keyValuePair_create(keyQuery_keepDay, valueQuery_keepDay); list_addElement(localVarQueryParameters,keyPairQuery_keepDay); } 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..a39b33e3eb3f 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 TYPICAL_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..28212b98d8b3 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 TYPICAL_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..375de6408960 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 TYPICAL_MAX_NUMBER_LENGTH_FLOAT 32 +#define MAX_NUMBER_LENGTH_LONG 21 // Create user @@ -594,6 +597,120 @@ 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,TYPICAL_MAX_NUMBER_LENGTH_FLOAT); + int s = snprintf(valueQuery_floatnum, TYPICAL_MAX_NUMBER_LENGTH_FLOAT, "%.7e", floatnum); + if (s >= 0 && s >= TYPICAL_MAX_NUMBER_LENGTH_FLOAT) + { + valueQuery_floatnum = realloc(valueQuery_floatnum, s+1); + snprintf(valueQuery_floatnum, s+1, "%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,TYPICAL_MAX_NUMBER_LENGTH_FLOAT); + int s = snprintf(valueQuery_doublenum, TYPICAL_MAX_NUMBER_LENGTH_FLOAT, "%.16e", doublenum); + if (s >= 0 && s >= TYPICAL_MAX_NUMBER_LENGTH_FLOAT) + { + valueQuery_doublenum = realloc(valueQuery_doublenum, s+1); + snprintf(valueQuery_doublenum, s+1, "%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); + int s = 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); } @@ -644,7 +761,7 @@ UserAPI_testIntAndBool(apiClient_t *apiClient, int *keep, int *keepDay) { keyQuery_keepDay = strdup("keepDay"); valueQuery_keepDay = calloc(1,MAX_NUMBER_LENGTH); - snprintf(valueQuery_keepDay, MAX_NUMBER_LENGTH, "%d", *keepDay); + int s = snprintf(valueQuery_keepDay, MAX_NUMBER_LENGTH, "%d", *keepDay); keyPairQuery_keepDay = keyValuePair_create(keyQuery_keepDay, valueQuery_keepDay); list_addElement(localVarQueryParameters,keyPairQuery_keepDay); } 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