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 0c3df633df32..69b2e74c3310 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 @@ -13,6 +13,7 @@ apiClient_t *apiClient_create() { curl_global_init(CURL_GLOBAL_ALL); apiClient_t *apiClient = malloc(sizeof(apiClient_t)); apiClient->basePath = strdup("{{{basePath}}}"); + apiClient->caPath = NULL; apiClient->dataReceived = NULL; apiClient->response_code = 0; {{#hasAuthMethods}} @@ -34,6 +35,7 @@ apiClient_t *apiClient_create() { } apiClient_t *apiClient_create_with_base_path(const char *basePath +, const char *caPath {{#hasAuthMethods}} {{#authMethods}} {{#isApiKey}} @@ -49,6 +51,13 @@ apiClient_t *apiClient_create_with_base_path(const char *basePath }else{ apiClient->basePath = strdup("{{{basePath}}}"); } + + if(caPath){ + apiClient->caPath = strdup(caPath); + }else{ + apiClient->caPath = NULL; + } + apiClient->dataReceived = NULL; apiClient->response_code = 0; {{#hasAuthMethods}} @@ -83,6 +92,9 @@ void apiClient_free(apiClient_t *apiClient) { if(apiClient->basePath) { free(apiClient->basePath); } + if(apiClient->caPath) { + free(apiClient->caPath); + } {{#hasAuthMethods}} {{#authMethods}} {{#isBasic}} @@ -375,6 +387,17 @@ void apiClient_invoke(apiClient_t *apiClient, free(headerValueToWrite); } } + + if( strstr(apiClient->basePath, "https") != NULL ){ + if (apiClient->caPath) { + curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, true); + curl_easy_setopt(handle, CURLOPT_CAINFO, apiClient->caPath); + } else { + curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, false); + curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, false); + } + } + {{#hasAuthMethods}} {{#authMethods}} {{#isApiKey}} diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.h.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.h.mustache index 5abae164e683..08458228e9dc 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.h.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.h.mustache @@ -11,6 +11,7 @@ typedef struct apiClient_t { char *basePath; + char *caPath; void *dataReceived; long response_code; {{#hasAuthMethods}} @@ -38,6 +39,7 @@ typedef struct binary_t apiClient_t* apiClient_create(); apiClient_t* apiClient_create_with_base_path(const char *basePath +, const char *caPath {{#hasAuthMethods}} {{#authMethods}} {{#isApiKey}}