From 5733ca4c30ed63c61344a1df0e6738ed40f90a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20A=2E=20Fern=C3=A1ndez?= Date: Thu, 12 Dec 2024 18:17:44 -0500 Subject: [PATCH 1/6] [C] Fail build on implicit function declarations --- .../src/main/resources/C-libcurl/CMakeLists.txt.mustache | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache index ae635d276b75..01703a0bf413 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache @@ -6,6 +6,7 @@ cmake_policy(SET CMP0063 NEW) set(CMAKE_C_VISIBILITY_PRESET default) set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +set(CMAKE_C_FLAGS "-Werror=implicit-function-declaration") option(BUILD_SHARED_LIBS "Build using shared libraries" ON) @@ -14,7 +15,7 @@ find_package(OpenSSL) if (OPENSSL_FOUND) message (STATUS "OPENSSL found") - set(CMAKE_C_FLAGS "-DOPENSSL") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DOPENSSL") if(CMAKE_VERSION VERSION_LESS 3.4) include_directories(${OPENSSL_INCLUDE_DIR}) include_directories(${OPENSSL_INCLUDE_DIRS}) From 53f0edc96ec9d895e0a3406fa45c13ee3334d30f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20A=2E=20Fern=C3=A1ndez?= Date: Mon, 16 Dec 2024 15:33:00 -0300 Subject: [PATCH 2/6] [C] Complete changes from patch 34c3f8c7aa84 --- .../src/main/resources/C-libcurl/model-body.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache index ebf15d178911..a835a9b37080 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache @@ -376,7 +376,7 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) { {{/isBoolean}} {{#isEnum}} {{#isString}} - if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{{name}}}{{classname}}_ToString({{{classname}}}->{{{name}}})) == NULL) + if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{classname}}_{{name}}_ToString({{{classname}}}->{{{name}}})) == NULL) { goto fail; //Enum } From 5f412c35c1118f0a7bb031bf1b43afcaa4bdb1dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20A=2E=20Fern=C3=A1ndez?= Date: Mon, 16 Dec 2024 14:02:37 -0500 Subject: [PATCH 3/6] Update samples --- samples/client/others/c/bearerAuth/CMakeLists.txt | 3 ++- samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt | 3 ++- samples/client/petstore/c-useJsonUnformatted/model/order.c | 2 +- samples/client/petstore/c-useJsonUnformatted/model/pet.c | 2 +- samples/client/petstore/c/model/order.c | 2 +- samples/client/petstore/c/model/pet.c | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/samples/client/others/c/bearerAuth/CMakeLists.txt b/samples/client/others/c/bearerAuth/CMakeLists.txt index 2bfcf58899c0..f7eddc4c612f 100644 --- a/samples/client/others/c/bearerAuth/CMakeLists.txt +++ b/samples/client/others/c/bearerAuth/CMakeLists.txt @@ -6,6 +6,7 @@ cmake_policy(SET CMP0063 NEW) set(CMAKE_C_VISIBILITY_PRESET default) set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +set(CMAKE_C_FLAGS "-Werror=implicit-function-declaration") option(BUILD_SHARED_LIBS "Build using shared libraries" ON) @@ -14,7 +15,7 @@ find_package(OpenSSL) if (OPENSSL_FOUND) message (STATUS "OPENSSL found") - set(CMAKE_C_FLAGS "-DOPENSSL") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DOPENSSL") if(CMAKE_VERSION VERSION_LESS 3.4) include_directories(${OPENSSL_INCLUDE_DIR}) include_directories(${OPENSSL_INCLUDE_DIRS}) diff --git a/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt b/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt index c97fd637cdb9..68895c666576 100644 --- a/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt +++ b/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt @@ -6,6 +6,7 @@ cmake_policy(SET CMP0063 NEW) set(CMAKE_C_VISIBILITY_PRESET default) set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +set(CMAKE_C_FLAGS "-Werror=implicit-function-declaration") option(BUILD_SHARED_LIBS "Build using shared libraries" ON) @@ -14,7 +15,7 @@ find_package(OpenSSL) if (OPENSSL_FOUND) message (STATUS "OPENSSL found") - set(CMAKE_C_FLAGS "-DOPENSSL") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DOPENSSL") if(CMAKE_VERSION VERSION_LESS 3.4) include_directories(${OPENSSL_INCLUDE_DIR}) include_directories(${OPENSSL_INCLUDE_DIRS}) diff --git a/samples/client/petstore/c-useJsonUnformatted/model/order.c b/samples/client/petstore/c-useJsonUnformatted/model/order.c index bbbc50e1a316..055dd08a3896 100644 --- a/samples/client/petstore/c-useJsonUnformatted/model/order.c +++ b/samples/client/petstore/c-useJsonUnformatted/model/order.c @@ -94,7 +94,7 @@ cJSON *order_convertToJSON(order_t *order) { // order->status if(order->status != openapi_petstore_order_STATUS_NULL) { - if(cJSON_AddStringToObject(item, "status", statusorder_ToString(order->status)) == NULL) + if(cJSON_AddStringToObject(item, "status", order_status_ToString(order->status)) == NULL) { goto fail; //Enum } diff --git a/samples/client/petstore/c-useJsonUnformatted/model/pet.c b/samples/client/petstore/c-useJsonUnformatted/model/pet.c index d95d672eda00..2472e769095d 100644 --- a/samples/client/petstore/c-useJsonUnformatted/model/pet.c +++ b/samples/client/petstore/c-useJsonUnformatted/model/pet.c @@ -148,7 +148,7 @@ cJSON *pet_convertToJSON(pet_t *pet) { // pet->status if(pet->status != openapi_petstore_pet_STATUS_NULL) { - if(cJSON_AddStringToObject(item, "status", statuspet_ToString(pet->status)) == NULL) + if(cJSON_AddStringToObject(item, "status", pet_status_ToString(pet->status)) == NULL) { goto fail; //Enum } diff --git a/samples/client/petstore/c/model/order.c b/samples/client/petstore/c/model/order.c index bbbc50e1a316..055dd08a3896 100644 --- a/samples/client/petstore/c/model/order.c +++ b/samples/client/petstore/c/model/order.c @@ -94,7 +94,7 @@ cJSON *order_convertToJSON(order_t *order) { // order->status if(order->status != openapi_petstore_order_STATUS_NULL) { - if(cJSON_AddStringToObject(item, "status", statusorder_ToString(order->status)) == NULL) + if(cJSON_AddStringToObject(item, "status", order_status_ToString(order->status)) == NULL) { goto fail; //Enum } diff --git a/samples/client/petstore/c/model/pet.c b/samples/client/petstore/c/model/pet.c index d95d672eda00..2472e769095d 100644 --- a/samples/client/petstore/c/model/pet.c +++ b/samples/client/petstore/c/model/pet.c @@ -148,7 +148,7 @@ cJSON *pet_convertToJSON(pet_t *pet) { // pet->status if(pet->status != openapi_petstore_pet_STATUS_NULL) { - if(cJSON_AddStringToObject(item, "status", statuspet_ToString(pet->status)) == NULL) + if(cJSON_AddStringToObject(item, "status", pet_status_ToString(pet->status)) == NULL) { goto fail; //Enum } From f309e448316623d67101a849a913f518cdee446a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20A=2E=20Fern=C3=A1ndez?= Date: Mon, 16 Dec 2024 19:34:39 -0300 Subject: [PATCH 4/6] [C] Fail build for global functions with no declaration --- .../src/main/resources/C-libcurl/CMakeLists.txt.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache index 01703a0bf413..dfbd9ee55986 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache @@ -6,7 +6,7 @@ cmake_policy(SET CMP0063 NEW) set(CMAKE_C_VISIBILITY_PRESET default) set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) -set(CMAKE_C_FLAGS "-Werror=implicit-function-declaration") +set(CMAKE_C_FLAGS "-Werror=implicit-function-declaration -Werror=missing-declarations") option(BUILD_SHARED_LIBS "Build using shared libraries" ON) From f4acbb250f389d0ccddeda29ba09e7db6c6387b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20A=2E=20Fern=C3=A1ndez?= Date: Mon, 16 Dec 2024 19:39:12 -0300 Subject: [PATCH 5/6] [C] Use "static" for apiClient.c internal functions --- .../main/resources/C-libcurl/apiClient.c.mustache | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache index 899cb22ef7aa..d032b5de1fa8 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache @@ -173,7 +173,7 @@ void sslConfig_free(sslConfig_t *sslConfig) { free(sslConfig); } -void replaceSpaceWithPlus(char *stringToProcess) { +static void replaceSpaceWithPlus(char *stringToProcess) { for(int i = 0; i < strlen(stringToProcess); i++) { if(stringToProcess[i] == ' ') { stringToProcess[i] = '+'; @@ -181,9 +181,9 @@ void replaceSpaceWithPlus(char *stringToProcess) { } } -char *assembleTargetUrl(const char *basePath, - const char *operationParameter, - list_t *queryParameters) { +static char *assembleTargetUrl(const char *basePath, + const char *operationParameter, + list_t *queryParameters) { int neededBufferSizeForQueryParameters = 0; listEntry_t *listEntry; @@ -234,7 +234,7 @@ char *assembleTargetUrl(const char *basePath, return targetUrl; } -char *assembleHeaderField(char *key, char *value) { +static char *assembleHeaderField(char *key, char *value) { char *header = malloc(strlen(key) + strlen(value) + 3); strcpy(header, key), @@ -244,13 +244,13 @@ char *assembleHeaderField(char *key, char *value) { return header; } -void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) { +static void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) { curl_easy_setopt(handle, CURLOPT_POSTFIELDS, bodyParameters); curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)bodyParametersLength); } -int lengthOfKeyPair(keyValuePair_t *keyPair) { +static int lengthOfKeyPair(keyValuePair_t *keyPair) { long length = 0; if((keyPair->key != NULL) && (keyPair->value != NULL) ) From 50af6974536a1138a559e5a0e35dfb9eaf3dc116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20A=2E=20Fern=C3=A1ndez?= Date: Mon, 16 Dec 2024 18:52:42 -0500 Subject: [PATCH 6/6] Update samples --- samples/client/others/c/bearerAuth/CMakeLists.txt | 2 +- samples/client/others/c/bearerAuth/src/apiClient.c | 14 +++++++------- .../petstore/c-useJsonUnformatted/CMakeLists.txt | 2 +- .../petstore/c-useJsonUnformatted/src/apiClient.c | 14 +++++++------- samples/client/petstore/c/src/apiClient.c | 14 +++++++------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/samples/client/others/c/bearerAuth/CMakeLists.txt b/samples/client/others/c/bearerAuth/CMakeLists.txt index f7eddc4c612f..2dc8b7b11ace 100644 --- a/samples/client/others/c/bearerAuth/CMakeLists.txt +++ b/samples/client/others/c/bearerAuth/CMakeLists.txt @@ -6,7 +6,7 @@ cmake_policy(SET CMP0063 NEW) set(CMAKE_C_VISIBILITY_PRESET default) set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) -set(CMAKE_C_FLAGS "-Werror=implicit-function-declaration") +set(CMAKE_C_FLAGS "-Werror=implicit-function-declaration -Werror=missing-declarations") option(BUILD_SHARED_LIBS "Build using shared libraries" ON) diff --git a/samples/client/others/c/bearerAuth/src/apiClient.c b/samples/client/others/c/bearerAuth/src/apiClient.c index 6614016d27ae..b9f52e2e1b7f 100644 --- a/samples/client/others/c/bearerAuth/src/apiClient.c +++ b/samples/client/others/c/bearerAuth/src/apiClient.c @@ -89,7 +89,7 @@ void sslConfig_free(sslConfig_t *sslConfig) { free(sslConfig); } -void replaceSpaceWithPlus(char *stringToProcess) { +static void replaceSpaceWithPlus(char *stringToProcess) { for(int i = 0; i < strlen(stringToProcess); i++) { if(stringToProcess[i] == ' ') { stringToProcess[i] = '+'; @@ -97,9 +97,9 @@ void replaceSpaceWithPlus(char *stringToProcess) { } } -char *assembleTargetUrl(const char *basePath, - const char *operationParameter, - list_t *queryParameters) { +static char *assembleTargetUrl(const char *basePath, + const char *operationParameter, + list_t *queryParameters) { int neededBufferSizeForQueryParameters = 0; listEntry_t *listEntry; @@ -150,7 +150,7 @@ char *assembleTargetUrl(const char *basePath, return targetUrl; } -char *assembleHeaderField(char *key, char *value) { +static char *assembleHeaderField(char *key, char *value) { char *header = malloc(strlen(key) + strlen(value) + 3); strcpy(header, key), @@ -160,13 +160,13 @@ char *assembleHeaderField(char *key, char *value) { return header; } -void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) { +static void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) { curl_easy_setopt(handle, CURLOPT_POSTFIELDS, bodyParameters); curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)bodyParametersLength); } -int lengthOfKeyPair(keyValuePair_t *keyPair) { +static int lengthOfKeyPair(keyValuePair_t *keyPair) { long length = 0; if((keyPair->key != NULL) && (keyPair->value != NULL) ) diff --git a/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt b/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt index 68895c666576..c5a0b31ca181 100644 --- a/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt +++ b/samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt @@ -6,7 +6,7 @@ cmake_policy(SET CMP0063 NEW) set(CMAKE_C_VISIBILITY_PRESET default) set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) -set(CMAKE_C_FLAGS "-Werror=implicit-function-declaration") +set(CMAKE_C_FLAGS "-Werror=implicit-function-declaration -Werror=missing-declarations") option(BUILD_SHARED_LIBS "Build using shared libraries" ON) diff --git a/samples/client/petstore/c-useJsonUnformatted/src/apiClient.c b/samples/client/petstore/c-useJsonUnformatted/src/apiClient.c index 302cb8bff342..ad06a341a4bb 100644 --- a/samples/client/petstore/c-useJsonUnformatted/src/apiClient.c +++ b/samples/client/petstore/c-useJsonUnformatted/src/apiClient.c @@ -116,7 +116,7 @@ void sslConfig_free(sslConfig_t *sslConfig) { free(sslConfig); } -void replaceSpaceWithPlus(char *stringToProcess) { +static void replaceSpaceWithPlus(char *stringToProcess) { for(int i = 0; i < strlen(stringToProcess); i++) { if(stringToProcess[i] == ' ') { stringToProcess[i] = '+'; @@ -124,9 +124,9 @@ void replaceSpaceWithPlus(char *stringToProcess) { } } -char *assembleTargetUrl(const char *basePath, - const char *operationParameter, - list_t *queryParameters) { +static char *assembleTargetUrl(const char *basePath, + const char *operationParameter, + list_t *queryParameters) { int neededBufferSizeForQueryParameters = 0; listEntry_t *listEntry; @@ -177,7 +177,7 @@ char *assembleTargetUrl(const char *basePath, return targetUrl; } -char *assembleHeaderField(char *key, char *value) { +static char *assembleHeaderField(char *key, char *value) { char *header = malloc(strlen(key) + strlen(value) + 3); strcpy(header, key), @@ -187,13 +187,13 @@ char *assembleHeaderField(char *key, char *value) { return header; } -void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) { +static void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) { curl_easy_setopt(handle, CURLOPT_POSTFIELDS, bodyParameters); curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)bodyParametersLength); } -int lengthOfKeyPair(keyValuePair_t *keyPair) { +static int lengthOfKeyPair(keyValuePair_t *keyPair) { long length = 0; if((keyPair->key != NULL) && (keyPair->value != NULL) ) diff --git a/samples/client/petstore/c/src/apiClient.c b/samples/client/petstore/c/src/apiClient.c index 302cb8bff342..ad06a341a4bb 100644 --- a/samples/client/petstore/c/src/apiClient.c +++ b/samples/client/petstore/c/src/apiClient.c @@ -116,7 +116,7 @@ void sslConfig_free(sslConfig_t *sslConfig) { free(sslConfig); } -void replaceSpaceWithPlus(char *stringToProcess) { +static void replaceSpaceWithPlus(char *stringToProcess) { for(int i = 0; i < strlen(stringToProcess); i++) { if(stringToProcess[i] == ' ') { stringToProcess[i] = '+'; @@ -124,9 +124,9 @@ void replaceSpaceWithPlus(char *stringToProcess) { } } -char *assembleTargetUrl(const char *basePath, - const char *operationParameter, - list_t *queryParameters) { +static char *assembleTargetUrl(const char *basePath, + const char *operationParameter, + list_t *queryParameters) { int neededBufferSizeForQueryParameters = 0; listEntry_t *listEntry; @@ -177,7 +177,7 @@ char *assembleTargetUrl(const char *basePath, return targetUrl; } -char *assembleHeaderField(char *key, char *value) { +static char *assembleHeaderField(char *key, char *value) { char *header = malloc(strlen(key) + strlen(value) + 3); strcpy(header, key), @@ -187,13 +187,13 @@ char *assembleHeaderField(char *key, char *value) { return header; } -void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) { +static void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) { curl_easy_setopt(handle, CURLOPT_POSTFIELDS, bodyParameters); curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)bodyParametersLength); } -int lengthOfKeyPair(keyValuePair_t *keyPair) { +static int lengthOfKeyPair(keyValuePair_t *keyPair) { long length = 0; if((keyPair->key != NULL) && (keyPair->value != NULL) )