From 3c7688b38d8b27873d265abdf66f613bf3607b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Fern=C3=A1ndez?= Date: Tue, 10 Dec 2024 01:23:29 -0300 Subject: [PATCH] Fix a few issues with the C generator (part 3) (#20269) * [C] Clear the response code from previous api calls Before making an api call, reset apiClient->response_code to zero. That will protect us from checking stale values if the curl request fails. * [C] Check that string arguments are not null Check early on that the arguments are not null, to prevent crashes on strdup() calls. * [C] Don't attempt to fill in a type with error info Check if the api call returned an error before attempting to parse the reply as the expected type. * [C] Handle binary and integer return types * [C] Update test schemas with binary and integer return types * Update samples --- .../resources/C-libcurl/api-body.mustache | 101 ++++-- .../resources/C-libcurl/api-header.mustache | 2 +- .../src/test/resources/2_0/c/petstore.yaml | 26 ++ .../others/c/bearerAuth/api/DefaultAPI.c | 55 +++- .../petstore/c-useJsonUnformatted/README.md | 2 + .../c-useJsonUnformatted/api/PetAPI.c | 290 ++++++++++++++---- .../c-useJsonUnformatted/api/PetAPI.h | 12 + .../c-useJsonUnformatted/api/StoreAPI.c | 61 +++- .../c-useJsonUnformatted/api/UserAPI.c | 61 +++- .../c-useJsonUnformatted/docs/PetAPI.md | 60 ++++ samples/client/petstore/c/README.md | 2 + samples/client/petstore/c/api/PetAPI.c | 290 ++++++++++++++---- samples/client/petstore/c/api/PetAPI.h | 12 + samples/client/petstore/c/api/StoreAPI.c | 61 +++- samples/client/petstore/c/api/UserAPI.c | 61 +++- samples/client/petstore/c/docs/PetAPI.md | 60 ++++ 16 files changed, 955 insertions(+), 201 deletions(-) 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 f7c9c391ce36..7335e277b8ab 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 @@ -98,7 +98,7 @@ end: // {{{.}}} // {{/notes}} -{{#returnType}}{{#returnTypeIsPrimitive}}{{#returnSimpleType}}{{{.}}}*{{/returnSimpleType}}{{^returnSimpleType}}{{#isArray}}{{{.}}}_t*{{/isArray}}{{#isMap}}{{{.}}}{{/isMap}}{{/returnSimpleType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}{{#returnProperty}}{{^isEnum}}{{{returnType}}}_t*{{/isEnum}}{{#isEnum}}{{projectName}}_{{{returnType}}}_{{returnEnumName}}_e{{/isEnum}}{{/returnProperty}}{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void{{/returnType}} +{{#returnType}}{{#returnTypeIsPrimitive}}{{#returnSimpleType}}{{{.}}}{{#returnProperty}}{{#isString}}*{{/isString}}{{/returnProperty}}{{/returnSimpleType}}{{^returnSimpleType}}{{#isArray}}{{{.}}}_t*{{/isArray}}{{#isMap}}{{{.}}}{{/isMap}}{{/returnSimpleType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}{{#returnProperty}}{{^isEnum}}{{{returnType}}}_t*{{/isEnum}}{{#isEnum}}{{projectName}}_{{{returnType}}}_{{returnEnumName}}_e{{/isEnum}}{{/returnProperty}}{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void{{/returnType}} {{{classname}}}_{{{operationId}}}(apiClient_t *apiClient{{#allParams}}, {{#isPrimitiveType}}{{#isNumber}}{{{dataType}}} {{/isNumber}}{{#isLong}}{{{dataType}}} {{/isLong}}{{#isInteger}}{{{dataType}}} *{{/isInteger}}{{#isDouble}}{{{dataType}}} {{/isDouble}}{{#isFloat}}{{{dataType}}} {{/isFloat}}{{#isBoolean}}{{dataType}} *{{/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}}{{#isFreeFormObject}}{{dataType}}_t *{{/isFreeFormObject}}{{/isPrimitiveType}}{{^isArray}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e {{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e {{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}} {{/isEmail}}{{/isPrimitiveType}}{{/isArray}}{{#isContainer}}{{#isArray}}{{dataType}}_t *{{/isArray}}{{#isMap}}{{dataType}} {{/isMap}}{{/isContainer}}{{{paramName}}}{{/allParams}}) { list_t *localVarQueryParameters = {{#hasQueryParams}}list_createList();{{/hasQueryParams}}{{^hasQueryParams}}NULL;{{/hasQueryParams}} @@ -108,11 +108,21 @@ end: list_t *localVarContentType = {{#hasConsumes}}list_createList();{{/hasConsumes}}{{^hasConsumes}}NULL;{{/hasConsumes}} char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("{{{path}}}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "{{{path}}}"); + {{#pathParams}} + {{#isString}} + if(!{{paramName}}) + goto end; + {{/isString}} + {{/pathParams}} + {{#pathParams}} // Path Params @@ -363,51 +373,80 @@ end: {{#returnType}} {{#returnTypeIsPrimitive}} {{#returnSimpleType}} - //primitive return type simple - {{returnType}}* elementToReturn = strdup(({{returnType}}*)apiClient->dataReceived); + {{#returnProperty}} + {{#isBinary}} + //primitive return type simple binary + {{returnType}} elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) + elementToReturn = instantiate_binary_t(apiClient->dataReceived, apiClient->dataReceivedLen); + + {{/isBinary}} + {{#isString}} + //primitive return type simple string + {{returnType}}* elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) + elementToReturn = strdup(({{returnType}}*)apiClient->dataReceived); + {{/isString}} + {{#isInteger}} + //primitive return type simple integer + {{returnType}} elementToReturn = 0; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) + elementToReturn = atoi(apiClient->dataReceived); + + {{/isInteger}} + {{/returnProperty}} {{/returnSimpleType}} {{^returnSimpleType}} //primitive return type not simple - cJSON *{{paramName}}localVarJSON = cJSON_Parse(apiClient->dataReceived); - cJSON *{{{paramName}}}VarJSON; - list_t *elementToReturn = list_createList(); - cJSON_ArrayForEach({{{paramName}}}VarJSON, {{paramName}}localVarJSON){ - keyValuePair_t *keyPair = keyValuePair_create(strdup({{{paramName}}}VarJSON->string), {{{cJSONPrint}}}({{{paramName}}}VarJSON)); - list_addElement(elementToReturn, keyPair); + list_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *{{paramName}}localVarJSON = cJSON_Parse(apiClient->dataReceived); + cJSON *{{{paramName}}}VarJSON; + elementToReturn = list_createList(); + cJSON_ArrayForEach({{{paramName}}}VarJSON, {{paramName}}localVarJSON){ + keyValuePair_t *keyPair = keyValuePair_create(strdup({{{paramName}}}VarJSON->string), {{{cJSONPrint}}}({{{paramName}}}VarJSON)); + list_addElement(elementToReturn, keyPair); + } + cJSON_Delete({{paramName}}localVarJSON); } - cJSON_Delete({{paramName}}localVarJSON); {{/returnSimpleType}} {{/returnTypeIsPrimitive}} {{^returnTypeIsPrimitive}} {{#returnContainer}} - cJSON *{{classname}}localVarJSON = cJSON_Parse(apiClient->dataReceived); - if(!cJSON_IsArray({{classname}}localVarJSON)) { - return 0;//nonprimitive container - } - list_t *elementToReturn = list_createList(); - cJSON *{{{paramName}}}VarJSON; - cJSON_ArrayForEach({{{paramName}}}VarJSON, {{classname}}localVarJSON) - { - if(!cJSON_IsObject({{{paramName}}}VarJSON)) + list_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *{{classname}}localVarJSON = cJSON_Parse(apiClient->dataReceived); + if(!cJSON_IsArray({{classname}}localVarJSON)) { + return 0;//nonprimitive container + } + elementToReturn = list_createList(); + cJSON *{{{paramName}}}VarJSON; + cJSON_ArrayForEach({{{paramName}}}VarJSON, {{classname}}localVarJSON) { - // return 0; + if(!cJSON_IsObject({{{paramName}}}VarJSON)) + { + // return 0; + } + char *localVarJSONToChar = {{{cJSONPrint}}}({{{paramName}}}VarJSON); + list_addElement(elementToReturn , localVarJSONToChar); } - char *localVarJSONToChar = {{{cJSONPrint}}}({{{paramName}}}VarJSON); - list_addElement(elementToReturn , localVarJSONToChar); - } - cJSON_Delete( {{classname}}localVarJSON); - cJSON_Delete( {{{paramName}}}VarJSON); + cJSON_Delete( {{classname}}localVarJSON); + cJSON_Delete( {{{paramName}}}VarJSON); + } {{/returnContainer}} {{^returnContainer}} //nonprimitive not container - cJSON *{{classname}}localVarJSON = cJSON_Parse(apiClient->dataReceived); - {{#returnProperty}}{{^isEnum}}{{{returnBaseType}}}_t *{{/isEnum}}{{#isEnum}}{{projectName}}_{{{returnType}}}_{{returnEnumName}}_e {{/isEnum}}{{/returnProperty}}elementToReturn = {{{returnBaseType}}}_parseFromJSON({{classname}}localVarJSON); - cJSON_Delete({{classname}}localVarJSON); - if(elementToReturn == {{#returnProperty}}{{^isEnum}}NULL{{/isEnum}}{{#isEnum}}0{{/isEnum}}{{/returnProperty}}) { - // return 0; + {{#returnProperty}}{{^isEnum}}{{{returnBaseType}}}_t *{{/isEnum}}{{#isEnum}}{{projectName}}_{{{returnType}}}_{{returnEnumName}}_e {{/isEnum}}{{/returnProperty}}elementToReturn = {{#returnProperty}}{{^isEnum}}NULL{{/isEnum}}{{#isEnum}}0{{/isEnum}}{{/returnProperty}}; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *{{classname}}localVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = {{{returnBaseType}}}_parseFromJSON({{classname}}localVarJSON); + cJSON_Delete({{classname}}localVarJSON); + if(elementToReturn == {{#returnProperty}}{{^isEnum}}NULL{{/isEnum}}{{#isEnum}}0{{/isEnum}}{{/returnProperty}}) { + // return 0; + } } {{/returnContainer}} @@ -550,7 +589,7 @@ end: return elementToReturn; end: free(localVarPath); - return {{#returnProperty}}{{^isEnum}}NULL{{/isEnum}}{{#isEnum}}0{{/isEnum}}{{/returnProperty}}; + return {{#returnProperty}}{{#isInteger}}0{{/isInteger}}{{^isInteger}}{{^isEnum}}NULL{{/isEnum}}{{#isEnum}}0{{/isEnum}}{{/isInteger}}{{/returnProperty}}; {{/returnType}} {{^returnType}} //No return type diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache index 78ac5f576782..4feb6ec9e10f 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache @@ -32,7 +32,7 @@ typedef enum { {{projectName}}_{{operationId}}_{{enumName}}_NULL = 0{{#enumVars // {{{.}}} // {{/notes}} -{{#returnType}}{{#returnTypeIsPrimitive}}{{#returnSimpleType}}{{{.}}}*{{/returnSimpleType}}{{^returnSimpleType}}{{#isArray}}{{{.}}}_t*{{/isArray}}{{#isMap}}{{{.}}}{{/isMap}}{{/returnSimpleType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}{{#returnProperty}}{{^isEnum}}{{{returnType}}}_t*{{/isEnum}}{{#isEnum}}{{projectName}}_{{{returnType}}}_{{returnEnumName}}_e{{/isEnum}}{{/returnProperty}}{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void{{/returnType}} +{{#returnType}}{{#returnTypeIsPrimitive}}{{#returnSimpleType}}{{{.}}}{{#returnProperty}}{{#isString}}*{{/isString}}{{/returnProperty}}{{/returnSimpleType}}{{^returnSimpleType}}{{#isArray}}{{{.}}}_t*{{/isArray}}{{#isMap}}{{{.}}}{{/isMap}}{{/returnSimpleType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}{{#returnProperty}}{{^isEnum}}{{{returnType}}}_t*{{/isEnum}}{{#isEnum}}{{projectName}}_{{{returnType}}}_{{returnEnumName}}_e{{/isEnum}}{{/returnProperty}}{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void{{/returnType}} {{{classname}}}_{{{operationId}}}(apiClient_t *apiClient{{#allParams}}, {{#isPrimitiveType}}{{#isNumber}}{{{dataType}}} {{/isNumber}}{{#isLong}}{{{dataType}}} {{/isLong}}{{#isInteger}}{{{dataType}}} *{{/isInteger}}{{#isDouble}}{{{dataType}}} {{/isDouble}}{{#isFloat}}{{{dataType}}} {{/isFloat}}{{#isBoolean}}{{dataType}} *{{/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}}{{#isFreeFormObject}}{{dataType}}_t *{{/isFreeFormObject}}{{/isPrimitiveType}}{{^isArray}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e {{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e {{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}} {{/isEmail}}{{/isPrimitiveType}}{{/isArray}}{{#isContainer}}{{#isArray}}{{dataType}}_t *{{/isArray}}{{#isMap}}{{dataType}} {{/isMap}}{{/isContainer}}{{{paramName}}}{{/allParams}}); 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 58f99c3126cd..d3b4b7d2417b 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 @@ -254,6 +254,19 @@ paths: - 'write:pets' - 'read:pets' /pet/picture: + get: + tags: + - pet + summary: Get a random picture of someone else's pet + description: '' + operationId: getPicture + parameters: [] + responses: + '200': + description: successful operation + schema: + type: string + format: binary post: tags: - pet @@ -335,6 +348,19 @@ paths: - petstore_auth: - 'write:pets' - 'read:pets' + /store/daysWithoutIncident: + get: + tags: + - pet + summary: Number of days since the last time a pet maimed someone at the store + description: '' + operationId: getDaysWithoutIncident + parameters: [] + responses: + '200': + description: successful operation + schema: + type: integer /store/inventory: get: tags: diff --git a/samples/client/others/c/bearerAuth/api/DefaultAPI.c b/samples/client/others/c/bearerAuth/api/DefaultAPI.c index 2ff9213bff46..5daf87c3e4f9 100644 --- a/samples/client/others/c/bearerAuth/api/DefaultAPI.c +++ b/samples/client/others/c/bearerAuth/api/DefaultAPI.c @@ -26,6 +26,9 @@ DefaultAPI_privateGet(apiClient_t *apiClient) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/private")+1; char *localVarPath = malloc(sizeOfPath); @@ -33,6 +36,7 @@ DefaultAPI_privateGet(apiClient_t *apiClient) + list_addElement(localVarHeaderType,"application/json"); //produces apiClient_invoke(apiClient, localVarPath, @@ -49,11 +53,14 @@ DefaultAPI_privateGet(apiClient_t *apiClient) // printf("%s\n","A JSON object with private information"); //} //nonprimitive not container - cJSON *DefaultAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - object_t *elementToReturn = object_parseFromJSON(DefaultAPIlocalVarJSON); - cJSON_Delete(DefaultAPIlocalVarJSON); - if(elementToReturn == NULL) { - // return 0; + object_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *DefaultAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = object_parseFromJSON(DefaultAPIlocalVarJSON); + cJSON_Delete(DefaultAPIlocalVarJSON); + if(elementToReturn == NULL) { + // return 0; + } } //return type @@ -89,6 +96,9 @@ DefaultAPI_publicGet(apiClient_t *apiClient) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/public")+1; char *localVarPath = malloc(sizeOfPath); @@ -96,6 +106,7 @@ DefaultAPI_publicGet(apiClient_t *apiClient) + list_addElement(localVarHeaderType,"application/json"); //produces apiClient_invoke(apiClient, localVarPath, @@ -112,11 +123,14 @@ DefaultAPI_publicGet(apiClient_t *apiClient) // printf("%s\n","A JSON object with public information"); //} //nonprimitive not container - cJSON *DefaultAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - object_t *elementToReturn = object_parseFromJSON(DefaultAPIlocalVarJSON); - cJSON_Delete(DefaultAPIlocalVarJSON); - if(elementToReturn == NULL) { - // return 0; + object_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *DefaultAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = object_parseFromJSON(DefaultAPIlocalVarJSON); + cJSON_Delete(DefaultAPIlocalVarJSON); + if(elementToReturn == NULL) { + // return 0; + } } //return type @@ -152,6 +166,9 @@ DefaultAPI_usersGet(apiClient_t *apiClient) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/users")+1; char *localVarPath = malloc(sizeOfPath); @@ -159,6 +176,7 @@ DefaultAPI_usersGet(apiClient_t *apiClient) + list_addElement(localVarHeaderType,"application/json"); //produces apiClient_invoke(apiClient, localVarPath, @@ -175,14 +193,17 @@ DefaultAPI_usersGet(apiClient_t *apiClient) // printf("%s\n","A JSON array of user names"); //} //primitive return type not simple - cJSON *localVarJSON = cJSON_Parse(apiClient->dataReceived); - cJSON *VarJSON; - list_t *elementToReturn = list_createList(); - cJSON_ArrayForEach(VarJSON, localVarJSON){ - keyValuePair_t *keyPair = keyValuePair_create(strdup(VarJSON->string), cJSON_Print(VarJSON)); - list_addElement(elementToReturn, keyPair); + list_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *localVarJSON = cJSON_Parse(apiClient->dataReceived); + cJSON *VarJSON; + elementToReturn = list_createList(); + cJSON_ArrayForEach(VarJSON, localVarJSON){ + keyValuePair_t *keyPair = keyValuePair_create(strdup(VarJSON->string), cJSON_Print(VarJSON)); + list_addElement(elementToReturn, keyPair); + } + cJSON_Delete(localVarJSON); } - cJSON_Delete(localVarJSON); if (apiClient->dataReceived) { free(apiClient->dataReceived); diff --git a/samples/client/petstore/c-useJsonUnformatted/README.md b/samples/client/petstore/c-useJsonUnformatted/README.md index 2ce0cfb21307..ed0ab28c7237 100644 --- a/samples/client/petstore/c-useJsonUnformatted/README.md +++ b/samples/client/petstore/c-useJsonUnformatted/README.md @@ -69,7 +69,9 @@ Category | Method | HTTP request | Description *PetAPI* | [**PetAPI_deletePet**](docs/PetAPI.md#PetAPI_deletePet) | **DELETE** /pet/{petId} | Deletes a pet *PetAPI* | [**PetAPI_findPetsByStatus**](docs/PetAPI.md#PetAPI_findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status *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_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 *PetAPI* | [**PetAPI_specialtyPet**](docs/PetAPI.md#PetAPI_specialtyPet) | **GET** /pet/specialty | Specialty of the shop diff --git a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c index 405162b4a0d7..f0ce1f548633 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c +++ b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c @@ -67,6 +67,9 @@ PetAPI_addPet(apiClient_t *apiClient, pet_t *body) list_t *localVarContentType = list_createList(); char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet")+1; char *localVarPath = malloc(sizeOfPath); @@ -75,6 +78,7 @@ PetAPI_addPet(apiClient_t *apiClient, pet_t *body) + // Body Param cJSON *localVarSingleItemJSON_body = NULL; if (body != NULL) @@ -132,12 +136,16 @@ PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/{petId}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/pet/{petId}"); + // Path Params long sizeOfPathParams_petId = sizeof(petId)+3 + strlen("{ petId }"); if(petId == 0){ @@ -219,6 +227,9 @@ PetAPI_findPetsByStatus(apiClient_t *apiClient, list_t *status) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/findByStatus")+1; char *localVarPath = malloc(sizeOfPath); @@ -227,6 +238,7 @@ PetAPI_findPetsByStatus(apiClient_t *apiClient, list_t *status) + // query parameters if (status) { @@ -252,24 +264,27 @@ PetAPI_findPetsByStatus(apiClient_t *apiClient, list_t *status) //if (apiClient->response_code == 400) { // printf("%s\n","Invalid status value"); //} - cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - if(!cJSON_IsArray(PetAPIlocalVarJSON)) { - return 0;//nonprimitive container - } - list_t *elementToReturn = list_createList(); - cJSON *VarJSON; - cJSON_ArrayForEach(VarJSON, PetAPIlocalVarJSON) - { - if(!cJSON_IsObject(VarJSON)) + list_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + if(!cJSON_IsArray(PetAPIlocalVarJSON)) { + return 0;//nonprimitive container + } + elementToReturn = list_createList(); + cJSON *VarJSON; + cJSON_ArrayForEach(VarJSON, PetAPIlocalVarJSON) { - // return 0; + if(!cJSON_IsObject(VarJSON)) + { + // return 0; + } + char *localVarJSONToChar = cJSON_PrintUnformatted(VarJSON); + list_addElement(elementToReturn , localVarJSONToChar); } - char *localVarJSONToChar = cJSON_PrintUnformatted(VarJSON); - list_addElement(elementToReturn , localVarJSONToChar); - } - cJSON_Delete( PetAPIlocalVarJSON); - cJSON_Delete( VarJSON); + cJSON_Delete( PetAPIlocalVarJSON); + cJSON_Delete( VarJSON); + } //return type if (apiClient->dataReceived) { free(apiClient->dataReceived); @@ -303,6 +318,9 @@ PetAPI_findPetsByTags(apiClient_t *apiClient, list_t *tags) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/findByTags")+1; char *localVarPath = malloc(sizeOfPath); @@ -311,6 +329,7 @@ PetAPI_findPetsByTags(apiClient_t *apiClient, list_t *tags) + // query parameters if (tags) { @@ -336,24 +355,27 @@ PetAPI_findPetsByTags(apiClient_t *apiClient, list_t *tags) //if (apiClient->response_code == 400) { // printf("%s\n","Invalid tag value"); //} - cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - if(!cJSON_IsArray(PetAPIlocalVarJSON)) { - return 0;//nonprimitive container - } - list_t *elementToReturn = list_createList(); - cJSON *VarJSON; - cJSON_ArrayForEach(VarJSON, PetAPIlocalVarJSON) - { - if(!cJSON_IsObject(VarJSON)) + list_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + if(!cJSON_IsArray(PetAPIlocalVarJSON)) { + return 0;//nonprimitive container + } + elementToReturn = list_createList(); + cJSON *VarJSON; + cJSON_ArrayForEach(VarJSON, PetAPIlocalVarJSON) { - // return 0; + if(!cJSON_IsObject(VarJSON)) + { + // return 0; + } + char *localVarJSONToChar = cJSON_PrintUnformatted(VarJSON); + list_addElement(elementToReturn , localVarJSONToChar); } - char *localVarJSONToChar = cJSON_PrintUnformatted(VarJSON); - list_addElement(elementToReturn , localVarJSONToChar); - } - cJSON_Delete( PetAPIlocalVarJSON); - cJSON_Delete( VarJSON); + cJSON_Delete( PetAPIlocalVarJSON); + cJSON_Delete( VarJSON); + } //return type if (apiClient->dataReceived) { free(apiClient->dataReceived); @@ -373,6 +395,67 @@ PetAPI_findPetsByTags(apiClient_t *apiClient, list_t *tags) } +// Number of days since the last time a pet maimed someone at the store +// +int +PetAPI_getDaysWithoutIncident(apiClient_t *apiClient) +{ + list_t *localVarQueryParameters = NULL; + list_t *localVarHeaderParameters = NULL; + list_t *localVarFormParameters = NULL; + list_t *localVarHeaderType = list_createList(); + list_t *localVarContentType = NULL; + char *localVarBodyParameters = NULL; + + // clear the error code from the previous api call + apiClient->response_code = 0; + + // create the path + long sizeOfPath = strlen("/store/daysWithoutIncident")+1; + char *localVarPath = malloc(sizeOfPath); + snprintf(localVarPath, sizeOfPath, "/store/daysWithoutIncident"); + + + + + list_addElement(localVarHeaderType,"*/*"); //produces + apiClient_invoke(apiClient, + localVarPath, + localVarQueryParameters, + localVarHeaderParameters, + localVarFormParameters, + localVarHeaderType, + localVarContentType, + localVarBodyParameters, + "GET"); + + // uncomment below to debug the error response + //if (apiClient->response_code == 200) { + // printf("%s\n","successful operation"); + //} + //primitive return type simple integer + int elementToReturn = 0; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) + elementToReturn = atoi(apiClient->dataReceived); + + if (apiClient->dataReceived) { + free(apiClient->dataReceived); + apiClient->dataReceived = NULL; + apiClient->dataReceivedLen = 0; + } + + + + list_freeList(localVarHeaderType); + + free(localVarPath); + return elementToReturn; +end: + free(localVarPath); + return 0; + +} + // Find pet by ID // // Returns a single pet @@ -387,12 +470,16 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/{petId}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/pet/{petId}"); + // Path Params long sizeOfPathParams_petId = sizeof(petId)+3 + strlen("{ petId }"); if(petId == 0){ @@ -433,11 +520,14 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId) // printf("%s\n","Pet not found"); //} //nonprimitive not container - cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - pet_t *elementToReturn = pet_parseFromJSON(PetAPIlocalVarJSON); - cJSON_Delete(PetAPIlocalVarJSON); - if(elementToReturn == NULL) { - // return 0; + 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 @@ -460,6 +550,67 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId) } +// Get a random picture of someone else's pet +// +binary_t* +PetAPI_getPicture(apiClient_t *apiClient) +{ + list_t *localVarQueryParameters = NULL; + list_t *localVarHeaderParameters = NULL; + list_t *localVarFormParameters = NULL; + list_t *localVarHeaderType = list_createList(); + list_t *localVarContentType = NULL; + char *localVarBodyParameters = NULL; + + // clear the error code from the previous api call + apiClient->response_code = 0; + + // create the path + long sizeOfPath = strlen("/pet/picture")+1; + char *localVarPath = malloc(sizeOfPath); + snprintf(localVarPath, sizeOfPath, "/pet/picture"); + + + + + list_addElement(localVarHeaderType,"*/*"); //produces + apiClient_invoke(apiClient, + localVarPath, + localVarQueryParameters, + localVarHeaderParameters, + localVarFormParameters, + localVarHeaderType, + localVarContentType, + localVarBodyParameters, + "GET"); + + // uncomment below to debug the error response + //if (apiClient->response_code == 200) { + // printf("%s\n","successful operation"); + //} + //primitive return type simple binary + binary_t* elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) + elementToReturn = instantiate_binary_t(apiClient->dataReceived, apiClient->dataReceivedLen); + + if (apiClient->dataReceived) { + free(apiClient->dataReceived); + apiClient->dataReceived = NULL; + apiClient->dataReceivedLen = 0; + } + + + + list_freeList(localVarHeaderType); + + free(localVarPath); + return elementToReturn; +end: + free(localVarPath); + return NULL; + +} + // Is this pet still available? // openapi_petstore_bit__e @@ -472,12 +623,16 @@ PetAPI_isPetAvailable(apiClient_t *apiClient, long petId) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/{petId}/isAvailable")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/pet/{petId}/isAvailable"); + // Path Params long sizeOfPathParams_petId = sizeof(petId)+3 + strlen("{ petId }"); if(petId == 0){ @@ -509,11 +664,14 @@ PetAPI_isPetAvailable(apiClient_t *apiClient, long petId) // printf("%s\n","successful operation"); //} //nonprimitive not container - cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - openapi_petstore_bit__e elementToReturn = bit_parseFromJSON(PetAPIlocalVarJSON); - cJSON_Delete(PetAPIlocalVarJSON); - if(elementToReturn == 0) { - // return 0; + openapi_petstore_bit__e elementToReturn = 0; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = bit_parseFromJSON(PetAPIlocalVarJSON); + cJSON_Delete(PetAPIlocalVarJSON); + if(elementToReturn == 0) { + // return 0; + } } //return type @@ -548,6 +706,9 @@ PetAPI_sharePicture(apiClient_t *apiClient, char *picture) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/picture")+1; char *localVarPath = malloc(sizeOfPath); @@ -556,6 +717,7 @@ PetAPI_sharePicture(apiClient_t *apiClient, char *picture) + // Body Param localVarBodyParameters = strdup(picture); list_addElement(localVarHeaderType,"*/*"); //produces @@ -573,8 +735,10 @@ PetAPI_sharePicture(apiClient_t *apiClient, char *picture) //if (apiClient->response_code == 200) { // printf("%s\n","successful operation"); //} - //primitive return type simple - char* elementToReturn = strdup((char*)apiClient->dataReceived); + //primitive return type simple string + char* elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) + elementToReturn = strdup((char*)apiClient->dataReceived); if (apiClient->dataReceived) { free(apiClient->dataReceived); @@ -609,6 +773,9 @@ PetAPI_specialtyPet(apiClient_t *apiClient) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/specialty")+1; char *localVarPath = malloc(sizeOfPath); @@ -616,6 +783,7 @@ PetAPI_specialtyPet(apiClient_t *apiClient) + list_addElement(localVarHeaderType,"application/xml"); //produces list_addElement(localVarHeaderType,"application/json"); //produces apiClient_invoke(apiClient, @@ -633,11 +801,14 @@ PetAPI_specialtyPet(apiClient_t *apiClient) // printf("%s\n","successful operation"); //} //nonprimitive not container - cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - openapi_petstore_preference__e elementToReturn = preference_parseFromJSON(PetAPIlocalVarJSON); - cJSON_Delete(PetAPIlocalVarJSON); - if(elementToReturn == 0) { - // return 0; + openapi_petstore_preference__e elementToReturn = 0; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = preference_parseFromJSON(PetAPIlocalVarJSON); + cJSON_Delete(PetAPIlocalVarJSON); + if(elementToReturn == 0) { + // return 0; + } } //return type @@ -671,6 +842,9 @@ PetAPI_updatePet(apiClient_t *apiClient, pet_t *body) list_t *localVarContentType = list_createList(); char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet")+1; char *localVarPath = malloc(sizeOfPath); @@ -679,6 +853,7 @@ PetAPI_updatePet(apiClient_t *apiClient, pet_t *body) + // Body Param cJSON *localVarSingleItemJSON_body = NULL; if (body != NULL) @@ -744,12 +919,16 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *s list_t *localVarContentType = list_createList(); char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/{petId}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/pet/{petId}"); + // Path Params long sizeOfPathParams_petId = sizeof(petId)+3 + strlen("{ petId }"); if(petId == 0){ @@ -851,12 +1030,16 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, list_t *localVarContentType = list_createList(); char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/{petId}/uploadImage")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/pet/{petId}/uploadImage"); + // Path Params long sizeOfPathParams_petId = sizeof(petId)+3 + strlen("{ petId }"); if(petId == 0){ @@ -913,11 +1096,14 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, // printf("%s\n","successful operation"); //} //nonprimitive not container - cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - api_response_t *elementToReturn = api_response_parseFromJSON(PetAPIlocalVarJSON); - cJSON_Delete(PetAPIlocalVarJSON); - if(elementToReturn == NULL) { - // return 0; + api_response_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = api_response_parseFromJSON(PetAPIlocalVarJSON); + cJSON_Delete(PetAPIlocalVarJSON); + if(elementToReturn == NULL) { + // return 0; + } } //return type diff --git a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h index 5c89fb864da3..94f1757edb27 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h +++ b/samples/client/petstore/c-useJsonUnformatted/api/PetAPI.h @@ -42,6 +42,12 @@ list_t* PetAPI_findPetsByTags(apiClient_t *apiClient, list_t *tags); +// Number of days since the last time a pet maimed someone at the store +// +int +PetAPI_getDaysWithoutIncident(apiClient_t *apiClient); + + // Find pet by ID // // Returns a single pet @@ -50,6 +56,12 @@ pet_t* PetAPI_getPetById(apiClient_t *apiClient, long petId); +// Get a random picture of someone else's pet +// +binary_t* +PetAPI_getPicture(apiClient_t *apiClient); + + // Is this pet still available? // openapi_petstore_bit__e diff --git a/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c b/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c index 77f6d7e2c850..bb3e9df75af0 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c +++ b/samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c @@ -26,11 +26,17 @@ StoreAPI_deleteOrder(apiClient_t *apiClient, char *orderId) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/store/order/{orderId}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/store/order/{orderId}"); + if(!orderId) + goto end; + // Path Params long sizeOfPathParams_orderId = strlen(orderId)+3 + strlen("{ orderId }"); @@ -92,6 +98,9 @@ StoreAPI_getInventory(apiClient_t *apiClient) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/store/inventory")+1; char *localVarPath = malloc(sizeOfPath); @@ -99,6 +108,7 @@ StoreAPI_getInventory(apiClient_t *apiClient) + list_addElement(localVarHeaderType,"application/json"); //produces apiClient_invoke(apiClient, localVarPath, @@ -115,14 +125,17 @@ StoreAPI_getInventory(apiClient_t *apiClient) // printf("%s\n","successful operation"); //} //primitive return type not simple - cJSON *localVarJSON = cJSON_Parse(apiClient->dataReceived); - cJSON *VarJSON; - list_t *elementToReturn = list_createList(); - cJSON_ArrayForEach(VarJSON, localVarJSON){ - keyValuePair_t *keyPair = keyValuePair_create(strdup(VarJSON->string), cJSON_PrintUnformatted(VarJSON)); - list_addElement(elementToReturn, keyPair); + list_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *localVarJSON = cJSON_Parse(apiClient->dataReceived); + cJSON *VarJSON; + elementToReturn = list_createList(); + cJSON_ArrayForEach(VarJSON, localVarJSON){ + keyValuePair_t *keyPair = keyValuePair_create(strdup(VarJSON->string), cJSON_PrintUnformatted(VarJSON)); + list_addElement(elementToReturn, keyPair); + } + cJSON_Delete(localVarJSON); } - cJSON_Delete(localVarJSON); if (apiClient->dataReceived) { free(apiClient->dataReceived); @@ -156,12 +169,16 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/store/order/{orderId}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/store/order/{orderId}"); + // Path Params long sizeOfPathParams_orderId = sizeof(orderId)+3 + strlen("{ orderId }"); if(orderId == 0){ @@ -202,11 +219,14 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) // printf("%s\n","Order not found"); //} //nonprimitive not container - cJSON *StoreAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - order_t *elementToReturn = order_parseFromJSON(StoreAPIlocalVarJSON); - cJSON_Delete(StoreAPIlocalVarJSON); - if(elementToReturn == NULL) { - // return 0; + order_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *StoreAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = order_parseFromJSON(StoreAPIlocalVarJSON); + cJSON_Delete(StoreAPIlocalVarJSON); + if(elementToReturn == NULL) { + // return 0; + } } //return type @@ -241,6 +261,9 @@ StoreAPI_placeOrder(apiClient_t *apiClient, order_t *body) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/store/order")+1; char *localVarPath = malloc(sizeOfPath); @@ -249,6 +272,7 @@ StoreAPI_placeOrder(apiClient_t *apiClient, order_t *body) + // Body Param cJSON *localVarSingleItemJSON_body = NULL; if (body != NULL) @@ -278,11 +302,14 @@ StoreAPI_placeOrder(apiClient_t *apiClient, order_t *body) // printf("%s\n","Invalid Order"); //} //nonprimitive not container - cJSON *StoreAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - order_t *elementToReturn = order_parseFromJSON(StoreAPIlocalVarJSON); - cJSON_Delete(StoreAPIlocalVarJSON); - if(elementToReturn == NULL) { - // return 0; + order_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *StoreAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = order_parseFromJSON(StoreAPIlocalVarJSON); + cJSON_Delete(StoreAPIlocalVarJSON); + if(elementToReturn == NULL) { + // return 0; + } } //return type diff --git a/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c b/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c index 7c82c56cc446..3eda32e2bcfe 100644 --- a/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c +++ b/samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c @@ -26,6 +26,9 @@ UserAPI_createUser(apiClient_t *apiClient, user_t *body) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user")+1; char *localVarPath = malloc(sizeOfPath); @@ -34,6 +37,7 @@ UserAPI_createUser(apiClient_t *apiClient, user_t *body) + // Body Param cJSON *localVarSingleItemJSON_body = NULL; if (body != NULL) @@ -89,6 +93,9 @@ UserAPI_createUsersWithArrayInput(apiClient_t *apiClient, list_t *body) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/createWithArray")+1; char *localVarPath = malloc(sizeOfPath); @@ -97,6 +104,7 @@ UserAPI_createUsersWithArrayInput(apiClient_t *apiClient, list_t *body) + // Body Param //notstring cJSON *localVar_body = NULL; @@ -180,6 +188,9 @@ UserAPI_createUsersWithListInput(apiClient_t *apiClient, list_t *body) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/createWithList")+1; char *localVarPath = malloc(sizeOfPath); @@ -188,6 +199,7 @@ UserAPI_createUsersWithListInput(apiClient_t *apiClient, list_t *body) + // Body Param //notstring cJSON *localVar_body = NULL; @@ -273,11 +285,17 @@ UserAPI_deleteUser(apiClient_t *apiClient, char *username) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/{username}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/user/{username}"); + if(!username) + goto end; + // Path Params long sizeOfPathParams_username = strlen(username)+3 + strlen("{ username }"); @@ -337,11 +355,17 @@ UserAPI_getUserByName(apiClient_t *apiClient, char *username) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/{username}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/user/{username}"); + if(!username) + goto end; + // Path Params long sizeOfPathParams_username = strlen(username)+3 + strlen("{ username }"); @@ -379,11 +403,14 @@ UserAPI_getUserByName(apiClient_t *apiClient, char *username) // printf("%s\n","User not found"); //} //nonprimitive not container - cJSON *UserAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - user_t *elementToReturn = user_parseFromJSON(UserAPIlocalVarJSON); - cJSON_Delete(UserAPIlocalVarJSON); - if(elementToReturn == NULL) { - // return 0; + user_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *UserAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = user_parseFromJSON(UserAPIlocalVarJSON); + cJSON_Delete(UserAPIlocalVarJSON); + if(elementToReturn == NULL) { + // return 0; + } } //return type @@ -418,6 +445,9 @@ UserAPI_loginUser(apiClient_t *apiClient, char *username, char *password) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/login")+1; char *localVarPath = malloc(sizeOfPath); @@ -426,6 +456,7 @@ UserAPI_loginUser(apiClient_t *apiClient, char *username, char *password) + // query parameters char *keyQuery_username = NULL; char * valueQuery_username = NULL; @@ -469,8 +500,10 @@ UserAPI_loginUser(apiClient_t *apiClient, char *username, char *password) //if (apiClient->response_code == 400) { // printf("%s\n","Invalid username/password supplied"); //} - //primitive return type simple - char* elementToReturn = strdup((char*)apiClient->dataReceived); + //primitive return type simple string + char* elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) + elementToReturn = strdup((char*)apiClient->dataReceived); if (apiClient->dataReceived) { free(apiClient->dataReceived); @@ -526,6 +559,9 @@ UserAPI_logoutUser(apiClient_t *apiClient) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/logout")+1; char *localVarPath = malloc(sizeOfPath); @@ -533,6 +569,7 @@ UserAPI_logoutUser(apiClient_t *apiClient) + apiClient_invoke(apiClient, localVarPath, localVarQueryParameters, @@ -577,6 +614,9 @@ UserAPI_testIntAndBool(apiClient_t *apiClient, int *keep, int *keepDay) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/testIntAndBool")+1; char *localVarPath = malloc(sizeOfPath); @@ -585,6 +625,7 @@ UserAPI_testIntAndBool(apiClient_t *apiClient, int *keep, int *keepDay) + // query parameters char *keyQuery_keep = NULL; char * valueQuery_keep = NULL; @@ -654,11 +695,17 @@ UserAPI_updateUser(apiClient_t *apiClient, char *username, user_t *body) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/{username}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/user/{username}"); + if(!username) + goto end; + // Path Params long sizeOfPathParams_username = strlen(username)+3 + strlen("{ username }"); diff --git a/samples/client/petstore/c-useJsonUnformatted/docs/PetAPI.md b/samples/client/petstore/c-useJsonUnformatted/docs/PetAPI.md index 9573ddfe9c45..d3fc1aeae838 100644 --- a/samples/client/petstore/c-useJsonUnformatted/docs/PetAPI.md +++ b/samples/client/petstore/c-useJsonUnformatted/docs/PetAPI.md @@ -8,7 +8,9 @@ Method | HTTP request | Description [**PetAPI_deletePet**](PetAPI.md#PetAPI_deletePet) | **DELETE** /pet/{petId} | Deletes a pet [**PetAPI_findPetsByStatus**](PetAPI.md#PetAPI_findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status [**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_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 [**PetAPI_specialtyPet**](PetAPI.md#PetAPI_specialtyPet) | **GET** /pet/specialty | Specialty of the shop @@ -136,6 +138,35 @@ Name | Type | Description | Notes [[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_getDaysWithoutIncident** +```c +// Number of days since the last time a pet maimed someone at the store +// +int* PetAPI_getDaysWithoutIncident(apiClient_t *apiClient); +``` + +### Parameters +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**apiClient** | **apiClient_t \*** | context containing the client configuration | + +### Return type + +int* + + + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: */* + +[[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_getPetById** ```c // Find pet by ID @@ -167,6 +198,35 @@ Name | Type | Description | Notes [[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_getPicture** +```c +// Get a random picture of someone else's pet +// +binary_t** PetAPI_getPicture(apiClient_t *apiClient); +``` + +### Parameters +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**apiClient** | **apiClient_t \*** | context containing the client configuration | + +### Return type + +binary_t** + + + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: */* + +[[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_isPetAvailable** ```c // Is this pet still available? diff --git a/samples/client/petstore/c/README.md b/samples/client/petstore/c/README.md index 2ce0cfb21307..ed0ab28c7237 100644 --- a/samples/client/petstore/c/README.md +++ b/samples/client/petstore/c/README.md @@ -69,7 +69,9 @@ Category | Method | HTTP request | Description *PetAPI* | [**PetAPI_deletePet**](docs/PetAPI.md#PetAPI_deletePet) | **DELETE** /pet/{petId} | Deletes a pet *PetAPI* | [**PetAPI_findPetsByStatus**](docs/PetAPI.md#PetAPI_findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status *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_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 *PetAPI* | [**PetAPI_specialtyPet**](docs/PetAPI.md#PetAPI_specialtyPet) | **GET** /pet/specialty | Specialty of the shop diff --git a/samples/client/petstore/c/api/PetAPI.c b/samples/client/petstore/c/api/PetAPI.c index adf72e1cf601..5814c1c6fa45 100644 --- a/samples/client/petstore/c/api/PetAPI.c +++ b/samples/client/petstore/c/api/PetAPI.c @@ -67,6 +67,9 @@ PetAPI_addPet(apiClient_t *apiClient, pet_t *body) list_t *localVarContentType = list_createList(); char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet")+1; char *localVarPath = malloc(sizeOfPath); @@ -75,6 +78,7 @@ PetAPI_addPet(apiClient_t *apiClient, pet_t *body) + // Body Param cJSON *localVarSingleItemJSON_body = NULL; if (body != NULL) @@ -132,12 +136,16 @@ PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/{petId}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/pet/{petId}"); + // Path Params long sizeOfPathParams_petId = sizeof(petId)+3 + strlen("{ petId }"); if(petId == 0){ @@ -219,6 +227,9 @@ PetAPI_findPetsByStatus(apiClient_t *apiClient, list_t *status) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/findByStatus")+1; char *localVarPath = malloc(sizeOfPath); @@ -227,6 +238,7 @@ PetAPI_findPetsByStatus(apiClient_t *apiClient, list_t *status) + // query parameters if (status) { @@ -252,24 +264,27 @@ PetAPI_findPetsByStatus(apiClient_t *apiClient, list_t *status) //if (apiClient->response_code == 400) { // printf("%s\n","Invalid status value"); //} - cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - if(!cJSON_IsArray(PetAPIlocalVarJSON)) { - return 0;//nonprimitive container - } - list_t *elementToReturn = list_createList(); - cJSON *VarJSON; - cJSON_ArrayForEach(VarJSON, PetAPIlocalVarJSON) - { - if(!cJSON_IsObject(VarJSON)) + list_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + if(!cJSON_IsArray(PetAPIlocalVarJSON)) { + return 0;//nonprimitive container + } + elementToReturn = list_createList(); + cJSON *VarJSON; + cJSON_ArrayForEach(VarJSON, PetAPIlocalVarJSON) { - // return 0; + if(!cJSON_IsObject(VarJSON)) + { + // return 0; + } + char *localVarJSONToChar = cJSON_Print(VarJSON); + list_addElement(elementToReturn , localVarJSONToChar); } - char *localVarJSONToChar = cJSON_Print(VarJSON); - list_addElement(elementToReturn , localVarJSONToChar); - } - cJSON_Delete( PetAPIlocalVarJSON); - cJSON_Delete( VarJSON); + cJSON_Delete( PetAPIlocalVarJSON); + cJSON_Delete( VarJSON); + } //return type if (apiClient->dataReceived) { free(apiClient->dataReceived); @@ -303,6 +318,9 @@ PetAPI_findPetsByTags(apiClient_t *apiClient, list_t *tags) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/findByTags")+1; char *localVarPath = malloc(sizeOfPath); @@ -311,6 +329,7 @@ PetAPI_findPetsByTags(apiClient_t *apiClient, list_t *tags) + // query parameters if (tags) { @@ -336,24 +355,27 @@ PetAPI_findPetsByTags(apiClient_t *apiClient, list_t *tags) //if (apiClient->response_code == 400) { // printf("%s\n","Invalid tag value"); //} - cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - if(!cJSON_IsArray(PetAPIlocalVarJSON)) { - return 0;//nonprimitive container - } - list_t *elementToReturn = list_createList(); - cJSON *VarJSON; - cJSON_ArrayForEach(VarJSON, PetAPIlocalVarJSON) - { - if(!cJSON_IsObject(VarJSON)) + list_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + if(!cJSON_IsArray(PetAPIlocalVarJSON)) { + return 0;//nonprimitive container + } + elementToReturn = list_createList(); + cJSON *VarJSON; + cJSON_ArrayForEach(VarJSON, PetAPIlocalVarJSON) { - // return 0; + if(!cJSON_IsObject(VarJSON)) + { + // return 0; + } + char *localVarJSONToChar = cJSON_Print(VarJSON); + list_addElement(elementToReturn , localVarJSONToChar); } - char *localVarJSONToChar = cJSON_Print(VarJSON); - list_addElement(elementToReturn , localVarJSONToChar); - } - cJSON_Delete( PetAPIlocalVarJSON); - cJSON_Delete( VarJSON); + cJSON_Delete( PetAPIlocalVarJSON); + cJSON_Delete( VarJSON); + } //return type if (apiClient->dataReceived) { free(apiClient->dataReceived); @@ -373,6 +395,67 @@ PetAPI_findPetsByTags(apiClient_t *apiClient, list_t *tags) } +// Number of days since the last time a pet maimed someone at the store +// +int +PetAPI_getDaysWithoutIncident(apiClient_t *apiClient) +{ + list_t *localVarQueryParameters = NULL; + list_t *localVarHeaderParameters = NULL; + list_t *localVarFormParameters = NULL; + list_t *localVarHeaderType = list_createList(); + list_t *localVarContentType = NULL; + char *localVarBodyParameters = NULL; + + // clear the error code from the previous api call + apiClient->response_code = 0; + + // create the path + long sizeOfPath = strlen("/store/daysWithoutIncident")+1; + char *localVarPath = malloc(sizeOfPath); + snprintf(localVarPath, sizeOfPath, "/store/daysWithoutIncident"); + + + + + list_addElement(localVarHeaderType,"*/*"); //produces + apiClient_invoke(apiClient, + localVarPath, + localVarQueryParameters, + localVarHeaderParameters, + localVarFormParameters, + localVarHeaderType, + localVarContentType, + localVarBodyParameters, + "GET"); + + // uncomment below to debug the error response + //if (apiClient->response_code == 200) { + // printf("%s\n","successful operation"); + //} + //primitive return type simple integer + int elementToReturn = 0; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) + elementToReturn = atoi(apiClient->dataReceived); + + if (apiClient->dataReceived) { + free(apiClient->dataReceived); + apiClient->dataReceived = NULL; + apiClient->dataReceivedLen = 0; + } + + + + list_freeList(localVarHeaderType); + + free(localVarPath); + return elementToReturn; +end: + free(localVarPath); + return 0; + +} + // Find pet by ID // // Returns a single pet @@ -387,12 +470,16 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/{petId}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/pet/{petId}"); + // Path Params long sizeOfPathParams_petId = sizeof(petId)+3 + strlen("{ petId }"); if(petId == 0){ @@ -433,11 +520,14 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId) // printf("%s\n","Pet not found"); //} //nonprimitive not container - cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - pet_t *elementToReturn = pet_parseFromJSON(PetAPIlocalVarJSON); - cJSON_Delete(PetAPIlocalVarJSON); - if(elementToReturn == NULL) { - // return 0; + 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 @@ -460,6 +550,67 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId) } +// Get a random picture of someone else's pet +// +binary_t* +PetAPI_getPicture(apiClient_t *apiClient) +{ + list_t *localVarQueryParameters = NULL; + list_t *localVarHeaderParameters = NULL; + list_t *localVarFormParameters = NULL; + list_t *localVarHeaderType = list_createList(); + list_t *localVarContentType = NULL; + char *localVarBodyParameters = NULL; + + // clear the error code from the previous api call + apiClient->response_code = 0; + + // create the path + long sizeOfPath = strlen("/pet/picture")+1; + char *localVarPath = malloc(sizeOfPath); + snprintf(localVarPath, sizeOfPath, "/pet/picture"); + + + + + list_addElement(localVarHeaderType,"*/*"); //produces + apiClient_invoke(apiClient, + localVarPath, + localVarQueryParameters, + localVarHeaderParameters, + localVarFormParameters, + localVarHeaderType, + localVarContentType, + localVarBodyParameters, + "GET"); + + // uncomment below to debug the error response + //if (apiClient->response_code == 200) { + // printf("%s\n","successful operation"); + //} + //primitive return type simple binary + binary_t* elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) + elementToReturn = instantiate_binary_t(apiClient->dataReceived, apiClient->dataReceivedLen); + + if (apiClient->dataReceived) { + free(apiClient->dataReceived); + apiClient->dataReceived = NULL; + apiClient->dataReceivedLen = 0; + } + + + + list_freeList(localVarHeaderType); + + free(localVarPath); + return elementToReturn; +end: + free(localVarPath); + return NULL; + +} + // Is this pet still available? // openapi_petstore_bit__e @@ -472,12 +623,16 @@ PetAPI_isPetAvailable(apiClient_t *apiClient, long petId) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/{petId}/isAvailable")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/pet/{petId}/isAvailable"); + // Path Params long sizeOfPathParams_petId = sizeof(petId)+3 + strlen("{ petId }"); if(petId == 0){ @@ -509,11 +664,14 @@ PetAPI_isPetAvailable(apiClient_t *apiClient, long petId) // printf("%s\n","successful operation"); //} //nonprimitive not container - cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - openapi_petstore_bit__e elementToReturn = bit_parseFromJSON(PetAPIlocalVarJSON); - cJSON_Delete(PetAPIlocalVarJSON); - if(elementToReturn == 0) { - // return 0; + openapi_petstore_bit__e elementToReturn = 0; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = bit_parseFromJSON(PetAPIlocalVarJSON); + cJSON_Delete(PetAPIlocalVarJSON); + if(elementToReturn == 0) { + // return 0; + } } //return type @@ -548,6 +706,9 @@ PetAPI_sharePicture(apiClient_t *apiClient, char *picture) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/picture")+1; char *localVarPath = malloc(sizeOfPath); @@ -556,6 +717,7 @@ PetAPI_sharePicture(apiClient_t *apiClient, char *picture) + // Body Param localVarBodyParameters = strdup(picture); list_addElement(localVarHeaderType,"*/*"); //produces @@ -573,8 +735,10 @@ PetAPI_sharePicture(apiClient_t *apiClient, char *picture) //if (apiClient->response_code == 200) { // printf("%s\n","successful operation"); //} - //primitive return type simple - char* elementToReturn = strdup((char*)apiClient->dataReceived); + //primitive return type simple string + char* elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) + elementToReturn = strdup((char*)apiClient->dataReceived); if (apiClient->dataReceived) { free(apiClient->dataReceived); @@ -609,6 +773,9 @@ PetAPI_specialtyPet(apiClient_t *apiClient) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/specialty")+1; char *localVarPath = malloc(sizeOfPath); @@ -616,6 +783,7 @@ PetAPI_specialtyPet(apiClient_t *apiClient) + list_addElement(localVarHeaderType,"application/xml"); //produces list_addElement(localVarHeaderType,"application/json"); //produces apiClient_invoke(apiClient, @@ -633,11 +801,14 @@ PetAPI_specialtyPet(apiClient_t *apiClient) // printf("%s\n","successful operation"); //} //nonprimitive not container - cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - openapi_petstore_preference__e elementToReturn = preference_parseFromJSON(PetAPIlocalVarJSON); - cJSON_Delete(PetAPIlocalVarJSON); - if(elementToReturn == 0) { - // return 0; + openapi_petstore_preference__e elementToReturn = 0; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = preference_parseFromJSON(PetAPIlocalVarJSON); + cJSON_Delete(PetAPIlocalVarJSON); + if(elementToReturn == 0) { + // return 0; + } } //return type @@ -671,6 +842,9 @@ PetAPI_updatePet(apiClient_t *apiClient, pet_t *body) list_t *localVarContentType = list_createList(); char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet")+1; char *localVarPath = malloc(sizeOfPath); @@ -679,6 +853,7 @@ PetAPI_updatePet(apiClient_t *apiClient, pet_t *body) + // Body Param cJSON *localVarSingleItemJSON_body = NULL; if (body != NULL) @@ -744,12 +919,16 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *s list_t *localVarContentType = list_createList(); char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/{petId}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/pet/{petId}"); + // Path Params long sizeOfPathParams_petId = sizeof(petId)+3 + strlen("{ petId }"); if(petId == 0){ @@ -851,12 +1030,16 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, list_t *localVarContentType = list_createList(); char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/pet/{petId}/uploadImage")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/pet/{petId}/uploadImage"); + // Path Params long sizeOfPathParams_petId = sizeof(petId)+3 + strlen("{ petId }"); if(petId == 0){ @@ -913,11 +1096,14 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata, // printf("%s\n","successful operation"); //} //nonprimitive not container - cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - api_response_t *elementToReturn = api_response_parseFromJSON(PetAPIlocalVarJSON); - cJSON_Delete(PetAPIlocalVarJSON); - if(elementToReturn == NULL) { - // return 0; + api_response_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = api_response_parseFromJSON(PetAPIlocalVarJSON); + cJSON_Delete(PetAPIlocalVarJSON); + if(elementToReturn == NULL) { + // return 0; + } } //return type diff --git a/samples/client/petstore/c/api/PetAPI.h b/samples/client/petstore/c/api/PetAPI.h index 5c89fb864da3..94f1757edb27 100644 --- a/samples/client/petstore/c/api/PetAPI.h +++ b/samples/client/petstore/c/api/PetAPI.h @@ -42,6 +42,12 @@ list_t* PetAPI_findPetsByTags(apiClient_t *apiClient, list_t *tags); +// Number of days since the last time a pet maimed someone at the store +// +int +PetAPI_getDaysWithoutIncident(apiClient_t *apiClient); + + // Find pet by ID // // Returns a single pet @@ -50,6 +56,12 @@ pet_t* PetAPI_getPetById(apiClient_t *apiClient, long petId); +// Get a random picture of someone else's pet +// +binary_t* +PetAPI_getPicture(apiClient_t *apiClient); + + // Is this pet still available? // openapi_petstore_bit__e diff --git a/samples/client/petstore/c/api/StoreAPI.c b/samples/client/petstore/c/api/StoreAPI.c index a42780f567ac..5fa561df1193 100644 --- a/samples/client/petstore/c/api/StoreAPI.c +++ b/samples/client/petstore/c/api/StoreAPI.c @@ -26,11 +26,17 @@ StoreAPI_deleteOrder(apiClient_t *apiClient, char *orderId) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/store/order/{orderId}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/store/order/{orderId}"); + if(!orderId) + goto end; + // Path Params long sizeOfPathParams_orderId = strlen(orderId)+3 + strlen("{ orderId }"); @@ -92,6 +98,9 @@ StoreAPI_getInventory(apiClient_t *apiClient) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/store/inventory")+1; char *localVarPath = malloc(sizeOfPath); @@ -99,6 +108,7 @@ StoreAPI_getInventory(apiClient_t *apiClient) + list_addElement(localVarHeaderType,"application/json"); //produces apiClient_invoke(apiClient, localVarPath, @@ -115,14 +125,17 @@ StoreAPI_getInventory(apiClient_t *apiClient) // printf("%s\n","successful operation"); //} //primitive return type not simple - cJSON *localVarJSON = cJSON_Parse(apiClient->dataReceived); - cJSON *VarJSON; - list_t *elementToReturn = list_createList(); - cJSON_ArrayForEach(VarJSON, localVarJSON){ - keyValuePair_t *keyPair = keyValuePair_create(strdup(VarJSON->string), cJSON_Print(VarJSON)); - list_addElement(elementToReturn, keyPair); + list_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *localVarJSON = cJSON_Parse(apiClient->dataReceived); + cJSON *VarJSON; + elementToReturn = list_createList(); + cJSON_ArrayForEach(VarJSON, localVarJSON){ + keyValuePair_t *keyPair = keyValuePair_create(strdup(VarJSON->string), cJSON_Print(VarJSON)); + list_addElement(elementToReturn, keyPair); + } + cJSON_Delete(localVarJSON); } - cJSON_Delete(localVarJSON); if (apiClient->dataReceived) { free(apiClient->dataReceived); @@ -156,12 +169,16 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/store/order/{orderId}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/store/order/{orderId}"); + // Path Params long sizeOfPathParams_orderId = sizeof(orderId)+3 + strlen("{ orderId }"); if(orderId == 0){ @@ -202,11 +219,14 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) // printf("%s\n","Order not found"); //} //nonprimitive not container - cJSON *StoreAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - order_t *elementToReturn = order_parseFromJSON(StoreAPIlocalVarJSON); - cJSON_Delete(StoreAPIlocalVarJSON); - if(elementToReturn == NULL) { - // return 0; + order_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *StoreAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = order_parseFromJSON(StoreAPIlocalVarJSON); + cJSON_Delete(StoreAPIlocalVarJSON); + if(elementToReturn == NULL) { + // return 0; + } } //return type @@ -241,6 +261,9 @@ StoreAPI_placeOrder(apiClient_t *apiClient, order_t *body) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/store/order")+1; char *localVarPath = malloc(sizeOfPath); @@ -249,6 +272,7 @@ StoreAPI_placeOrder(apiClient_t *apiClient, order_t *body) + // Body Param cJSON *localVarSingleItemJSON_body = NULL; if (body != NULL) @@ -278,11 +302,14 @@ StoreAPI_placeOrder(apiClient_t *apiClient, order_t *body) // printf("%s\n","Invalid Order"); //} //nonprimitive not container - cJSON *StoreAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - order_t *elementToReturn = order_parseFromJSON(StoreAPIlocalVarJSON); - cJSON_Delete(StoreAPIlocalVarJSON); - if(elementToReturn == NULL) { - // return 0; + order_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *StoreAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = order_parseFromJSON(StoreAPIlocalVarJSON); + cJSON_Delete(StoreAPIlocalVarJSON); + if(elementToReturn == NULL) { + // return 0; + } } //return type diff --git a/samples/client/petstore/c/api/UserAPI.c b/samples/client/petstore/c/api/UserAPI.c index 3f5af05c8094..75852645f422 100644 --- a/samples/client/petstore/c/api/UserAPI.c +++ b/samples/client/petstore/c/api/UserAPI.c @@ -26,6 +26,9 @@ UserAPI_createUser(apiClient_t *apiClient, user_t *body) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user")+1; char *localVarPath = malloc(sizeOfPath); @@ -34,6 +37,7 @@ UserAPI_createUser(apiClient_t *apiClient, user_t *body) + // Body Param cJSON *localVarSingleItemJSON_body = NULL; if (body != NULL) @@ -89,6 +93,9 @@ UserAPI_createUsersWithArrayInput(apiClient_t *apiClient, list_t *body) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/createWithArray")+1; char *localVarPath = malloc(sizeOfPath); @@ -97,6 +104,7 @@ UserAPI_createUsersWithArrayInput(apiClient_t *apiClient, list_t *body) + // Body Param //notstring cJSON *localVar_body = NULL; @@ -180,6 +188,9 @@ UserAPI_createUsersWithListInput(apiClient_t *apiClient, list_t *body) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/createWithList")+1; char *localVarPath = malloc(sizeOfPath); @@ -188,6 +199,7 @@ UserAPI_createUsersWithListInput(apiClient_t *apiClient, list_t *body) + // Body Param //notstring cJSON *localVar_body = NULL; @@ -273,11 +285,17 @@ UserAPI_deleteUser(apiClient_t *apiClient, char *username) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/{username}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/user/{username}"); + if(!username) + goto end; + // Path Params long sizeOfPathParams_username = strlen(username)+3 + strlen("{ username }"); @@ -337,11 +355,17 @@ UserAPI_getUserByName(apiClient_t *apiClient, char *username) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/{username}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/user/{username}"); + if(!username) + goto end; + // Path Params long sizeOfPathParams_username = strlen(username)+3 + strlen("{ username }"); @@ -379,11 +403,14 @@ UserAPI_getUserByName(apiClient_t *apiClient, char *username) // printf("%s\n","User not found"); //} //nonprimitive not container - cJSON *UserAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); - user_t *elementToReturn = user_parseFromJSON(UserAPIlocalVarJSON); - cJSON_Delete(UserAPIlocalVarJSON); - if(elementToReturn == NULL) { - // return 0; + user_t *elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) { + cJSON *UserAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived); + elementToReturn = user_parseFromJSON(UserAPIlocalVarJSON); + cJSON_Delete(UserAPIlocalVarJSON); + if(elementToReturn == NULL) { + // return 0; + } } //return type @@ -418,6 +445,9 @@ UserAPI_loginUser(apiClient_t *apiClient, char *username, char *password) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/login")+1; char *localVarPath = malloc(sizeOfPath); @@ -426,6 +456,7 @@ UserAPI_loginUser(apiClient_t *apiClient, char *username, char *password) + // query parameters char *keyQuery_username = NULL; char * valueQuery_username = NULL; @@ -469,8 +500,10 @@ UserAPI_loginUser(apiClient_t *apiClient, char *username, char *password) //if (apiClient->response_code == 400) { // printf("%s\n","Invalid username/password supplied"); //} - //primitive return type simple - char* elementToReturn = strdup((char*)apiClient->dataReceived); + //primitive return type simple string + char* elementToReturn = NULL; + if(apiClient->response_code >= 200 && apiClient->response_code < 300) + elementToReturn = strdup((char*)apiClient->dataReceived); if (apiClient->dataReceived) { free(apiClient->dataReceived); @@ -526,6 +559,9 @@ UserAPI_logoutUser(apiClient_t *apiClient) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/logout")+1; char *localVarPath = malloc(sizeOfPath); @@ -533,6 +569,7 @@ UserAPI_logoutUser(apiClient_t *apiClient) + apiClient_invoke(apiClient, localVarPath, localVarQueryParameters, @@ -577,6 +614,9 @@ UserAPI_testIntAndBool(apiClient_t *apiClient, int *keep, int *keepDay) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/testIntAndBool")+1; char *localVarPath = malloc(sizeOfPath); @@ -585,6 +625,7 @@ UserAPI_testIntAndBool(apiClient_t *apiClient, int *keep, int *keepDay) + // query parameters char *keyQuery_keep = NULL; char * valueQuery_keep = NULL; @@ -654,11 +695,17 @@ UserAPI_updateUser(apiClient_t *apiClient, char *username, user_t *body) list_t *localVarContentType = NULL; char *localVarBodyParameters = NULL; + // clear the error code from the previous api call + apiClient->response_code = 0; + // create the path long sizeOfPath = strlen("/user/{username}")+1; char *localVarPath = malloc(sizeOfPath); snprintf(localVarPath, sizeOfPath, "/user/{username}"); + if(!username) + goto end; + // Path Params long sizeOfPathParams_username = strlen(username)+3 + strlen("{ username }"); diff --git a/samples/client/petstore/c/docs/PetAPI.md b/samples/client/petstore/c/docs/PetAPI.md index 9573ddfe9c45..d3fc1aeae838 100644 --- a/samples/client/petstore/c/docs/PetAPI.md +++ b/samples/client/petstore/c/docs/PetAPI.md @@ -8,7 +8,9 @@ Method | HTTP request | Description [**PetAPI_deletePet**](PetAPI.md#PetAPI_deletePet) | **DELETE** /pet/{petId} | Deletes a pet [**PetAPI_findPetsByStatus**](PetAPI.md#PetAPI_findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status [**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_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 [**PetAPI_specialtyPet**](PetAPI.md#PetAPI_specialtyPet) | **GET** /pet/specialty | Specialty of the shop @@ -136,6 +138,35 @@ Name | Type | Description | Notes [[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_getDaysWithoutIncident** +```c +// Number of days since the last time a pet maimed someone at the store +// +int* PetAPI_getDaysWithoutIncident(apiClient_t *apiClient); +``` + +### Parameters +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**apiClient** | **apiClient_t \*** | context containing the client configuration | + +### Return type + +int* + + + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: */* + +[[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_getPetById** ```c // Find pet by ID @@ -167,6 +198,35 @@ Name | Type | Description | Notes [[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_getPicture** +```c +// Get a random picture of someone else's pet +// +binary_t** PetAPI_getPicture(apiClient_t *apiClient); +``` + +### Parameters +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**apiClient** | **apiClient_t \*** | context containing the client configuration | + +### Return type + +binary_t** + + + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: */* + +[[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_isPetAvailable** ```c // Is this pet still available?