forked from loafle/openapi-generator-original
* Added a .gitignore to ignore the build folder * Added a CMakeLists and a basic implementation of a double linked list * Added the pet model * changed the behaviour when a list gets freed - the data of each element doesn't get freed anymore * Added the tool uncrustify in order to make code look better * Uncrustified code * added an implementation(constructor and deconstructor) for the category model * Added a third party JSON library * The pet struct now uses pointers for its members; the pet struct now has a proper constructor and a basic toJSON method * The pet model now gets fully serialized into JSON * Fixed the example url... * Added third party library libcurl * Modified category struct and added an unit test * Added a foreach macro and added two functions * Added a tag model and an unit test * the pet struct now uses no double pointer for it's name anymore and no pointer for the enum status anymore; the pet struct can now be fully converted to json and parsed from json * Added the struct APIClient and an unit test * Uncrustified the unit test for category * Added ifdef in pet.h to prevent errors * Added one API endpoint to get a pet by id * Added a "== 0" comparison that I forgot * Added some kind of debug functionality to test-petApi.c * Removed the DEBUG define * Moved the c petstore example from samples/client/c to samples/client/petstore/c * Renamed function getPetById to petApi_getPetById to avoid name collisions * Removed unecessary method in list.c * Added POST functionality; added petApi_addPet method and improved unit-test for petApi; cleaned up some code in apiClient * removed two methods in list.c(string/tag to JSON) and moved their code directly in the pet_convertToJSON method * Removed old, already commented out, puts artifact in apiClient.c * Added a convertToJSON method to the category model * Added a convertToJSON method to the tag model * changed how the convertToJSON method works in the pet model * Adjusted the unit-tests on how the convertToJSON method now works(now returns a cJSON* instead of a char*) * apiClient_t now needs to be given to API methods as a parameter. This means apiClient_t can now be reused in multiple methods. * Added an untested concept for how authentication could be handled * Tested basicAuth using wireshark and added untested OAuth2 feature * Added support for api key authentication using the http-header and tested functionality using wireshark * Renamed the dataToPost parameter in apiClient_invoke to bodyParameters * Renamed apiKey_t to keyValuePair_t and implemented GET queries * Spaces are now being replaced with + in querryParameters * Renamed assembleHeader to assembleAPIKeyAuthentication and added support to change the request type * Implemented the option to provide custom httpHeader fields to apiClient_invoke * Added support for form parameters to the apiClient_invoke method * update petstore sample
68 lines
2.0 KiB
C
68 lines
2.0 KiB
C
#include <assert.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include "apiClient.h"
|
|
#include "list.h"
|
|
#include "keyValuePair.h"
|
|
|
|
#define EXAMPLE_BASE_PATH "localhost"
|
|
#define EXAMPLE_OPERATION_NAME "pets"
|
|
#define OPERATION_PARAMETER "5"
|
|
#define EXAMPLE_KEY_1 "skin color"
|
|
#define EXAMPLE_VALUE_1 "red"
|
|
#define EXAMPLE_KEY_2 "legs"
|
|
#define EXAMPLE_VALUE_2 "4"
|
|
|
|
#define OUTPUT_URL_1 "localhost/pets/5?skin+color=red"
|
|
#define OUTPUT_URL_2 "localhost/pets/5?skin+color=red&legs=4"
|
|
|
|
char *assembleTargetUrl(char *basePath,
|
|
char *operationName,
|
|
char *operationParameter,
|
|
list_t *queryParameters);
|
|
|
|
int main() {
|
|
char *keyOne = malloc(strlen(EXAMPLE_KEY_1) + 1);
|
|
char *valueOne = malloc(strlen(EXAMPLE_VALUE_1) + 1);
|
|
|
|
strcpy(keyOne, EXAMPLE_KEY_1);
|
|
strcpy(valueOne, EXAMPLE_VALUE_1);
|
|
|
|
keyValuePair_t *keyValuePairOne = keyValuePair_create(keyOne, valueOne);
|
|
list_t *list = list_create();
|
|
list_addElement(list, keyValuePairOne);
|
|
|
|
char *exampleUrlOne = assembleTargetUrl(EXAMPLE_BASE_PATH,
|
|
EXAMPLE_OPERATION_NAME,
|
|
OPERATION_PARAMETER,
|
|
list);
|
|
|
|
assert(strcmp(exampleUrlOne, OUTPUT_URL_1) == 0);
|
|
|
|
char *keyTwo = malloc(strlen(EXAMPLE_KEY_2) + 1);
|
|
char *valueTwo = malloc(strlen(EXAMPLE_VALUE_2) + 1);
|
|
|
|
strcpy(keyTwo, EXAMPLE_KEY_2);
|
|
strcpy(valueTwo, EXAMPLE_VALUE_2);
|
|
|
|
keyValuePair_t *keyValuePairTwo = keyValuePair_create(keyTwo, valueTwo);
|
|
list_addElement(list, keyValuePairTwo);
|
|
|
|
char *exampleUrlTwo = assembleTargetUrl(EXAMPLE_BASE_PATH,
|
|
EXAMPLE_OPERATION_NAME,
|
|
OPERATION_PARAMETER,
|
|
list);
|
|
|
|
assert(strcmp(exampleUrlTwo, OUTPUT_URL_2) == 0);
|
|
|
|
free(keyOne);
|
|
free(keyTwo);
|
|
free(valueOne);
|
|
free(valueTwo);
|
|
free(exampleUrlOne);
|
|
free(exampleUrlTwo);
|
|
keyValuePair_free(keyValuePairOne);
|
|
keyValuePair_free(keyValuePairTwo);
|
|
list_free(list);
|
|
} |