forked from loafle/openapi-generator-original
* add c generator (1st commit) * udpate c model template * more fixes * Add string replace function for C generator (#908) * Add string replace function for C generator * Fixed replacement for variable only * Fixed problem for different datatypes of paramName * store return value of modified path * set str_replace variable to be same as original variable. * [C] Fixed coding style issues * add uncrustify support * update petstore sampmles * add Locale.ROOT * added test-api-client.c to include test cases for strReplace function * added header and body mustache and made changes to ClibcurlClientCodegen.java accordingly * [C] renamed functions in apiKey.c.mustache according to apiKey.h.mustache * [C] changes in import statement * renamed apiKey.h to keyValuePair.h and made necessary changes in the codes * changed apiKey.c according to keyValuePair.h * fixed import statement in model * added code for generating struct in model-header.mustache * added typedef struct for model-headers * updated sample/client/petstore/C * fix locale * [C] Function addition and modification of major structs (#1020) * added readme file * fixed parameters in api headers functions * made changes to add readme file and typemapping of array to list * fixed header import statement in apiheader files * modified struct of model type in model header * updated sample * modified README file * updated sample * parse from json function added * modified struct and create function * added include for model * modified parsefromjson function * modified struct and create function for more datatypes * added mapping for date-time and modified model import return statement * modified function parameters * modified include statement * fix function in api body * updated sample * clean up files * regenerate c petstore * fix error message when setting uncrustify * add version to uncrustify usage * added uncrustify rules in mustache (#1021) * added uncrustify rules in mustache * updated sample * updated same with crustify * updated sample with uncrusitfy 0.67 * modified readme about uncrustify requirements * fixed mistakes in readme mustache and sample readme * fix file import, unformat c petstore * fix import in test files * fix model with complexType * fix free string, format the code using uncrustify * modified sample * Modified sample to check * return type issue figured,more to do to fix it * minor fixes to make complete code compile * Compiling sample code. Store has issue with map. * comment out test file generation which is not req. * commented operation name * fixed various issues responsible for code not compiling * test mustache temporary for testing * updated sample add,del,getbyid works, formparam yet to do * few minor changes and added fuction to add different header and content type in apiClient * added code to upload image * added function to test upload image * fixes for fileupload and various other small things * fixed issue due to xml produces * updated sample:working sample add,del,find,uploading:tocheck , * added free functions for variable where memory is allocated * rename imagecontainer struct to filestruct * fix issues with if functions for all list types * fixed issue with primitive return type in header file * updated sample w/ free functions * update c samples * remove corrupted file * update samples * test cases for APIs * added function to generate test cases from new mustache * mustache files for manual written test cases * added default content type to application/json * fixed issue with primitive return type * fixed issue with bool type * added file apiKey.c * updated sample tested * update c environment variable (#1090) * add mapping for map (#1103) * minor update * revert list paramter check to NULL * modified return type for primitive(map - list_t)in mustache * removed apiClient_free as it was two times * updated sample * fixed issue of path parameter when string less than parameter len * fixed issue for form paramters upload * added checks to avoid seg faults * updated sample * added check for null value in form parameter * modified size of mallocs to dynamic * updated sample * Add C Petstore to Travis CI (#1136) * setup CI for C petstore * update bash script permission * unit petapi test * fixed memory leak in strReplace and apiClient Functions * modified return value for status generation * added enum defination and functions to convert and back from string * added function for enum and made changes to free memory at necessary places * added datatype handling for enum * fixes regarding memory allocation and free * updated mustache of test files * updated sample * renamed manually written test files * manual test file for pet * cleaned common api test file for time being * renamed test files * added renamed test files to build test bash * added file null pointer check * modified uncrusitfy rules * minor update to c templates (#1161) * [C] Fixed enum function declaration (#1178) * fixed enum function declaration in model headers * fixed enum declaration in header files for sample * disable curl verbose mode and add response code variable * added response code variable in apiClient struct * modified apiClient header and source file * added response and removed commented code api-body mustache * removed commented code from model-body mustache * removed unnecessary print statements from test mustache * updated sample * fixed spaces issue * Better format in C templates (#1224) * better format in the c template * minor format fix * [C] changed base url from static to dynamic (#1225) * changed basePath from static to dynamic * removed unnecessary header declaration * updated sample * [C] added curl version check in CMakeList.txt (#1248) * added curl version check in CMakeList.txt * Updated README for latest curl version * [C] Major changes to keyValuePair function (#1282) * removed static declaration * changed static declaration * added difference for string and non string * added more code for different function for string and non string * fix issue with param name * change value in keyPairValue to void * fixed issue of difference in function name cases * added support for non char parameters in api * fix issue of map return data * modified manual-StoreAPI map return data handling * fix minor mistake * added support for map and changed code to support value of keyvaluepair as char and other * updated sample * fixed api header declarations * change map declaration in header * resolved issues realted to map data handling * fix minor issues * add N at start if enum variable starts with number * override toParamName method * changed paramters to paramName from baseName * change variables in apibody from baseName to paramName * Skip test file generation (#1459) * skip test file generation * skip overwriting CMakeLists.txt
130 lines
3.9 KiB
C
130 lines
3.9 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <assert.h>
|
|
#include "apiClient.h"
|
|
#include "cJSON.h"
|
|
#include "pet.h"
|
|
#include "PetAPI.h"
|
|
#include "category.h"
|
|
#include "tag.h"
|
|
#include "keyValuePair.h"
|
|
|
|
#define EXAMPLE_CATEGORY_NAME "Example Category"
|
|
#define EXAMPLE_CATEGORY_ID 5
|
|
#define EXAMPLE_PET_NAME "Example Pet"
|
|
#define EXAMPLE_URL_1 "http://www.github.com"
|
|
#define EXAMPLE_URL_2 "http://www.gitter.im"
|
|
#define EXAMPLE_TAG_1_NAME "beautiful code"
|
|
#define EXAMPLE_TAG_2_NAME "at least I tried"
|
|
#define EXAMPLE_TAG_1_ID 1
|
|
#define EXAMPLE_TAG_2_ID 542353
|
|
#define EXAMPLE_PET_ID 1234 // Set to 0 to generate a new pet
|
|
|
|
|
|
int main() {
|
|
// Add pet test
|
|
apiClient_t *apiClient = apiClient_create();
|
|
|
|
char *categoryName = malloc(strlen(EXAMPLE_CATEGORY_NAME) + 1);
|
|
strcpy(categoryName, EXAMPLE_CATEGORY_NAME);
|
|
|
|
category_t *category =
|
|
category_create(EXAMPLE_CATEGORY_ID, categoryName);
|
|
|
|
char *petName = malloc(strlen(EXAMPLE_PET_NAME) + 1);
|
|
strcpy(petName, EXAMPLE_PET_NAME);
|
|
|
|
char *exampleUrl1 = malloc(strlen(EXAMPLE_URL_1) + 1);
|
|
strcpy(exampleUrl1, EXAMPLE_URL_1);
|
|
|
|
char *exampleUrl2 = malloc(strlen(EXAMPLE_URL_2) + 1);
|
|
strcpy(exampleUrl2, EXAMPLE_URL_2);
|
|
|
|
list_t *photoUrls = list_create();
|
|
|
|
list_addElement(photoUrls, exampleUrl1);
|
|
list_addElement(photoUrls, exampleUrl2);
|
|
|
|
char *exampleTag1Name = malloc(strlen(EXAMPLE_TAG_1_NAME) + 1);
|
|
strcpy(exampleTag1Name, EXAMPLE_TAG_1_NAME);
|
|
tag_t *exampleTag1 = tag_create(EXAMPLE_TAG_1_ID, exampleTag1Name);
|
|
|
|
char *exampleTag2Name = malloc(strlen(EXAMPLE_TAG_2_NAME) + 1);
|
|
strcpy(exampleTag2Name, EXAMPLE_TAG_2_NAME);
|
|
tag_t *exampleTag2 = tag_create(EXAMPLE_TAG_2_ID, exampleTag2Name);
|
|
|
|
list_t *tags = list_create();
|
|
|
|
list_addElement(tags, exampleTag1);
|
|
list_addElement(tags, exampleTag2);
|
|
|
|
|
|
status_e status = available;
|
|
pet_t *pet =
|
|
pet_create(EXAMPLE_PET_ID,
|
|
category,
|
|
petName,
|
|
photoUrls,
|
|
tags,
|
|
status);
|
|
|
|
PetAPI_addPet(apiClient, pet);
|
|
pet_free(pet);
|
|
|
|
|
|
// Pet update with form test
|
|
char *petName1 = "Rocky Handsome";
|
|
|
|
char *petName2 = "sold";
|
|
|
|
apiClient_t *apiClient1 = apiClient_create();
|
|
PetAPI_updatePetWithForm(apiClient1, EXAMPLE_PET_ID, petName1,
|
|
petName2);
|
|
|
|
|
|
// Get pet by id test
|
|
apiClient_t *apiClient2 = apiClient_create();
|
|
pet_t *mypet = PetAPI_getPetById(apiClient2, EXAMPLE_PET_ID);
|
|
|
|
cJSON *JSONR = pet_convertToJSON(mypet);
|
|
char *petJson = cJSON_Print(JSONR);
|
|
printf("Data is:%s\n", petJson);
|
|
|
|
assert(strcmp(mypet->name, "Rocky Handsome") == 0);
|
|
assert(mypet->id == EXAMPLE_PET_ID);
|
|
assert(strcmp(mypet->category->name, EXAMPLE_CATEGORY_NAME) == 0);
|
|
assert(mypet->category->id == EXAMPLE_CATEGORY_ID);
|
|
assert(strcmp(list_getElementAt(mypet->photoUrls,
|
|
0)->data, EXAMPLE_URL_1) == 0);
|
|
assert(strcmp(list_getElementAt(mypet->photoUrls,
|
|
1)->data, EXAMPLE_URL_2) == 0);
|
|
assert(((tag_t *) list_getElementAt(mypet->tags,
|
|
0)->data)->id == EXAMPLE_TAG_1_ID);
|
|
assert(((tag_t *) list_getElementAt(mypet->tags,
|
|
1)->data)->id == EXAMPLE_TAG_2_ID);
|
|
assert(strcmp(((tag_t *) list_getElementAt(mypet->tags, 0)->data)->name,
|
|
EXAMPLE_TAG_1_NAME) == 0);
|
|
assert(strcmp(((tag_t *) list_getElementAt(mypet->tags, 1)->data)->name,
|
|
EXAMPLE_TAG_2_NAME) == 0);
|
|
|
|
free(petJson);
|
|
cJSON_Delete(JSONR);
|
|
pet_free(mypet);
|
|
|
|
// Pet upload file Test
|
|
apiClient_t *apiClient3 = apiClient_create();
|
|
FILE *file = fopen("/opt/image.png", "r");
|
|
if(file != NULL) {
|
|
api_response_t *respo = PetAPI_uploadFile(apiClient3,
|
|
EXAMPLE_PET_ID,
|
|
"dec",
|
|
file);
|
|
|
|
api_response_free(respo);
|
|
fclose(file);
|
|
} else {
|
|
apiClient_free(apiClient3);
|
|
}
|
|
}
|