forked from loafle/openapi-generator-original
Fix a few issues with the C generator (part 6) (#20332)
* [C] Fail build on implicit function declarations * [C] Complete changes from patch 34c3f8c7aa84 * Update samples * [C] Fail build for global functions with no declaration * [C] Use "static" for apiClient.c internal functions * Update samples
This commit is contained in:
parent
8790f7c8b1
commit
77e9c1f03a
@ -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 -Werror=missing-declarations")
|
||||
|
||||
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})
|
||||
|
@ -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) )
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 -Werror=missing-declarations")
|
||||
|
||||
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})
|
||||
|
@ -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) )
|
||||
|
@ -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 -Werror=missing-declarations")
|
||||
|
||||
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})
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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) )
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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) )
|
||||
|
Loading…
x
Reference in New Issue
Block a user