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 a88c20fb4d90..607eb44bcad1 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 @@ -188,15 +188,6 @@ end: localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, {{^isEnum}}{{paramName}}{{/isEnum}}{{#isEnum}}{{{operationId}}}_{{enumName}}_ToString({{paramName}}){{/isEnum}}); {{/isString}} - {{#isUuid}} - if({{paramName}} == NULL) { - goto end; - } - char* localVarToReplace_{{paramName}} = malloc(sizeOfPathParams_{{paramName}}); - sprintf(localVarToReplace_{{paramName}}, "{%s}", "{{baseName}}"); - - localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, {{paramName}}); - {{/isUuid}} {{/pathParams}} 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 a34f00cab472..b7ea03b1c779 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 @@ -253,6 +253,34 @@ paths: - petstore_auth: - 'write:pets' - 'read:pets' + '/pet/byUuid/{uuid}': + get: + tags: + - pet + summary: Find pet by UUID + description: Returns a single pet identified by UUID + operationId: getPetByUuid + produces: + - application/xml + - application/json + parameters: + - name: uuid + in: path + description: UUID of pet to return + required: true + type: string + format: uuid + responses: + '200': + description: successful operation + schema: + $ref: '#/definitions/Pet' + '400': + description: Invalid UUID supplied + '404': + description: Pet not found + security: + - api_key: [] /pet/picture: get: tags: diff --git a/samples/client/petstore/c-useJsonUnformatted/README.md b/samples/client/petstore/c-useJsonUnformatted/README.md index 051210cfee7f..5cfc40800598 100644 --- a/samples/client/petstore/c-useJsonUnformatted/README.md +++ b/samples/client/petstore/c-useJsonUnformatted/README.md @@ -71,6 +71,7 @@ Category | Method | HTTP request | Description *PetAPI* | [**PetAPI_findPetsByTags**](docs/PetAPI.md#PetAPI_findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags *PetAPI* | [**PetAPI_getDaysWithoutIncident**](docs/PetAPI.md#PetAPI_getDaysWithoutIncident) | **GET** /store/daysWithoutIncident | Number of days since the last time a pet maimed someone at the store *PetAPI* | [**PetAPI_getPetById**](docs/PetAPI.md#PetAPI_getPetById) | **GET** /pet/{petId} | Find pet by ID +*PetAPI* | [**PetAPI_getPetByUuid**](docs/PetAPI.md#PetAPI_getPetByUuid) | **GET** /pet/byUuid/{uuid} | Find pet by UUID *PetAPI* | [**PetAPI_getPicture**](docs/PetAPI.md#PetAPI_getPicture) | **GET** /pet/picture | Get a random picture of someone else's pet *PetAPI* | [**PetAPI_isPetAvailable**](docs/PetAPI.md#PetAPI_isPetAvailable) | **POST** /pet/{petId}/isAvailable | Is this pet still available? *PetAPI* | [**PetAPI_sharePicture**](docs/PetAPI.md#PetAPI_sharePicture) | **POST** /pet/picture | Send a picture of your happy pet diff --git a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c index 10c2d9434ef1..6e86b656c65e 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c +++ b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c @@ -548,6 +548,98 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId) } +// Find pet by UUID +// +// Returns a single pet identified by UUID +// +pet_t* +PetAPI_getPetByUuid(apiClient_t *apiClient, char *uuid) +{ + list_t *localVarQueryParameters = NULL; + list_t *localVarHeaderParameters = NULL; + list_t *localVarFormParameters = NULL; + list_t *localVarHeaderType = list_createList(); + 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("/pet/byUuid/{uuid}"); + + if(!uuid) + goto end; + + + // Path Params + long sizeOfPathParams_uuid = strlen(uuid)+3 + sizeof("{ uuid }") - 1; + if(uuid == NULL) { + goto end; + } + char* localVarToReplace_uuid = malloc(sizeOfPathParams_uuid); + sprintf(localVarToReplace_uuid, "{%s}", "uuid"); + + localVarPath = strReplace(localVarPath, localVarToReplace_uuid, uuid); + + + list_addElement(localVarHeaderType,"application/xml"); //produces + list_addElement(localVarHeaderType,"application/json"); //produces + 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"); + //} + // uncomment below to debug the error response + //if (apiClient->response_code == 400) { + // printf("%s\n","Invalid UUID supplied"); + //} + // uncomment below to debug the error response + //if (apiClient->response_code == 404) { + // printf("%s\n","Pet not found"); + //} + //nonprimitive not container + pet_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = pet_parseFromJSON(PetAPIlocalVarJSON); + cJSON_Delete(PetAPIlocalVarJSON); + if(elementToReturn == NULL) { + // return 0; + } + } + + //return type + if (apiClient->dataReceived) { + free(apiClient->dataReceived); + apiClient->dataReceived = NULL; + apiClient->dataReceivedLen = 0; + } + + + + list_freeList(localVarHeaderType); + + free(localVarPath); + free(localVarToReplace_uuid); + return elementToReturn; +end: + free(localVarPath); + return NULL; + +} + // Get a random picture of someone else's pet // binary_t* diff --git a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h index 3dc0c570c29e..18f923caaf41 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h +++ b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h @@ -56,6 +56,14 @@ pet_t* PetAPI_getPetById(apiClient_t *apiClient, long petId); +// Find pet by UUID +// +// Returns a single pet identified by UUID +// +pet_t* +PetAPI_getPetByUuid(apiClient_t *apiClient, char *uuid); + + // Get a random picture of someone else's pet // binary_t* diff --git a/samples/client/petstore/c-useJsonUnformatted/docs/PetAPI.md b/samples/client/petstore/c-useJsonUnformatted/docs/PetAPI.md index 9a9532d952d5..8d376abd3660 100644 --- a/samples/client/petstore/c-useJsonUnformatted/docs/PetAPI.md +++ b/samples/client/petstore/c-useJsonUnformatted/docs/PetAPI.md @@ -10,6 +10,7 @@ Method | HTTP request | Description [**PetAPI_findPetsByTags**](PetAPI.md#PetAPI_findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags [**PetAPI_getDaysWithoutIncident**](PetAPI.md#PetAPI_getDaysWithoutIncident) | **GET** /store/daysWithoutIncident | Number of days since the last time a pet maimed someone at the store [**PetAPI_getPetById**](PetAPI.md#PetAPI_getPetById) | **GET** /pet/{petId} | Find pet by ID +[**PetAPI_getPetByUuid**](PetAPI.md#PetAPI_getPetByUuid) | **GET** /pet/byUuid/{uuid} | Find pet by UUID [**PetAPI_getPicture**](PetAPI.md#PetAPI_getPicture) | **GET** /pet/picture | Get a random picture of someone else's pet [**PetAPI_isPetAvailable**](PetAPI.md#PetAPI_isPetAvailable) | **POST** /pet/{petId}/isAvailable | Is this pet still available? [**PetAPI_sharePicture**](PetAPI.md#PetAPI_sharePicture) | **POST** /pet/picture | Send a picture of your happy pet @@ -187,6 +188,37 @@ Name | Type | Description | Notes [pet_t](pet.md) * +### Authorization + +[api_key](../README.md#api_key) + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/xml, application/json + +[[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) + +# **PetAPI_getPetByUuid** +```c +// Find pet by UUID +// +// Returns a single pet identified by UUID +// +pet_t* PetAPI_getPetByUuid(apiClient_t *apiClient, char *uuid); +``` + +### Parameters +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**apiClient** | **apiClient_t \*** | context containing the client configuration | +**uuid** | **char \*** | UUID of pet to return | + +### Return type + +[pet_t](pet.md) * + + ### Authorization [api_key](../README.md#api_key) diff --git a/samples/client/petstore/c/README.md b/samples/client/petstore/c/README.md index 051210cfee7f..5cfc40800598 100644 --- a/samples/client/petstore/c/README.md +++ b/samples/client/petstore/c/README.md @@ -71,6 +71,7 @@ Category | Method | HTTP request | Description *PetAPI* | [**PetAPI_findPetsByTags**](docs/PetAPI.md#PetAPI_findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags *PetAPI* | [**PetAPI_getDaysWithoutIncident**](docs/PetAPI.md#PetAPI_getDaysWithoutIncident) | **GET** /store/daysWithoutIncident | Number of days since the last time a pet maimed someone at the store *PetAPI* | [**PetAPI_getPetById**](docs/PetAPI.md#PetAPI_getPetById) | **GET** /pet/{petId} | Find pet by ID +*PetAPI* | [**PetAPI_getPetByUuid**](docs/PetAPI.md#PetAPI_getPetByUuid) | **GET** /pet/byUuid/{uuid} | Find pet by UUID *PetAPI* | [**PetAPI_getPicture**](docs/PetAPI.md#PetAPI_getPicture) | **GET** /pet/picture | Get a random picture of someone else's pet *PetAPI* | [**PetAPI_isPetAvailable**](docs/PetAPI.md#PetAPI_isPetAvailable) | **POST** /pet/{petId}/isAvailable | Is this pet still available? *PetAPI* | [**PetAPI_sharePicture**](docs/PetAPI.md#PetAPI_sharePicture) | **POST** /pet/picture | Send a picture of your happy pet diff --git a/samples/client/petstore/c/api/PetAPI.c b/samples/client/petstore/c/api/PetAPI.c index 61c0f1d3281a..bdae08381642 100644 --- a/samples/client/petstore/c/api/PetAPI.c +++ b/samples/client/petstore/c/api/PetAPI.c @@ -548,6 +548,98 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId) } +// Find pet by UUID +// +// Returns a single pet identified by UUID +// +pet_t* +PetAPI_getPetByUuid(apiClient_t *apiClient, char *uuid) +{ + list_t *localVarQueryParameters = NULL; + list_t *localVarHeaderParameters = NULL; + list_t *localVarFormParameters = NULL; + list_t *localVarHeaderType = list_createList(); + 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("/pet/byUuid/{uuid}"); + + if(!uuid) + goto end; + + + // Path Params + long sizeOfPathParams_uuid = strlen(uuid)+3 + sizeof("{ uuid }") - 1; + if(uuid == NULL) { + goto end; + } + char* localVarToReplace_uuid = malloc(sizeOfPathParams_uuid); + sprintf(localVarToReplace_uuid, "{%s}", "uuid"); + + localVarPath = strReplace(localVarPath, localVarToReplace_uuid, uuid); + + + list_addElement(localVarHeaderType,"application/xml"); //produces + list_addElement(localVarHeaderType,"application/json"); //produces + 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"); + //} + // uncomment below to debug the error response + //if (apiClient->response_code == 400) { + // printf("%s\n","Invalid UUID supplied"); + //} + // uncomment below to debug the error response + //if (apiClient->response_code == 404) { + // printf("%s\n","Pet not found"); + //} + //nonprimitive not container + pet_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = pet_parseFromJSON(PetAPIlocalVarJSON); + cJSON_Delete(PetAPIlocalVarJSON); + if(elementToReturn == NULL) { + // return 0; + } + } + + //return type + if (apiClient->dataReceived) { + free(apiClient->dataReceived); + apiClient->dataReceived = NULL; + apiClient->dataReceivedLen = 0; + } + + + + list_freeList(localVarHeaderType); + + free(localVarPath); + free(localVarToReplace_uuid); + return elementToReturn; +end: + free(localVarPath); + return NULL; + +} + // Get a random picture of someone else's pet // binary_t* diff --git a/samples/client/petstore/c/api/PetAPI.h b/samples/client/petstore/c/api/PetAPI.h index 3dc0c570c29e..18f923caaf41 100644 --- a/samples/client/petstore/c/api/PetAPI.h +++ b/samples/client/petstore/c/api/PetAPI.h @@ -56,6 +56,14 @@ pet_t* PetAPI_getPetById(apiClient_t *apiClient, long petId); +// Find pet by UUID +// +// Returns a single pet identified by UUID +// +pet_t* +PetAPI_getPetByUuid(apiClient_t *apiClient, char *uuid); + + // Get a random picture of someone else's pet // binary_t* diff --git a/samples/client/petstore/c/docs/PetAPI.md b/samples/client/petstore/c/docs/PetAPI.md index 9a9532d952d5..8d376abd3660 100644 --- a/samples/client/petstore/c/docs/PetAPI.md +++ b/samples/client/petstore/c/docs/PetAPI.md @@ -10,6 +10,7 @@ Method | HTTP request | Description [**PetAPI_findPetsByTags**](PetAPI.md#PetAPI_findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags [**PetAPI_getDaysWithoutIncident**](PetAPI.md#PetAPI_getDaysWithoutIncident) | **GET** /store/daysWithoutIncident | Number of days since the last time a pet maimed someone at the store [**PetAPI_getPetById**](PetAPI.md#PetAPI_getPetById) | **GET** /pet/{petId} | Find pet by ID +[**PetAPI_getPetByUuid**](PetAPI.md#PetAPI_getPetByUuid) | **GET** /pet/byUuid/{uuid} | Find pet by UUID [**PetAPI_getPicture**](PetAPI.md#PetAPI_getPicture) | **GET** /pet/picture | Get a random picture of someone else's pet [**PetAPI_isPetAvailable**](PetAPI.md#PetAPI_isPetAvailable) | **POST** /pet/{petId}/isAvailable | Is this pet still available? [**PetAPI_sharePicture**](PetAPI.md#PetAPI_sharePicture) | **POST** /pet/picture | Send a picture of your happy pet @@ -187,6 +188,37 @@ Name | Type | Description | Notes [pet_t](pet.md) * +### Authorization + +[api_key](../README.md#api_key) + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/xml, application/json + +[[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) + +# **PetAPI_getPetByUuid** +```c +// Find pet by UUID +// +// Returns a single pet identified by UUID +// +pet_t* PetAPI_getPetByUuid(apiClient_t *apiClient, char *uuid); +``` + +### Parameters +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**apiClient** | **apiClient_t \*** | context containing the client configuration | +**uuid** | **char \*** | UUID of pet to return | + +### Return type + +[pet_t](pet.md) * + + ### Authorization [api_key](../README.md#api_key)