forked from loafle/openapi-generator-original
[C] C generator refactored (#2463)
* New modified model header and body mustache for c client generator * remove uncrustify from cmake as it is used during code generation, also remove valgrind as it is not used * add function to encode and decode binary data * update model mustache * update api body and header mustache for handling all types of parameters * update model mustache with variable names and address few more issues to generate working codes * updated api body and header mustaches with support for various new parameters and fix some issues as per new changes in code flow structure * update apiClient header and body mustache as per new modifications for handling binary data and few more stuff * updated samples generated by new modified mustache * update handling of file and binary data type to binary_t * update samples with recent commit on master regarding c-generator * update cmakelist which was ignored by .openapi-generator-ignore, cleanup external folder * update CMakeList mustache to show how to use compiled libary to compile source files * update samples with new cmake * Add comments explaining what each command is doing inshort * remove freeing of base path as it is not memory allocated * update samples to free apiclient object when the requirement is over * add missing cJSON delete to fix memory not freed bugs * use uncrustify to beautify manual written test code
This commit is contained in:
committed by
William Cheng
parent
d9bb676038
commit
3be4902444
@@ -133,7 +133,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
languageSpecificPrimitives.add("float");
|
||||
languageSpecificPrimitives.add("double");
|
||||
languageSpecificPrimitives.add("char");
|
||||
languageSpecificPrimitives.add("FILE");
|
||||
languageSpecificPrimitives.add("binary_t*");
|
||||
languageSpecificPrimitives.add("Object");
|
||||
languageSpecificPrimitives.add("list_t*");
|
||||
languageSpecificPrimitives.add("list");
|
||||
@@ -148,8 +148,8 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
typeMapping.put("date", "char");
|
||||
typeMapping.put("DateTime", "char");
|
||||
typeMapping.put("boolean", "int");
|
||||
typeMapping.put("file", "FILE");
|
||||
typeMapping.put("binary", "char");
|
||||
typeMapping.put("file", "binary_t*");
|
||||
typeMapping.put("binary", "binary_t*");
|
||||
typeMapping.put("ByteArray", "char");
|
||||
typeMapping.put("UUID", "char");
|
||||
typeMapping.put("array", "list");
|
||||
|
||||
@@ -10,13 +10,6 @@ set(CMAKE_BUILD_TYPE Debug)
|
||||
|
||||
set(pkgName "{{projectName}}")
|
||||
|
||||
find_program(VALGRIND valgrind)
|
||||
if(VALGRIND)
|
||||
set(CMAKE_MEMORYCHECK_COMMAND valgrind)
|
||||
set(CMAKE_MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --track-origins=yes --read-var-info=yes --show-leak-kinds=all --error-exitcode=1")
|
||||
set(VALGRIND_LIST "")
|
||||
endif()
|
||||
|
||||
find_package(CURL 7.58.0 REQUIRED)
|
||||
if(CURL_FOUND)
|
||||
include_directories(${CURL_INCLUDE_DIR})
|
||||
@@ -65,27 +58,39 @@ set(HDRS
|
||||
|
||||
)
|
||||
|
||||
# Add library with project file with projectname as library name
|
||||
add_library(${pkgName} SHARED ${SRCS} ${HDRS})
|
||||
# Link dependent libraries
|
||||
target_link_libraries(${pkgName} ${CURL_LIBRARIES} )
|
||||
#install library to destination
|
||||
install(TARGETS ${pkgName} DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
|
||||
#For common coding standard (code beautifier/pretty printing)
|
||||
find_program(UNCRUSTIFY uncrustify)
|
||||
if(UNCRUSTIFY)
|
||||
add_custom_target(
|
||||
uncrustify
|
||||
)
|
||||
# Setting file variables to null
|
||||
set(SRCS "")
|
||||
set(HDRS "")
|
||||
|
||||
foreach(ELEMENT ${ALL_SRC_LIST})
|
||||
string(REGEX REPLACE "/" "_" ELEMENT_NAME ${ELEMENT})
|
||||
set(DEP_NAME "uncrustify-${ELEMENT_NAME}")
|
||||
add_custom_target(
|
||||
${DEP_NAME}
|
||||
uncrustify -c uncrustify-rules.cfg --no-backup ${ELEMENT}
|
||||
DEPENDS ${ELEMENT}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
VERBATIM
|
||||
)
|
||||
add_dependencies(uncrustify ${DEP_NAME})
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
## This section shows how to use the above compiled libary to compile the source files
|
||||
## set source files
|
||||
#set(SRCS
|
||||
# unit-tests/manual-PetAPI.c
|
||||
# unit-tests/manual-StoreAPI.c
|
||||
# unit-tests/manual-UserAPI.c
|
||||
# unit-tests/manual-order.c
|
||||
# unit-tests/manual-user.c)
|
||||
|
||||
##set header files
|
||||
#set(HDRS
|
||||
#)
|
||||
|
||||
## loop over all files in SRCS variable
|
||||
#foreach(SOURCE_FILE ${SRCS})
|
||||
# # Get only the file name from the file as add_executable doesnot support executable with slash("/")
|
||||
# get_filename_component(FILE_NAME_ONLY ${SOURCE_FILE} NAME_WE)
|
||||
# # Remove .c from the file name and set it as executable name
|
||||
# string( REPLACE ".c" "" EXECUTABLE_FILE ${FILE_NAME_ONLY})
|
||||
# # Add executable for every source file in SRCS
|
||||
# add_executable(unit-${EXECUTABLE_FILE} ${SOURCE_FILE})
|
||||
# # Link above created libary to executable and dependent libary curl
|
||||
# target_link_libraries(unit-${EXECUTABLE_FILE} ${CURL_LIBRARIES} ${pkgName} )
|
||||
#endforeach(SOURCE_FILE ${SRCS})
|
||||
|
||||
@@ -21,8 +21,9 @@
|
||||
// {{{notes}}}
|
||||
//
|
||||
{{/notes}}
|
||||
{{#returnType}}{{#returnTypeIsPrimitive}}{{#returnSimpleType}}{{{.}}}*{{/returnSimpleType}}{{^returnSimpleType}}{{{.}}}{{/returnSimpleType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}{{{.}}}_t*{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||
{{{classname}}}_{{{operationId}}}(apiClient_t *apiClient{{#allParams}}, {{{dataType}}}{{#isPrimitiveType}}{{#isString}}*{{/isString}}{{#isFile}}*{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}_t*{{/isPrimitiveType}} {{{paramName}}}{{/allParams}}) {
|
||||
{{#returnType}}{{#returnTypeIsPrimitive}}{{#returnSimpleType}}{{{.}}}*{{/returnSimpleType}}{{^returnSimpleType}}{{#isListContainer}}{{{.}}}_t*{{/isListContainer}}{{#isMapContainer}}{{{.}}}{{/isMapContainer}}{{/returnSimpleType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}{{{.}}}_t*{{/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}}{{{baseName}}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}}{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{^isListContainer}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isListContainer}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}}{{#isContainer}}{{#isListContainer}}{{dataType}}_t *{{/isListContainer}}{{#isMapContainer}}{{dataType}}{{/isMapContainer}}{{/isContainer}} {{{paramName}}}{{/allParams}})
|
||||
{
|
||||
list_t *localVarQueryParameters = {{#hasQueryParams}}list_create();{{/hasQueryParams}}{{^hasQueryParams}}NULL;{{/hasQueryParams}}
|
||||
list_t *localVarHeaderParameters = {{#hasHeaderParams}}list_create();{{/hasHeaderParams}}{{^hasHeaderParams}}NULL;{{/hasHeaderParams}}
|
||||
list_t *localVarFormParameters = {{#hasFormParams}}list_create();{{/hasFormParams}}{{^hasFormParams}}NULL;{{/hasFormParams}}
|
||||
@@ -39,13 +40,51 @@
|
||||
|
||||
// Path Params
|
||||
long sizeOfPathParams_{{{paramName}}} = {{#pathParams}}{{#isLong}}sizeof({{paramName}})+3{{/isLong}}{{#isString}}strlen({{paramName}})+3{{/isString}}{{/pathParams}} + strlen("{ {{paramName}} }");
|
||||
{{#isNumeric}}
|
||||
if({{paramName}} == 0){
|
||||
goto end;
|
||||
}
|
||||
char* localVarToReplace_{{paramName}} = malloc(sizeOfPathParams_{{paramName}});
|
||||
snprintf(localVarToReplace_{{paramName}}, sizeOfPathParams_{{paramName}}, "{%s}", "{{paramName}}");
|
||||
|
||||
char localVarBuff_{{paramName}}[256];
|
||||
intToStr(localVarBuff_{{paramName}}, {{paramName}});
|
||||
|
||||
localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, localVarBuff_{{paramName}});
|
||||
|
||||
{{/isNumeric}}
|
||||
{{#isInteger}}
|
||||
if({{paramName}} == 0){
|
||||
goto end;
|
||||
}
|
||||
char* localVarToReplace_{{paramName}} = malloc(sizeOfPathParams_{{paramName}});
|
||||
snprintf(localVarToReplace_{{paramName}}, sizeOfPathParams_{{paramName}}, "{%s}", "{{paramName}}");
|
||||
|
||||
char localVarBuff_{{paramName}}[256];
|
||||
intToStr(localVarBuff_{{paramName}}, {{paramName}});
|
||||
|
||||
localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, localVarBuff_{{paramName}});
|
||||
|
||||
{{/isInteger}}
|
||||
{{#isFloat}}
|
||||
if({{paramName}} == 0){
|
||||
goto end;
|
||||
}
|
||||
char* localVarToReplace_{{paramName}} = malloc(sizeOfPathParams_{{paramName}});
|
||||
snprintf(localVarToReplace_{{paramName}}, sizeOfPathParams_{{paramName}}, "{%s}", "{{paramName}}");
|
||||
|
||||
char localVarBuff_{{paramName}}[256];
|
||||
intToStr(localVarBuff_{{paramName}}, {{paramName}});
|
||||
|
||||
localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, localVarBuff_{{paramName}});
|
||||
|
||||
{{/isFloat}}
|
||||
{{#isLong}}
|
||||
if({{paramName}} == 0){
|
||||
goto end;
|
||||
}
|
||||
char* localVarToReplace_{{paramName}} = malloc(sizeOfPathParams_{{paramName}});
|
||||
snprintf(localVarToReplace_{{paramName}}, sizeOfPathParams_{{paramName}}, "%s%s%s", "{", "{{paramName}}", "}");
|
||||
snprintf(localVarToReplace_{{paramName}}, sizeOfPathParams_{{paramName}}, "{%s}", "{{paramName}}");
|
||||
|
||||
char localVarBuff_{{paramName}}[256];
|
||||
intToStr(localVarBuff_{{paramName}}, {{paramName}});
|
||||
@@ -58,138 +97,83 @@
|
||||
goto end;
|
||||
}
|
||||
char* localVarToReplace_{{paramName}} = malloc(sizeOfPathParams_{{paramName}});
|
||||
sprintf(localVarToReplace_{{paramName}}, "%s%s%s", "{", "{{paramName}}", "}");
|
||||
sprintf(localVarToReplace_{{paramName}}, "{%s}", "{{paramName}}");
|
||||
|
||||
localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, {{paramName}});
|
||||
{{/isString}}
|
||||
{{#isUuid}}
|
||||
if({{paramName}} == NULL) {
|
||||
goto end;
|
||||
}
|
||||
char* localVarToReplace_{{paramName}} = malloc(sizeOfPathParams_{{paramName}});
|
||||
sprintf(localVarToReplace_{{paramName}}, "{%s}", "{{paramName}}");
|
||||
|
||||
localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, {{paramName}});
|
||||
{{/isUuid}}
|
||||
{{/pathParams}}
|
||||
|
||||
|
||||
{{#headerParams}}
|
||||
|
||||
{{#isString}}
|
||||
// header parameters
|
||||
char *keyHeader_{{{paramName}}};
|
||||
char *valueHeader_{{{paramName}}};
|
||||
{{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}{{{dataType}}}{{/isLong}}{{#isInteger}}{{{dataType}}}{{/isInteger}}{{#isDouble}}{{{dataType}}}{{/isDouble}}{{#isFloat}}{{{dataType}}}{{/isFloat}}{{#isBoolean}}{{dataType}}{{/isBoolean}}{{#isEnum}}{{#isString}}{{{baseName}}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}}{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueHeader_{{{paramName}}};
|
||||
keyValuePair_t *keyPairHeader_{{paramName}} = 0;
|
||||
if ({{paramName}}) {
|
||||
keyHeader_{{{paramName}}} = strdup("{{{paramName}}}");
|
||||
valueHeader_{{{paramName}}} = strdup({{{paramName}}});
|
||||
keyPairHeader_{{paramName}} = keyValuePair_create(keyHeader_{{{paramName}}}, valueHeader_{{{paramName}}});
|
||||
valueHeader_{{{paramName}}} = {{#isString}}{{^isEnum}}strdup({{/isEnum}}{{/isString}}({{{paramName}}}){{#isString}}{{^isEnum}}){{/isEnum}}{{/isString}};
|
||||
keyPairHeader_{{paramName}} = keyValuePair_create(keyHeader_{{{paramName}}}, {{#isEnum}}(void *){{/isEnum}}{{^isString}}&{{/isString}}valueHeader_{{{paramName}}});
|
||||
list_addElement(localVarHeaderParameters,keyPairHeader_{{paramName}});
|
||||
}
|
||||
{{/isString}}
|
||||
{{^isString}}
|
||||
// header parameters
|
||||
char *keyHeader_{{{paramName}}};
|
||||
{{dataType}} valueHeader_{{{paramName}}};
|
||||
keyValuePair_t *keyPairHeader_{{paramName}} = 0;
|
||||
if ({{paramName}}) {
|
||||
keyHeader_{{{paramName}}} = strdup("{{{paramName}}}");
|
||||
valueHeader_{{{paramName}}} = {{{paramName}}};
|
||||
keyPairHeader_{{paramName}} = keyValuePair_create(keyHeader_{{{paramName}}}, &valueHeader_{{{paramName}}});
|
||||
list_addElement(localVarHeaderParameters,keyPairHeader_{{paramName}});
|
||||
}
|
||||
{{/isString}}
|
||||
|
||||
{{/headerParams}}
|
||||
{{#queryParams}}
|
||||
|
||||
// query parameters
|
||||
{{#isListContainer}}
|
||||
if ({{paramName}})
|
||||
{{/isListContainer}}
|
||||
{{^isListContainer}}
|
||||
{{#isString}}
|
||||
char *keyQuery_{{{paramName}}};
|
||||
char *valueQuery_{{{paramName}}};
|
||||
{{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}{{{dataType}}}{{/isLong}}{{#isInteger}}{{{dataType}}}{{/isInteger}}{{#isDouble}}{{{dataType}}}{{/isDouble}}{{#isFloat}}{{{dataType}}}{{/isFloat}}{{#isBoolean}}{{{dataType}}}{{/isBoolean}}{{#isEnum}}{{#isString}}{{{baseName}}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}}{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueQuery_{{{paramName}}};
|
||||
keyValuePair_t *keyPairQuery_{{paramName}} = 0;
|
||||
if ({{paramName}})
|
||||
{{/isString}}
|
||||
{{^isString}}
|
||||
char *keyQuery_{{{paramName}}};
|
||||
{{dataType}} valueQuery_{{{paramName}}};
|
||||
keyValuePair_t *keyPairQuery_{{paramName}} = 0;
|
||||
if ({{paramName}})
|
||||
{{/isString}}
|
||||
{{/isListContainer}}
|
||||
if ({{paramName}})
|
||||
{
|
||||
{{#isListContainer}}
|
||||
//listContainer
|
||||
localVarQueryParameters = {{{paramName}}};
|
||||
{{/isListContainer}}
|
||||
{{^isListContainer}}
|
||||
{{#isString}}
|
||||
//string
|
||||
keyQuery_{{{paramName}}} = strdup("{{{paramName}}}");
|
||||
valueQuery_{{{paramName}}} = strdup({{{paramName}}});
|
||||
keyPairQuery_{{paramName}} = keyValuePair_create(keyQuery_{{{paramName}}}, valueQuery_{{{paramName}}});
|
||||
list_addElement(localVarQueryParameters,keyPairQuery_{{paramName}});
|
||||
{{/isString}}
|
||||
{{^isString}}
|
||||
//not string
|
||||
keyQuery_{{{paramName}}} = strdup("{{{paramName}}}");
|
||||
valueQuery_{{{paramName}}} = {{{paramName}}};
|
||||
keyPairQuery_{{paramName}} = keyValuePair_create(keyQuery_{{{paramName}}}, &valueQuery_{{{paramName}}});
|
||||
list_addElement(localVarQueryParameters,keyPairQuery_{{paramName}});
|
||||
{{/isString}}
|
||||
{{/isListContainer}}
|
||||
{{#isListContainer}}
|
||||
list_addElement(localVarQueryParameters,{{paramName}});
|
||||
{{/isListContainer}}
|
||||
{{^isListContainer}}
|
||||
keyQuery_{{{paramName}}} = strdup("{{{paramName}}}");
|
||||
valueQuery_{{{paramName}}} = {{#isString}}{{^isEnum}}strdup({{/isEnum}}{{/isString}}({{{paramName}}}){{#isString}}{{^isEnum}}){{/isEnum}}{{/isString}};
|
||||
keyPairQuery_{{paramName}} = keyValuePair_create(keyQuery_{{{paramName}}}, {{#isEnum}}(void *){{/isEnum}}{{^isString}}&{{/isString}}valueQuery_{{{paramName}}});
|
||||
list_addElement(localVarQueryParameters,keyPairQuery_{{paramName}});
|
||||
{{/isListContainer}}
|
||||
}
|
||||
{{/queryParams}}
|
||||
{{#formParams}}
|
||||
|
||||
// form parameters
|
||||
{{#isFile}}
|
||||
|
||||
char *keyForm_{{paramName}};
|
||||
FileStruct *fileVar_{{paramName}};
|
||||
{{{dataType}}} valueForm_{{paramName}};
|
||||
keyValuePair_t *keyPairForm_{{paramName}} = 0;
|
||||
if ({{paramName}} != NULL)
|
||||
{{/isFile}}
|
||||
{{^isFile}}
|
||||
{{#isString}}
|
||||
char *keyForm_{{paramName}};
|
||||
char *valueForm_{{paramName}};
|
||||
{{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}{{{dataType}}}{{/isLong}}{{#isInteger}}{{{dataType}}}{{/isInteger}}{{#isDouble}}{{{dataType}}}{{/isDouble}}{{#isFloat}}{{{dataType}}}{{/isFloat}}{{#isBoolean}}{{dataType}}{{/isBoolean}}{{#isEnum}}{{#isString}}{{{baseName}}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}}{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueForm_{{paramName}};
|
||||
keyValuePair_t *keyPairForm_{{paramName}} = 0;
|
||||
if ({{paramName}})
|
||||
{{/isString}}
|
||||
{{^isString}}
|
||||
char *keyForm_{{paramName}};
|
||||
{{dataType}} valueForm_{{paramName}};
|
||||
keyValuePair_t *keyPairForm_{{paramName}} = 0;
|
||||
if ({{paramName}})
|
||||
{{/isString}}
|
||||
{{/isFile}}
|
||||
if ({{paramName}} != NULL)
|
||||
{
|
||||
{{#isFile}}
|
||||
fseek({{paramName}}, 0, SEEK_END);
|
||||
long f_size = ftell({{paramName}});
|
||||
fseek({{paramName}}, 0, SEEK_SET);
|
||||
fileVar_{{paramName}} = malloc(sizeof(FileStruct));
|
||||
keyForm_{{paramName}} = strdup("{{{paramName}}}");
|
||||
fileVar_{{paramName}}->fileData = malloc((f_size)* sizeof(char*));
|
||||
|
||||
fread(fileVar_{{paramName}}->fileData, f_size, 1, file);
|
||||
fileVar_{{paramName}}->fileData[f_size] = '\0';
|
||||
|
||||
fileVar_{{paramName}}->fileSize = f_size;
|
||||
char valueFile_{{paramName}}[sizeof(fileVar_{{paramName}})];
|
||||
|
||||
memcpy(valueFile_{{paramName}},&fileVar_{{paramName}}, sizeof(fileVar_{{paramName}}));
|
||||
|
||||
keyPairForm_{{paramName}} = keyValuePair_create(keyForm_{{paramName}},valueFile_{{paramName}});
|
||||
valueForm_{{paramName}} = {{paramName}};
|
||||
keyPairForm_{{paramName}} = keyValuePair_create(keyForm_{{paramName}}, &valueForm_{{paramName}});
|
||||
list_addElement(localVarFormParameters,keyPairForm_{{paramName}}); //file adding
|
||||
{{/isFile}}
|
||||
{{^isFile}}
|
||||
{{#isString}}
|
||||
keyForm_{{paramName}} = strdup("{{{paramName}}}");
|
||||
valueForm_{{paramName}} = strdup({{paramName}});
|
||||
keyPairForm_{{paramName}} = keyValuePair_create(keyForm_{{paramName}},valueForm_{{paramName}});
|
||||
list_addElement(localVarFormParameters,keyPairForm_{{paramName}}); //String
|
||||
{{/isString}}
|
||||
{{^isString}}
|
||||
keyForm_{{paramName}} = strdup("{{{paramName}}}");
|
||||
valueForm_{{paramName}} = {{paramName}};
|
||||
keyPairForm_{{paramName}} = keyValuePair_create(keyForm_{{paramName}},&valueForm_{{paramName}});
|
||||
list_addElement(localVarFormParameters,keyPairForm_{{paramName}}); // not String
|
||||
{{/isString}}
|
||||
valueForm_{{paramName}} = {{#isString}}{{^isEnum}}strdup({{/isEnum}}{{/isString}}({{{paramName}}}){{#isString}}{{^isEnum}}){{/isEnum}}{{/isString}};
|
||||
keyPairForm_{{paramName}} = keyValuePair_create(keyForm_{{paramName}},{{#isString}}{{#isEnum}}(void *){{/isEnum}}{{/isString}}{{^isString}}&{{/isString}}valueForm_{{paramName}});
|
||||
list_addElement(localVarFormParameters,keyPairForm_{{paramName}});
|
||||
{{/isFile}}
|
||||
}
|
||||
{{/formParams}}
|
||||
@@ -201,39 +185,36 @@
|
||||
cJSON *localVar_{{paramName}};
|
||||
cJSON *localVarItemJSON_{{paramName}};
|
||||
cJSON *localVarSingleItemJSON_{{paramName}};
|
||||
if ({{paramName}} != NULL) {
|
||||
if ({{paramName}} != NULL)
|
||||
{
|
||||
localVarItemJSON_{{paramName}} = cJSON_CreateObject();
|
||||
localVarSingleItemJSON_{{paramName}} = cJSON_AddArrayToObject(localVarItemJSON_{{paramName}}, "{{paramName}}");
|
||||
if (localVarSingleItemJSON_{{paramName}} == NULL) {
|
||||
if (localVarSingleItemJSON_{{paramName}} == NULL)
|
||||
{
|
||||
// nonprimitive container
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if(error_ptr != NULL) {
|
||||
fprintf(stderr, "Error Before: %s\n", error_ptr);
|
||||
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
listEntry_t *{{paramName}}BodyListEntry;
|
||||
}
|
||||
|
||||
list_ForEach({{paramName}}BodyListEntry, {{paramName}}) {
|
||||
localVar_{{paramName}} = {{paramName}}_convertToJSON({{paramName}}BodyListEntry->data);
|
||||
if(localVar_{{paramName}} == NULL) {
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if(error_ptr != NULL) {
|
||||
fprintf(stderr, "Error Before: %s\n", error_ptr);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
cJSON_AddItemToArray(localVarSingleItemJSON_{{paramName}}, localVar_{{paramName}});
|
||||
listEntry_t *{{paramName}}BodyListEntry;
|
||||
list_ForEach({{paramName}}BodyListEntry, {{paramName}})
|
||||
{
|
||||
localVar_{{paramName}} = {{#items}}{{complexType}}{{/items}}_convertToJSON({{paramName}}BodyListEntry->data);
|
||||
if(localVar_{{paramName}} == NULL)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
|
||||
cJSON_AddItemToArray(localVarSingleItemJSON_{{paramName}}, localVar_{{paramName}});
|
||||
localVarBodyParameters = cJSON_Print(localVarItemJSON_{{paramName}});
|
||||
}
|
||||
{{/isListContainer}}
|
||||
{{^isListContainer}}
|
||||
cJSON *localVarSingleItemJSON_{{paramName}};
|
||||
if ({{paramName}} != NULL) {
|
||||
if ({{paramName}} != NULL)
|
||||
{
|
||||
//string
|
||||
localVarSingleItemJSON_{{paramName}} = {{paramName}}_convertToJSON({{paramName}});
|
||||
localVarSingleItemJSON_{{paramName}} = {{dataType}}_convertToJSON({{paramName}});
|
||||
localVarBodyParameters = cJSON_Print(localVarSingleItemJSON_{{paramName}});
|
||||
}
|
||||
{{/isListContainer}}
|
||||
@@ -302,7 +283,9 @@
|
||||
{{/returnContainer}}
|
||||
{{^returnContainer}}
|
||||
//nonprimitive not container
|
||||
{{{returnBaseType}}}_t *elementToReturn = {{{returnBaseType}}}_parseFromJSON(apiClient->dataReceived);
|
||||
cJSON *{{classname}}localVarJSON = cJSON_Parse(apiClient->dataReceived);
|
||||
{{{returnBaseType}}}_t *elementToReturn = {{{returnBaseType}}}_parseFromJSON({{classname}}localVarJSON);
|
||||
cJSON_Delete({{classname}}localVarJSON);
|
||||
if(elementToReturn == NULL) {
|
||||
// return 0;
|
||||
}
|
||||
@@ -360,8 +343,8 @@
|
||||
{{#formParams}}
|
||||
{{#isFile}}
|
||||
free(keyForm_{{{paramName}}});
|
||||
free(fileVar_{{paramName}}->fileData);
|
||||
free(fileVar_{{paramName}});
|
||||
// free(fileVar_{{paramName}}->data);
|
||||
// free(fileVar_{{paramName}});
|
||||
free(keyPairForm_{{paramName}});
|
||||
{{/isFile}}
|
||||
{{^isFile}}
|
||||
@@ -433,8 +416,8 @@ end:
|
||||
{{#formParams}}
|
||||
{{#isFile}}
|
||||
free(keyForm_{{{paramName}}});
|
||||
free(fileVar_{{paramName}}->fileData);
|
||||
free(fileVar_{{paramName}});
|
||||
// free(fileVar_{{paramName}}->data);
|
||||
// free(fileVar_{{paramName}});
|
||||
{{/isFile}}
|
||||
{{^isFile}}
|
||||
{{#isString}}
|
||||
|
||||
@@ -18,9 +18,8 @@
|
||||
// {{{notes}}}
|
||||
//
|
||||
{{/notes}}
|
||||
{{#returnType}}{{#returnTypeIsPrimitive}}{{#returnSimpleType}}{{{.}}}*{{/returnSimpleType}}{{^returnSimpleType}}{{{.}}}{{/returnSimpleType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}{{{.}}}_t*{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||
{{{classname}}}_{{{operationId}}}(apiClient_t *apiClient{{#allParams}},{{{dataType}}}{{#isPrimitiveType}}{{#isString}}*{{/isString}}{{#isFile}}*{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}_t*{{/isPrimitiveType}} {{{paramName}}} {{/allParams}});
|
||||
|
||||
{{#returnType}}{{#returnTypeIsPrimitive}}{{#returnSimpleType}}{{{.}}}*{{/returnSimpleType}}{{^returnSimpleType}}{{#isListContainer}}{{{.}}}_t*{{/isListContainer}}{{#isMapContainer}}{{{.}}}{{/isMapContainer}}{{/returnSimpleType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}{{{.}}}_t*{{/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}}{{{baseName}}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}}{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{^isListContainer}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isListContainer}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}}{{#isContainer}}{{#isListContainer}}{{dataType}}_t *{{/isListContainer}}{{#isMapContainer}}{{dataType}}{{/isMapContainer}}{{/isContainer}} {{{paramName}}}{{/allParams}});
|
||||
|
||||
|
||||
{{/operation}}
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "../include/apiClient.h"
|
||||
#ifdef OPENSSL
|
||||
#include "openssl/pem.h"
|
||||
#endif
|
||||
|
||||
size_t writeDataCallback(void *buffer, size_t size, size_t nmemb, void *userp);
|
||||
|
||||
@@ -31,9 +34,6 @@ apiClient_t *apiClient_create() {
|
||||
}
|
||||
|
||||
void apiClient_free(apiClient_t *apiClient) {
|
||||
if(apiClient->basePath) {
|
||||
free(apiClient->basePath);
|
||||
}
|
||||
{{#hasAuthMethods}}
|
||||
{{#authMethods}}
|
||||
{{#isBasic}}
|
||||
@@ -50,7 +50,9 @@ void apiClient_free(apiClient_t *apiClient) {
|
||||
}
|
||||
{{/isOAuth}}
|
||||
{{#isApiKey}}
|
||||
list_free(apiClient->apiKeys);
|
||||
if(apiClient->accessToken) {
|
||||
list_free(apiClient->apiKeys);
|
||||
}
|
||||
{{/isApiKey}}
|
||||
{{/authMethods}}
|
||||
{{/hasAuthMethods}}
|
||||
@@ -170,7 +172,7 @@ void apiClient_invoke(apiClient_t *apiClient,
|
||||
struct curl_slist *headers = NULL;
|
||||
char *buffContent = NULL;
|
||||
char *buffHeader = NULL;
|
||||
FileStruct *fileVar = NULL;
|
||||
binary_t *fileVar = NULL;
|
||||
char *formString = NULL;
|
||||
|
||||
if(headerType != NULL) {
|
||||
@@ -286,8 +288,8 @@ void apiClient_invoke(apiClient_t *apiClient,
|
||||
keyValuePair->value,
|
||||
sizeof(fileVar));
|
||||
curl_mime_data(part,
|
||||
fileVar->fileData,
|
||||
fileVar->fileSize);
|
||||
fileVar->data,
|
||||
fileVar->len);
|
||||
curl_mime_filename(part,
|
||||
"image.png");
|
||||
} else {
|
||||
@@ -492,3 +494,40 @@ char *strReplace(char *orig, char *rep, char *with) {
|
||||
free(originalPointer);
|
||||
return result;
|
||||
}
|
||||
|
||||
char *sbi_base64encode (const void *b64_encode_this, int encode_this_many_bytes){
|
||||
#ifdef OPENSSL
|
||||
BIO *b64_bio, *mem_bio; //Declares two OpenSSL BIOs: a base64 filter and a memory BIO.
|
||||
BUF_MEM *mem_bio_mem_ptr; //Pointer to a "memory BIO" structure holding our base64 data.
|
||||
b64_bio = BIO_new(BIO_f_base64()); //Initialize our base64 filter BIO.
|
||||
mem_bio = BIO_new(BIO_s_mem()); //Initialize our memory sink BIO.
|
||||
BIO_push(b64_bio, mem_bio); //Link the BIOs by creating a filter-sink BIO chain.
|
||||
BIO_set_flags(b64_bio, BIO_FLAGS_BASE64_NO_NL); //No newlines every 64 characters or less.
|
||||
BIO_write(b64_bio, b64_encode_this, encode_this_many_bytes); //Records base64 encoded data.
|
||||
BIO_flush(b64_bio); //Flush data. Necessary for b64 encoding, because of pad characters.
|
||||
BIO_get_mem_ptr(mem_bio, &mem_bio_mem_ptr); //Store address of mem_bio's memory structure.
|
||||
BIO_set_close(mem_bio, BIO_NOCLOSE); //Permit access to mem_ptr after BIOs are destroyed.
|
||||
BIO_free_all(b64_bio); //Destroys all BIOs in chain, starting with b64 (i.e. the 1st one).
|
||||
BUF_MEM_grow(mem_bio_mem_ptr, (*mem_bio_mem_ptr).length + 1); //Makes space for end null.
|
||||
(*mem_bio_mem_ptr).data[(*mem_bio_mem_ptr).length] = '\0'; //Adds null-terminator to tail.
|
||||
return (*mem_bio_mem_ptr).data; //Returns base-64 encoded data. (See: "buf_mem_st" struct).
|
||||
#endif
|
||||
}
|
||||
|
||||
char *sbi_base64decode (const void *b64_decode_this, int decode_this_many_bytes){
|
||||
#ifdef OPENSSL
|
||||
BIO *b64_bio, *mem_bio; //Declares two OpenSSL BIOs: a base64 filter and a memory BIO.
|
||||
char *base64_decoded = calloc( (decode_this_many_bytes*3)/4+1, sizeof(char) ); //+1 = null.
|
||||
b64_bio = BIO_new(BIO_f_base64()); //Initialize our base64 filter BIO.
|
||||
mem_bio = BIO_new(BIO_s_mem()); //Initialize our memory source BIO.
|
||||
BIO_write(mem_bio, b64_decode_this, decode_this_many_bytes); //Base64 data saved in source.
|
||||
BIO_push(b64_bio, mem_bio); //Link the BIOs by creating a filter-source BIO chain.
|
||||
BIO_set_flags(b64_bio, BIO_FLAGS_BASE64_NO_NL); //Don't require trailing newlines.
|
||||
int decoded_byte_index = 0; //Index where the next base64_decoded byte should be written.
|
||||
while ( 0 < BIO_read(b64_bio, base64_decoded+decoded_byte_index, 1) ){ //Read byte-by-byte.
|
||||
decoded_byte_index++; //Increment the index until read of BIO decoded data is complete.
|
||||
} //Once we're done reading decoded data, BIO_read returns -1 even though there's no error.
|
||||
BIO_free_all(b64_bio); //Destroys all BIOs in chain, starting with b64 (i.e. the 1st one).
|
||||
return base64_decoded; //Returns base-64 decoded data with trailing null terminator.
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#ifndef INCLUDE_API_CLIENT_H
|
||||
#define INCLUDE_API_CLIENT_H
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "../include/list.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
|
||||
typedef int bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
typedef struct apiClient_t {
|
||||
char *basePath;
|
||||
void *dataReceived;
|
||||
@@ -28,11 +29,11 @@ typedef struct apiClient_t {
|
||||
{{/hasAuthMethods}}
|
||||
} apiClient_t;
|
||||
|
||||
typedef struct FileStruct
|
||||
typedef struct binary_t
|
||||
{
|
||||
char* fileData;
|
||||
long fileSize;
|
||||
}FileStruct;
|
||||
uint8_t* data;
|
||||
unsigned int len;
|
||||
} binary_t;
|
||||
|
||||
apiClient_t* apiClient_create();
|
||||
|
||||
@@ -42,4 +43,8 @@ void apiClient_invoke(apiClient_t *apiClient,char* operationParameter, list_t *q
|
||||
|
||||
char *strReplace(char *orig, char *rep, char *with);
|
||||
|
||||
char *base64encode(const void *b64_encode_this, int encode_this_many_bytes);
|
||||
|
||||
char *base64decode(const void *b64_decode_this, int decode_this_many_bytes);
|
||||
|
||||
#endif // INCLUDE_API_CLIENT_H
|
||||
|
||||
@@ -6,15 +6,80 @@
|
||||
#include "{{classname}}.h"
|
||||
|
||||
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
char* {{baseName}}{{classname}}_ToString({{baseName}}_e {{baseName}}){
|
||||
char *{{baseName}}Array[] = { {{#allowableValues}}{{#enumVars}}"{{{value}}}"{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} };
|
||||
return {{baseName}}Array[{{baseName}}];
|
||||
|
||||
char* {{classname}}_ToString({{classname}}_e {{classname}}){
|
||||
char *{{classname}}Array[] = { {{#allowableValues}}{{#enumVars}}"{{{value}}}"{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} };
|
||||
return {{classname}}Array[{{classname}}];
|
||||
}
|
||||
|
||||
{{baseName}}_e {{baseName}}{{classname}}_FromString(char* {{baseName}}){
|
||||
{{classname}}_e {{classname}}_FromString(char* {{classname}}){
|
||||
int stringToReturn = 0;
|
||||
char *{{classname}}Array[] = { {{#allowableValues}}{{#enumVars}}"{{{value}}}"{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} };
|
||||
size_t sizeofArray = sizeof({{classname}}Array) / sizeof({{classname}}Array[0]);
|
||||
while(stringToReturn < sizeofArray) {
|
||||
if(strcmp({{classname}}, {{classname}}Array[stringToReturn]) == 0) {
|
||||
return stringToReturn;
|
||||
}
|
||||
stringToReturn++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
cJSON *{{classname}}_convertToJSON({{classname}}_e {{classname}}) {
|
||||
cJSON *item = cJSON_CreateObject();
|
||||
{{#isString}}
|
||||
if(cJSON_AddStringToObject(item, "{{{classname}}}", {{{classname}}}_ToString({{{classname}}})) == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
{{/isString}}
|
||||
{{#isNumeric}}
|
||||
if(cJSON_AddNumberToObject(item, "{{{classname}}}", {{{classname}}}) == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
{{/isNumeric}}
|
||||
return item;
|
||||
fail:
|
||||
cJSON_Delete(item);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
{{classname}}_e {{classname}}_parseFromJSON(cJSON *{{classname}}JSON){
|
||||
|
||||
{{classname}}_e *{{classname}} = NULL;
|
||||
|
||||
{{#isEnum}}
|
||||
{{#isNumeric}}
|
||||
cJSON *{{{classname}}}Var = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{{classname}}}");
|
||||
if(!cJSON_IsNumber({{{classname}}}Var))
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
{{/isNumeric}}
|
||||
{{#isString}}
|
||||
{{{classname}}}_e {{classname}}Variable;
|
||||
cJSON *{{{classname}}}Var = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{{classname}}}");
|
||||
if(!cJSON_IsString({{{classname}}}Var) || ({{{classname}}}Var->valuestring == NULL)){
|
||||
goto end;
|
||||
}
|
||||
{{classname}}Variable = {{classname}}_FromString({{{classname}}}Var->valuestring);
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
return {{classname}}Variable;
|
||||
end:
|
||||
return 0;
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{#vars}}
|
||||
{{^isContainer}}
|
||||
{{^isModel}}
|
||||
{{#isEnum}}
|
||||
char* {{baseName}}{{classname}}_ToString({{baseName}}_e {{baseName}}){
|
||||
char *{{baseName}}Array[] = { {{#allowableValues}}{{#enumVars}}"{{{value}}}"{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} };
|
||||
return {{baseName}}Array[{{baseName}}];
|
||||
}
|
||||
|
||||
{{baseName}}_e {{baseName}}{{classname}}_FromString(char* {{baseName}}){
|
||||
int stringToReturn = 0;
|
||||
char *{{baseName}}Array[] = { {{#allowableValues}}{{#enumVars}}"{{{value}}}"{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} };
|
||||
size_t sizeofArray = sizeof({{baseName}}Array) / sizeof({{baseName}}Array[0]);
|
||||
@@ -24,22 +89,66 @@ char* {{baseName}}{{classname}}_ToString({{baseName}}_e {{baseName}}){
|
||||
}
|
||||
stringToReturn++;
|
||||
}
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{/vars}}
|
||||
return 0;
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{/isModel}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#items}}
|
||||
{{^isModel}}
|
||||
{{#isEnum}}
|
||||
char* {{baseName}}{{classname}}_ToString({{baseName}}_e {{baseName}}){
|
||||
char *{{baseName}}Array[] = { {{#allowableValues}}{{#enumVars}}"{{{value}}}"{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} };
|
||||
return {{baseName}}Array[{{baseName}} - 1];
|
||||
}
|
||||
|
||||
{{baseName}}_e {{baseName}}{{classname}}_FromString(char* {{baseName}}){
|
||||
int stringToReturn = 0;
|
||||
char *{{baseName}}Array[] = { {{#allowableValues}}{{#enumVars}}"{{{value}}}"{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} };
|
||||
size_t sizeofArray = sizeof({{baseName}}Array) / sizeof({{baseName}}Array[0]);
|
||||
while(stringToReturn < sizeofArray) {
|
||||
if(strcmp({{baseName}}, {{baseName}}Array[stringToReturn]) == 0) {
|
||||
return stringToReturn + 1;
|
||||
}
|
||||
stringToReturn++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{/isModel}}
|
||||
{{/items}}
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
|
||||
{{classname}}_t *{{classname}}_create(
|
||||
{{#vars}}
|
||||
{{^isContainer}}
|
||||
{{^isPrimitiveType}}
|
||||
{{#isModel}}
|
||||
{{#isEnum}}
|
||||
{{datatype}}_e {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{datatype}}_t *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isEnum}}
|
||||
{{/isModel}}
|
||||
{{#isUuid}}
|
||||
{{datatype}} *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isUuid}}
|
||||
{{#isEmail}}
|
||||
{{datatype}} *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isEmail}}
|
||||
{{#isFreeFormObject}}
|
||||
{{datatype}}_t *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isFreeFormObject}}
|
||||
{{/isPrimitiveType}}
|
||||
{{#isPrimitiveType}}
|
||||
{{#isNumeric}}
|
||||
{{datatype}} {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isNumeric}}
|
||||
{{#isBoolean}}
|
||||
bool {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{datatype}} {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isBoolean}}
|
||||
{{#isEnum}}
|
||||
{{#isString}}
|
||||
@@ -51,6 +160,15 @@ char* {{baseName}}{{classname}}_ToString({{baseName}}_e {{baseName}}){
|
||||
{{datatype}} *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
{{#isByteArray}}
|
||||
{{datatype}} {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isByteArray}}
|
||||
{{#isBinary}}
|
||||
{{datatype}} {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isBinary}}
|
||||
{{#isDate}}
|
||||
{{datatype}} *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isDate}}
|
||||
{{#isDateTime}}
|
||||
{{datatype}} *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isDateTime}}
|
||||
@@ -67,66 +185,100 @@ char* {{baseName}}{{classname}}_ToString({{baseName}}_e {{baseName}}){
|
||||
{{/isListContainer}}
|
||||
{{#isMapContainer}}
|
||||
{{datatype}} {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
// TODO map/hash not supported at the moment
|
||||
{{/isMapContainer}}
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
) {
|
||||
{{classname}}_t *{{classname}} = malloc(sizeof({{classname}}_t));
|
||||
{{classname}}_t *{{classname}}_local_var = malloc(sizeof({{classname}}_t));
|
||||
if (!{{classname}}_local_var) {
|
||||
return NULL;
|
||||
}
|
||||
{{#vars}}
|
||||
{{classname}}->{{{baseName}}} = {{{baseName}}};
|
||||
{{classname}}_local_var->{{{baseName}}} = {{{baseName}}};
|
||||
{{/vars}}
|
||||
|
||||
return {{classname}};
|
||||
return {{classname}}_local_var;
|
||||
}
|
||||
|
||||
|
||||
void {{classname}}_free({{classname}}_t *{{classname}}) {
|
||||
listEntry_t *listEntry;
|
||||
{{#vars}}
|
||||
{{^isContainer}}
|
||||
{{^isPrimitiveType}}
|
||||
{{{complexType}}}_free({{{classname}}}->{{{baseName}}});
|
||||
{{/isPrimitiveType}}
|
||||
{{#isPrimitiveType}}
|
||||
{{#vars}}
|
||||
{{^isContainer}}
|
||||
{{^isPrimitiveType}}
|
||||
{{#isModel}}
|
||||
{{^isEnum}}
|
||||
{{{complexType}}}_free({{{classname}}}->{{{baseName}}});
|
||||
{{/isEnum}}
|
||||
{{/isModel}}
|
||||
{{#isUuid}}
|
||||
free({{{classname}}}->{{{baseName}}});
|
||||
{{/isUuid}}
|
||||
{{#isEmail}}
|
||||
free({{{classname}}}->{{{baseName}}});
|
||||
{{/isEmail}}
|
||||
{{#isFreeFormObject}}
|
||||
object_free({{{classname}}}->{{{baseName}}});
|
||||
{{/isFreeFormObject}}
|
||||
{{/isPrimitiveType}}
|
||||
{{#isPrimitiveType}}
|
||||
{{^isEnum}}
|
||||
{{#isString}}
|
||||
free({{{classname}}}->{{{baseName}}});
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
{{#isBinary}}
|
||||
free({{{classname}}}->{{{baseName}}}->data);
|
||||
{{/isBinary}}
|
||||
{{#isDate}}
|
||||
free({{{classname}}}->{{{baseName}}});
|
||||
{{/isDate}}
|
||||
{{#isDateTime}}
|
||||
free({{{classname}}}->{{{baseName}}});
|
||||
{{/isDateTime}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#isListContainer}}
|
||||
{{#isPrimitiveType}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#isListContainer}}
|
||||
{{#isPrimitiveType}}
|
||||
list_ForEach(listEntry, {{classname}}->{{baseName}}) {
|
||||
free(listEntry->data);
|
||||
}
|
||||
list_free({{classname}}->{{baseName}});
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
list_ForEach(listEntry, {{classname}}->{{baseName}}) {
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
list_ForEach(listEntry, {{classname}}->{{baseName}}) {
|
||||
{{complexType}}_free(listEntry->data);
|
||||
}
|
||||
list_free({{classname}}->{{baseName}});
|
||||
{{/isPrimitiveType}}
|
||||
{{/isListContainer}}
|
||||
{{#isMapContainer}}
|
||||
// TODO map/hash not supported at the moment
|
||||
{{/isMapContainer}}
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
|
||||
{{/isPrimitiveType}}
|
||||
{{/isListContainer}}
|
||||
{{#isMapContainer}}
|
||||
list_ForEach(listEntry, {{classname}}->{{baseName}}) {
|
||||
keyValuePair_t *localMapKeyPair = (keyValuePair_t*) listEntry->data;
|
||||
free (localKeyValue->key);
|
||||
free (localKeyValue->value);
|
||||
}
|
||||
list_free({{classname}}->{{baseName}});
|
||||
{{/isMapContainer}}
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
free({{classname}});
|
||||
}
|
||||
|
||||
cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
|
||||
cJSON *item = cJSON_CreateObject();
|
||||
{{#vars}}
|
||||
|
||||
// {{{classname}}}->{{{baseName}}}
|
||||
{{#required}}
|
||||
{{^isEnum}}
|
||||
if (!{{{classname}}}->{{{baseName}}}) {
|
||||
goto fail;
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{/required}}
|
||||
{{^required}}{{^isEnum}}if({{{classname}}}->{{{baseName}}}) { {{/isEnum}}{{/required}}
|
||||
{{^isContainer}}
|
||||
{{#isPrimitiveType}}
|
||||
{{#isNumeric}}
|
||||
@@ -136,13 +288,14 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
|
||||
{{/isNumeric}}
|
||||
{{#isBoolean}}
|
||||
if(cJSON_AddBoolToObject(item, "{{{baseName}}}", {{{classname}}}->{{{baseName}}}) == NULL) {
|
||||
goto fail; //Numeric
|
||||
goto fail; //Bool
|
||||
}
|
||||
{{/isBoolean}}
|
||||
{{#isEnum}}
|
||||
{{#isString}}
|
||||
if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{{baseName}}}{{classname}}_ToString({{{classname}}}->{{{baseName}}})) == NULL) {
|
||||
goto fail; //String
|
||||
if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{{baseName}}}{{classname}}_ToString({{{classname}}}->{{{baseName}}})) == NULL)
|
||||
{
|
||||
goto fail; //Enum
|
||||
}
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
@@ -153,21 +306,72 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
|
||||
}
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
{{#isByteArray}}
|
||||
if(cJSON_AddNumberToObject(item, "{{{baseName}}}", {{{classname}}}->{{{baseName}}}) == NULL) {
|
||||
goto fail; //Byte
|
||||
}
|
||||
{{/isByteArray}}
|
||||
{{#isBinary}}
|
||||
char* encoded_str_{{{baseName}}} = base64encode({{{classname}}}->{{{baseName}}}->data,{{{classname}}}->{{{baseName}}}->len);
|
||||
if(cJSON_AddStringToObject(item, "{{{baseName}}}", encoded_str_{{{baseName}}}) == NULL) {
|
||||
goto fail; //Binary
|
||||
}
|
||||
free (encoded_str_{{{baseName}}});
|
||||
{{/isBinary}}
|
||||
{{#isDate}}
|
||||
if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{{classname}}}->{{{baseName}}}) == NULL) {
|
||||
goto fail; //Date
|
||||
}
|
||||
{{/isDate}}
|
||||
{{#isDateTime}}
|
||||
if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{{classname}}}->{{{baseName}}}) == NULL) {
|
||||
goto fail; //String
|
||||
goto fail; //Date-Time
|
||||
}
|
||||
{{/isDateTime}}
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
cJSON *{{{baseName}}} = {{complexType}}_convertToJSON({{{classname}}}->{{{baseName}}});
|
||||
if({{{baseName}}} == NULL) {
|
||||
goto fail; //nonprimitive
|
||||
}
|
||||
cJSON_AddItemToObject(item, "{{{baseName}}}", {{{baseName}}});
|
||||
if(item->child == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
{{#isModel}}
|
||||
{{#isEnum}}
|
||||
cJSON *{{{baseName}}}_enum_local_JSON = {{datatypeWithEnum}}_convertToJSON({{{classname}}}->{{{baseName}}});
|
||||
if({{{baseName}}}_enum_local_JSON == NULL) {
|
||||
goto fail; // enum
|
||||
}
|
||||
cJSON_AddItemToObject(item, "{{{baseName}}}", {{{baseName}}}_enum_local_JSON);
|
||||
if(item->child == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
cJSON *{{{baseName}}}_local_JSON = {{complexType}}{{#isFreeFormObject}}object{{/isFreeFormObject}}_convertToJSON({{{classname}}}->{{{baseName}}});
|
||||
if({{{baseName}}}_local_JSON == NULL) {
|
||||
goto fail; //model
|
||||
}
|
||||
cJSON_AddItemToObject(item, "{{{baseName}}}", {{{baseName}}}_local_JSON);
|
||||
if(item->child == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{/isModel}}
|
||||
{{#isUuid}}
|
||||
if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{{classname}}}->{{{baseName}}}) == NULL) {
|
||||
goto fail; //uuid
|
||||
}
|
||||
{{/isUuid}}
|
||||
{{#isEmail}}
|
||||
if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{{classname}}}->{{{baseName}}}) == NULL) {
|
||||
goto fail; //Email
|
||||
}
|
||||
{{/isEmail}}
|
||||
{{#isFreeFormObject}}
|
||||
cJSON *{{{baseName}}}_object = object_convertToJSON({{{classname}}}->{{{baseName}}});
|
||||
if({{{baseName}}}_object == NULL) {
|
||||
goto fail; //model
|
||||
}
|
||||
cJSON_AddItemToObject(item, "{{{baseName}}}", {{{baseName}}}_object);
|
||||
if(item->child == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
{{/isFreeFormObject}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
@@ -180,46 +384,48 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
|
||||
|
||||
listEntry_t *{{{name}}}ListEntry;
|
||||
list_ForEach({{{name}}}ListEntry, {{{classname}}}->{{{baseName}}}) {
|
||||
{{#items}}
|
||||
{{#isString}}
|
||||
if(cJSON_AddStringToObject({{{baseName}}}, "", (char*){{{baseName}}}ListEntry->data) == NULL)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
{{/isString}}
|
||||
{{^isString}}
|
||||
if(cJSON_AddNumberToObject({{{baseName}}}, "", *(double *){{{baseName}}}ListEntry->data) == NULL)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
{{/isString}}
|
||||
{{/items}}
|
||||
{{#items}}
|
||||
{{#isString}}
|
||||
if(cJSON_AddStringToObject({{{baseName}}}, "", (char*){{{baseName}}}ListEntry->data) == NULL)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
{{/isString}}
|
||||
{{^isString}}
|
||||
if(cJSON_AddNumberToObject({{{baseName}}}, "", *(double *){{{baseName}}}ListEntry->data) == NULL)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
{{/isString}}
|
||||
{{/items}}
|
||||
}
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
cJSON *{{{baseName}}} = cJSON_AddArrayToObject(item, "{{{baseName}}}");
|
||||
if({{{baseName}}} == NULL) {
|
||||
goto fail; //nonprimitive container
|
||||
}
|
||||
if({{{baseName}}} == NULL) {
|
||||
goto fail; //nonprimitive container
|
||||
}
|
||||
|
||||
listEntry_t *{{{baseName}}}ListEntry;
|
||||
list_ForEach({{{baseName}}}ListEntry, {{classname}}->{{{baseName}}}) {
|
||||
cJSON *item = {{complexType}}_convertToJSON({{{baseName}}}ListEntry->data);
|
||||
if(item == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
cJSON_AddItemToArray({{{baseName}}}, item);
|
||||
}
|
||||
listEntry_t *{{{baseName}}}ListEntry;
|
||||
if ({{{classname}}}->{{{baseName}}}) {
|
||||
list_ForEach({{{baseName}}}ListEntry, {{classname}}->{{{baseName}}}) {
|
||||
cJSON *itemLocal = {{complexType}}_convertToJSON({{#isEnum}}{{#items}}({{datatypeWithEnum}}_e){{/items}}{{/isEnum}}{{{baseName}}}ListEntry->data);
|
||||
if(itemLocal == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
cJSON_AddItemToArray({{{baseName}}}, itemLocal);
|
||||
}
|
||||
}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isListContainer}}
|
||||
{{#isMapContainer}}
|
||||
// map Container
|
||||
cJSON *{{{baseName}}} = cJSON_AddObjectToObject(item, "{{{baseName}}}");
|
||||
if({{{baseName}}} == NULL) {
|
||||
goto fail; //primitive map container
|
||||
}
|
||||
cJSON *localMapObject = cJSON_CreateObject(); //Memory free to be implemented in user code
|
||||
listEntry_t *{{{baseName}}}ListEntry;
|
||||
if ({{{classname}}}->{{{baseName}}}) {
|
||||
list_ForEach({{{baseName}}}ListEntry, {{{classname}}}->{{{baseName}}}) {
|
||||
keyValuePair_t *localKeyValue = (keyValuePair_t*){{{baseName}}}ListEntry->data;
|
||||
{{#items}}
|
||||
@@ -237,232 +443,305 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
|
||||
{{/isString}}
|
||||
{{/items}}
|
||||
cJSON_AddItemToObject({{{baseName}}},"", localMapObject);
|
||||
}
|
||||
}
|
||||
{{/isMapContainer}}
|
||||
{{/isContainer}}
|
||||
{{^required}}
|
||||
{{^isEnum}} } {{/isEnum}}
|
||||
{{/required}}
|
||||
|
||||
{{/vars}}
|
||||
return item;
|
||||
fail:
|
||||
cJSON_Delete(item);
|
||||
if (item) {
|
||||
cJSON_Delete(item);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
{{classname}}_t *{{classname}}_parseFromJSON(char *jsonString){
|
||||
{{classname}}_t *{{classname}}_parseFromJSON(cJSON *{{classname}}JSON){
|
||||
|
||||
{{classname}}_t *{{classname}} = NULL;
|
||||
cJSON *{{classname}}JSON = cJSON_Parse(jsonString);
|
||||
if({{classname}}JSON == NULL){
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if (error_ptr != NULL) {
|
||||
fprintf(stderr, "Error Before: %s\n", error_ptr);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
{{classname}}_t *{{classname}}_local_var = NULL;
|
||||
|
||||
{{#vars}}
|
||||
// {{{classname}}}->{{{baseName}}}
|
||||
cJSON *{{{baseName}}} = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{{baseName}}}");
|
||||
{{#required}}
|
||||
if (!{{{baseName}}}) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
{{/required}}
|
||||
{{^isContainer}}
|
||||
{{#isPrimitiveType}}
|
||||
{{#isNumeric}}
|
||||
cJSON *{{{baseName}}} = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{{baseName}}}");
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
if(!cJSON_IsNumber({{{baseName}}}))
|
||||
{
|
||||
goto end; //Numeric
|
||||
}
|
||||
{{/isNumeric}}
|
||||
{{#isBoolean}}
|
||||
cJSON *{{{baseName}}} = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{{baseName}}}");
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
if(!cJSON_IsBool({{{baseName}}}))
|
||||
{
|
||||
goto end; //Numeric
|
||||
goto end; //Bool
|
||||
}
|
||||
{{/isBoolean}}
|
||||
{{#isEnum}}
|
||||
{{#isString}}
|
||||
{{{baseName}}}_e {{baseName}}Variable;
|
||||
cJSON *{{{baseName}}} = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{{baseName}}}");
|
||||
if(!cJSON_IsString({{{baseName}}}) || ({{{baseName}}}->valuestring == NULL)){
|
||||
goto end; //String
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
if(!cJSON_IsString({{{baseName}}}))
|
||||
{
|
||||
goto end; //Enum
|
||||
}
|
||||
|
||||
{{baseName}}Variable = {{baseName}}{{classname}}_FromString({{{baseName}}}->valuestring);
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{#isString}}
|
||||
cJSON *{{{baseName}}} = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{{baseName}}}");
|
||||
if(!cJSON_IsString({{{baseName}}}) || ({{{baseName}}}->valuestring == NULL)){
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
if(!cJSON_IsString({{{baseName}}}))
|
||||
{
|
||||
goto end; //String
|
||||
}
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
{{#isByteArray}}
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
if(!cJSON_IsNumber({{{baseName}}}))
|
||||
{
|
||||
goto end; //Byte
|
||||
}
|
||||
{{/isByteArray}}
|
||||
{{#isBinary}}
|
||||
binary_t* decoded_str_{{{baseName}}};
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
if(!cJSON_IsString({{{baseName}}}))
|
||||
{
|
||||
goto end; //Binary
|
||||
}
|
||||
char* decoded = base64decode({{{baseName}}}->valuestring, strlen({{{baseName}}}->valuestring));
|
||||
decoded_str_{{{baseName}}}->data = malloc(strlen(decoded) - 1);
|
||||
if (!decoded_str_{{{baseName}}}->data) {
|
||||
goto end;
|
||||
}
|
||||
memcpy(decoded_str_{{{baseName}}}->data,decoded,(strlen(decoded)-1));
|
||||
decoded_str_{{{baseName}}}->len = strlen(decoded) - 1;
|
||||
{{/isBinary}}
|
||||
{{#isDate}}
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
if(!cJSON_IsString({{{baseName}}}))
|
||||
{
|
||||
goto end; //Date
|
||||
}
|
||||
{{/isDate}}
|
||||
{{#isDateTime}}
|
||||
cJSON *{{{baseName}}} = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{{baseName}}}");
|
||||
if(!cJSON_IsString({{{baseName}}}) || ({{{baseName}}}->valuestring == NULL)){
|
||||
goto end; //String
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
if(!cJSON_IsString({{{baseName}}}))
|
||||
{
|
||||
goto end; //DateTime
|
||||
}
|
||||
{{/isDateTime}}
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
{{complexType}}_t *{{baseName}};
|
||||
cJSON *{{baseName}}JSON = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{baseName}}");
|
||||
if({{classname}}JSON == NULL){
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if (error_ptr != NULL)
|
||||
fprintf(stderr, "Error Before: %s\n", error_ptr);
|
||||
goto end; //nonprimitive
|
||||
{{#isModel}}
|
||||
{{#isEnum}}
|
||||
{{datatypeWithEnum}}_e {{baseName}}_local_nonprim_enum;
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
{{{baseName}}}_local_nonprim_enum = {{datatypeWithEnum}}_parseFromJSON({{{baseName}}}); //enum model
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{^isFreeFormObject}}{{complexType}}{{/isFreeFormObject}}{{#isFreeFormObject}}object{{/isFreeFormObject}}_t *{{baseName}}_local_nonprim = NULL;
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
{{{baseName}}}_local_nonprim = {{complexType}}{{#isFreeFormObject}}object{{/isFreeFormObject}}_parseFromJSON({{{baseName}}}); //nonprimitive
|
||||
{{/isEnum}}
|
||||
{{/isModel}}
|
||||
{{#isUuid}}
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
if(!cJSON_IsString({{{baseName}}}))
|
||||
{
|
||||
goto end; //uuid
|
||||
}
|
||||
char *{{{baseName}}}JSONData = cJSON_Print({{{baseName}}}JSON);
|
||||
{{{baseName}}} = {{complexType}}_parseFromJSON({{{baseName}}}JSONData);
|
||||
{{/isUuid}}
|
||||
{{#isEmail}}
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
if(!cJSON_IsString({{{baseName}}}))
|
||||
{
|
||||
goto end; //email
|
||||
}
|
||||
{{/isEmail}}
|
||||
{{#isFreeFormObject}}
|
||||
object_t *{{baseName}}_local_object = NULL;
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
{{{baseName}}}_local_object = object_parseFromJSON({{{baseName}}}); //object
|
||||
{{/isFreeFormObject}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#isListContainer}}
|
||||
{{#isPrimitiveType}}
|
||||
cJSON *{{{name}}};
|
||||
cJSON *{{{baseName}}}JSON = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{{baseName}}}");
|
||||
if(!cJSON_IsArray({{{baseName}}}JSON)) {
|
||||
list_t *{{{name}}}List;
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
cJSON *{{{name}}}_local;
|
||||
if(!cJSON_IsArray({{{baseName}}})) {
|
||||
goto end;//primitive container
|
||||
}
|
||||
list_t *{{{name}}}List = list_create();
|
||||
{{{name}}}List = list_create();
|
||||
|
||||
cJSON_ArrayForEach({{{name}}}, {{{baseName}}}JSON)
|
||||
cJSON_ArrayForEach({{{name}}}_local, {{{baseName}}})
|
||||
{
|
||||
{{#items}}
|
||||
{{#isString}}
|
||||
if(!cJSON_IsString({{{baseName}}}))
|
||||
if(!cJSON_IsString({{{baseName}}}_local))
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
list_addElement({{{baseName}}}List , strdup({{{baseName}}}->valuestring));
|
||||
list_addElement({{{baseName}}}List , strdup({{{baseName}}}_local->valuestring));
|
||||
{{/isString}}
|
||||
{{^isString}}
|
||||
if(!cJSON_IsNumber({{{baseName}}}))
|
||||
if(!cJSON_IsNumber({{{baseName}}}_local))
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
list_addElement({{{baseName}}}List , &{{{baseName}}}->valuedouble);
|
||||
list_addElement({{{baseName}}}List , &{{{baseName}}}_local->valuedouble);
|
||||
{{/isString}}
|
||||
{{/items}}
|
||||
|
||||
}
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
cJSON *{{{baseName}}};
|
||||
cJSON *{{{baseName}}}JSON = cJSON_GetObjectItemCaseSensitive({{classname}}JSON,"{{{baseName}}}");
|
||||
if(!cJSON_IsArray({{{baseName}}}JSON)){
|
||||
list_t *{{{baseName}}}List;
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
cJSON *{{{baseName}}}_local_nonprimitive;
|
||||
if(!cJSON_IsArray({{{baseName}}})){
|
||||
goto end; //nonprimitive container
|
||||
}
|
||||
|
||||
list_t *{{{baseName}}}List = list_create();
|
||||
{{{baseName}}}List = list_create();
|
||||
|
||||
cJSON_ArrayForEach({{{baseName}}},{{{baseName}}}JSON )
|
||||
cJSON_ArrayForEach({{{baseName}}}_local_nonprimitive,{{{baseName}}} )
|
||||
{
|
||||
if(!cJSON_IsObject({{{baseName}}})){
|
||||
if(!cJSON_IsObject({{{baseName}}}_local_nonprimitive)){
|
||||
goto end;
|
||||
}
|
||||
char *JSONData = cJSON_Print({{{baseName}}});
|
||||
{{complexType}}_t *{{{baseName}}}Item = {{complexType}}_parseFromJSON(JSONData);
|
||||
{{#isEnum}}{{#items}}{{datatypeWithEnum}}_e {{/items}}{{/isEnum}}{{^isEnum}}{{complexType}}_t *{{/isEnum}}{{{baseName}}}Item = {{complexType}}_parseFromJSON({{{baseName}}}_local_nonprimitive);
|
||||
|
||||
list_addElement({{{baseName}}}List, {{{baseName}}}Item);
|
||||
free(JSONData);
|
||||
list_addElement({{{baseName}}}List, {{#isEnum}}{{#items}}(void *){{/items}}{{/isEnum}}{{{baseName}}}Item);
|
||||
}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isListContainer}}
|
||||
{{#isMapContainer}}
|
||||
// map
|
||||
cJSON *{{{complexType}}};
|
||||
cJSON *{{{baseName}}}JSON = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{{baseName}}}");
|
||||
if(!cJSON_IsObject({{{baseName}}}JSON)) {
|
||||
list_t *{{{complexType}}}List;
|
||||
{{^required}}if ({{{baseName}}}) { {{/required}}
|
||||
cJSON *{{{complexType}}}_local_map;
|
||||
if(!cJSON_IsObject({{{baseName}}})) {
|
||||
goto end;//primitive map container
|
||||
}
|
||||
list_t *{{{complexType}}}List = list_create();
|
||||
{{{complexType}}}List = list_create();
|
||||
keyValuePair_t *localMapKeyPair;
|
||||
cJSON_ArrayForEach({{{complexType}}}, {{{baseName}}}JSON)
|
||||
cJSON_ArrayForEach({{{complexType}}}_local_map, {{{baseName}}})
|
||||
{
|
||||
{{#items}}
|
||||
{{#isString}}
|
||||
if(!cJSON_IsString({{{complexType}}}))
|
||||
if(!cJSON_IsString({{{complexType}}}_local_map))
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
localMapKeyPair = keyValuePair_create(strdup({{{complexType}}}->string),strdup({{{complexType}}}->valuestring))
|
||||
localMapKeyPair = keyValuePair_create(strdup({{{complexType}}}_local_map->string),strdup({{{complexType}}}_local_map->valuestring))
|
||||
list_addElement({{{complexType}}}List , localMapKeyPair);
|
||||
{{/isString}}
|
||||
{{^isString}}
|
||||
if(!cJSON_IsNumber({{{complexType}}}))
|
||||
if(!cJSON_IsNumber({{{complexType}}}_local_map))
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
localMapKeyPair = keyValuePair_create(strdup({{{complexType}}}->string),&{{{complexType}}}->valuedouble );
|
||||
localMapKeyPair = keyValuePair_create(strdup({{{complexType}}}_local_map->string),&{{{complexType}}}_local_map->valuedouble );
|
||||
list_addElement({{{complexType}}}List , localMapKeyPair);
|
||||
{{/isString}}
|
||||
{{/items}}
|
||||
|
||||
}
|
||||
{{/isMapContainer}}
|
||||
{{/isContainer}}
|
||||
{{^required}}
|
||||
}
|
||||
{{/required}}
|
||||
|
||||
{{/vars}}
|
||||
|
||||
{{classname}} = {{classname}}_create (
|
||||
{{classname}}_local_var = {{classname}}_create (
|
||||
{{#vars}}
|
||||
{{^isContainer}}
|
||||
{{^isPrimitiveType}}
|
||||
{{{baseName}}}{{#hasMore}},{{/hasMore}}
|
||||
{{#isModel}}
|
||||
{{#isEnum}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}{{{baseName}}}_local_nonprim_enum{{^required}} : -1{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}{{{baseName}}}_local_nonprim{{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isEnum}}
|
||||
{{/isModel}}
|
||||
{{#isUuid}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}strdup({{{baseName}}}->valuestring){{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isUuid}}
|
||||
{{#isEmail}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}strdup({{{baseName}}}->valuestring){{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isEmail}}
|
||||
{{#isFreeFormObject}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}{{{baseName}}}_local_object{{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isFreeFormObject}}
|
||||
{{/isPrimitiveType}}
|
||||
{{#isPrimitiveType}}
|
||||
{{#isNumeric}}
|
||||
{{{baseName}}}->valuedouble{{#hasMore}},{{/hasMore}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}{{{baseName}}}->valuedouble{{^required}} : 0{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isNumeric}}
|
||||
{{#isBoolean}}
|
||||
{{{baseName}}}->valueint{{#hasMore}},{{/hasMore}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}{{{baseName}}}->valueint{{^required}} : 0{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isBoolean}}
|
||||
{{#isEnum}}
|
||||
{{#isString}}
|
||||
{{baseName}}Variable{{#hasMore}},{{/hasMore}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}{{baseName}}Variable{{^required}} : -1{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{#isString}}
|
||||
strdup({{{baseName}}}->valuestring){{#hasMore}},{{/hasMore}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}strdup({{{baseName}}}->valuestring){{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
{{#isByteArray}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}{{{baseName}}}->valueint{{^required}} : 0{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isByteArray}}
|
||||
{{#isBinary}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}decoded_str_{{{baseName}}}{{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isBinary}}
|
||||
{{#isDate}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}strdup({{{baseName}}}->valuestring){{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isDate}}
|
||||
{{#isDateTime}}
|
||||
strdup({{{baseName}}}->valuestring){{#hasMore}},{{/hasMore}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}strdup({{{baseName}}}->valuestring){{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isDateTime}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#isListContainer}}
|
||||
{{#isPrimitiveType}}
|
||||
{{{name}}}List{{#hasMore}},{{/hasMore}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}{{{name}}}List{{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
{{{baseName}}}List{{#hasMore}},{{/hasMore}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}{{{baseName}}}List{{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isListContainer}}
|
||||
{{#isMapContainer}}
|
||||
{{{complexType}}}List{{#hasMore}},{{/hasMore}}
|
||||
{{^required}}{{{baseName}}} ? {{/required}}{{{complexType}}}List{{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isMapContainer}}
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
);
|
||||
{{#vars}}
|
||||
{{^isContainer}}
|
||||
{{^isPrimitiveType}}
|
||||
free({{{baseName}}}JSONData);
|
||||
{{/isPrimitiveType}}
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
cJSON_Delete({{classname}}JSON);
|
||||
return {{classname}};
|
||||
|
||||
return {{classname}}_local_var;
|
||||
end:
|
||||
cJSON_Delete({{classname}}JSON);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
{{/isEnum}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
@@ -15,126 +15,199 @@
|
||||
#include "{{{.}}}.h"
|
||||
{{/imports}}
|
||||
|
||||
{{#vars}}
|
||||
{{#isBoolean}}
|
||||
typedef int bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
{{/isBoolean}}
|
||||
{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
|
||||
{{#allowableValues}}
|
||||
typedef enum { {{#enumVars}} {{{value}}}{{^-last}},{{/-last}}{{/enumVars}} } {{baseName}}_e;
|
||||
typedef enum { {{#enumVars}} {{{value}}}{{#first}} = 0{{/first}}{{^-last}},{{/-last}}{{/enumVars}} } {{classname}}_e;
|
||||
{{/allowableValues}}
|
||||
{{/isEnum}}
|
||||
{{/vars}}
|
||||
|
||||
char* {{classname}}_ToString({{classname}}_e {{classname}});
|
||||
|
||||
{{classname}}_e {{classname}}_FromString(char* {{classname}});
|
||||
|
||||
cJSON *{{classname}}_convertToJSON({{classname}}_e {{classname}});
|
||||
|
||||
{{classname}}_e {{classname}}_parseFromJSON(cJSON *{{classname}}JSON);
|
||||
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
char* {{baseName}}{{classname}}_ToString({{baseName}}_e {{baseName}});
|
||||
{{^isContainer}}
|
||||
{{^isModel}}
|
||||
{{#isEnum}}
|
||||
{{#allowableValues}}
|
||||
typedef enum { {{#enumVars}} {{{value}}}{{#first}} = 0{{/first}}{{^-last}},{{/-last}}{{/enumVars}} } {{baseName}}_e;
|
||||
{{/allowableValues}}
|
||||
|
||||
{{baseName}}_e {{baseName}}{{classname}}_FromString(char* {{baseName}});
|
||||
{{/isEnum}}
|
||||
char* {{baseName}}_ToString({{baseName}}_e {{baseName}});
|
||||
|
||||
{{baseName}}_e {{baseName}}_FromString(char* {{baseName}});
|
||||
{{/isEnum}}
|
||||
{{/isModel}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#items}}
|
||||
{{^isModel}}
|
||||
{{#isEnum}}
|
||||
{{#allowableValues}}
|
||||
typedef enum { {{#enumVars}} {{{value}}}{{^-last}},{{/-last}}{{/enumVars}} } {{baseName}}_e;
|
||||
{{/allowableValues}}
|
||||
|
||||
char* {{baseName}}_ToString({{baseName}}_e {{baseName}});
|
||||
|
||||
{{baseName}}_e {{baseName}}_FromString(char* {{baseName}});
|
||||
{{/isEnum}}
|
||||
{{/isModel}}
|
||||
{{/items}}
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
|
||||
|
||||
typedef struct {{classname}}_t {
|
||||
{{#vars}}
|
||||
{{^isContainer}}
|
||||
{{^isPrimitiveType}}
|
||||
{{datatype}}_t *{{baseName}}; //nonprimitive
|
||||
{{/isPrimitiveType}}
|
||||
{{#isPrimitiveType}}
|
||||
{{#isNumeric}}
|
||||
{{datatype}} {{baseName}}; //numeric
|
||||
{{/isNumeric}}
|
||||
{{#isBoolean}}
|
||||
bool {{baseName}}; //boolean
|
||||
{{/isBoolean}}
|
||||
{{#isEnum}}
|
||||
{{#isString}}
|
||||
{{baseName}}_e {{baseName}}; //enum string
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{#isString}}
|
||||
{{datatype}} *{{baseName}}; //no enum string
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
{{#isDateTime}}
|
||||
{{datatype}} *{{baseName}}; //date time string
|
||||
{{/isDateTime}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#isListContainer}}
|
||||
{{#isPrimitiveType}}
|
||||
{{datatype}}_t *{{baseName}}; //primitive container
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
{{datatype}}_t *{{baseName}}; //nonprimitive container
|
||||
{{/isPrimitiveType}}
|
||||
{{/isListContainer}}
|
||||
{{#isMapContainer}}
|
||||
{{datatype}} {{baseName}};
|
||||
// TODO map/hash not supported at the moment
|
||||
{{/isMapContainer}}
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
{{#vars}}
|
||||
{{^isContainer}}
|
||||
{{^isPrimitiveType}}
|
||||
{{#isModel}}
|
||||
{{#isEnum}}
|
||||
{{datatype}}_e {{baseName}}; //enum model
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{datatype}}_t *{{baseName}}; //model
|
||||
{{/isEnum}}
|
||||
{{/isModel}}
|
||||
{{#isUuid}}
|
||||
{{datatype}} *{{baseName}}; // uuid
|
||||
{{/isUuid}}
|
||||
{{#isEmail}}
|
||||
{{datatype}} *{{baseName}}; // email
|
||||
{{/isEmail}}
|
||||
{{#isFreeFormObject}}
|
||||
{{datatype}}_t *{{baseName}}; //object
|
||||
{{/isFreeFormObject}}
|
||||
{{/isPrimitiveType}}
|
||||
{{#isPrimitiveType}}
|
||||
{{#isNumeric}}
|
||||
{{datatype}} {{baseName}}; //numeric
|
||||
{{/isNumeric}}
|
||||
{{#isBoolean}}
|
||||
{{datatype}} {{baseName}}; //boolean
|
||||
{{/isBoolean}}
|
||||
{{#isEnum}}
|
||||
{{#isString}}
|
||||
{{baseName}}_e {{baseName}}; //enum
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{#isString}}
|
||||
{{datatype}} *{{baseName}}; // string
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
{{#isByteArray}}
|
||||
{{datatype}} {{baseName}}; //Byte
|
||||
{{/isByteArray}}
|
||||
{{#isBinary}}
|
||||
{{datatype}} {{baseName}}; //binary
|
||||
{{/isBinary}}
|
||||
{{#isDate}}
|
||||
{{datatype}} *{{baseName}}; //date
|
||||
{{/isDate}}
|
||||
{{#isDateTime}}
|
||||
{{datatype}} *{{baseName}}; //date time
|
||||
{{/isDateTime}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#isListContainer}}
|
||||
{{#isPrimitiveType}}
|
||||
{{datatype}}_t *{{baseName}}; //primitive container
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
{{datatype}}_t *{{baseName}}; //nonprimitive container
|
||||
{{/isPrimitiveType}}
|
||||
{{/isListContainer}}
|
||||
{{#isMapContainer}}
|
||||
{{datatype}} {{baseName}}; //map
|
||||
{{/isMapContainer}}
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
|
||||
} {{classname}}_t;
|
||||
|
||||
{{classname}}_t *{{classname}}_create(
|
||||
{{#vars}}
|
||||
{{^isContainer}}
|
||||
{{^isPrimitiveType}}
|
||||
{{datatype}}_t *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isPrimitiveType}}
|
||||
{{#isPrimitiveType}}
|
||||
{{#isNumeric}}
|
||||
{{datatype}} {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isNumeric}}
|
||||
{{#isBoolean}}
|
||||
bool {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isBoolean}}
|
||||
{{#isEnum}}
|
||||
{{#isString}}
|
||||
{{baseName}}_e {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{#isString}}
|
||||
{{datatype}} *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
{{#isDateTime}}
|
||||
{{datatype}} *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isDateTime}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#isListContainer}}
|
||||
{{#isPrimitiveType}}
|
||||
{{datatype}}_t *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
{{datatype}}_t *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isListContainer}}
|
||||
{{#isMapContainer}}
|
||||
{{datatype}} {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
// TODO map/hash not supported at the moment
|
||||
{{/isMapContainer}}
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
{{#vars}}
|
||||
{{^isContainer}}
|
||||
{{^isPrimitiveType}}
|
||||
{{#isModel}}
|
||||
{{#isEnum}}
|
||||
{{datatype}}_e {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{datatype}}_t *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isEnum}}
|
||||
{{/isModel}}
|
||||
{{#isUuid}}
|
||||
{{datatype}} *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isUuid}}
|
||||
{{#isEmail}}
|
||||
{{datatype}} *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isEmail}}
|
||||
{{#isFreeFormObject}}
|
||||
{{datatype}}_t *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isFreeFormObject}}
|
||||
{{/isPrimitiveType}}
|
||||
{{#isPrimitiveType}}
|
||||
{{#isNumeric}}
|
||||
{{datatype}} {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isNumeric}}
|
||||
{{#isBoolean}}
|
||||
{{datatype}} {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isBoolean}}
|
||||
{{#isEnum}}
|
||||
{{#isString}}
|
||||
{{baseName}}_e {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{#isString}}
|
||||
{{datatype}} *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isString}}
|
||||
{{/isEnum}}
|
||||
{{#isByteArray}}
|
||||
{{datatype}} {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isByteArray}}
|
||||
{{#isBinary}}
|
||||
{{datatype}} {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isBinary}}
|
||||
{{#isDate}}
|
||||
{{datatype}} *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isDate}}
|
||||
{{#isDateTime}}
|
||||
{{datatype}} *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isDateTime}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#isListContainer}}
|
||||
{{#isPrimitiveType}}
|
||||
{{datatype}}_t *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
{{datatype}}_t *{{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isListContainer}}
|
||||
{{#isMapContainer}}
|
||||
{{datatype}} {{baseName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/isMapContainer}}
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
);
|
||||
|
||||
void {{classname}}_free({{classname}}_t *{{classname}});
|
||||
|
||||
{{classname}}_t *{{classname}}_parseFromJSON(char *jsonString);
|
||||
{{classname}}_t *{{classname}}_parseFromJSON(cJSON *{{classname}}JSON);
|
||||
|
||||
cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}});
|
||||
|
||||
{{/isEnum}}
|
||||
#endif /* _{{classname}}_H_ */
|
||||
{{/model}}{{/models}}
|
||||
|
||||
@@ -21,6 +21,3 @@
|
||||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
||||
#
|
||||
|
||||
CMakeLists.txt
|
||||
|
||||
@@ -1 +1 @@
|
||||
3.3.0-SNAPSHOT
|
||||
4.0.0-SNAPSHOT
|
||||
@@ -1,29 +1,16 @@
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
project (CGenerator)
|
||||
|
||||
file(GLOB SRC_C src/*.c)
|
||||
file(GLOB UNIT_TESTS_C unit-tests/*.c)
|
||||
#file(GLOB UNIT_TEST_C unit-test/*.c)
|
||||
file(GLOB MODEL_C model/*.c)
|
||||
file(GLOB API_C api/*.c)
|
||||
file(GLOB EXTERNAL_SRC_C external/src/*.c)
|
||||
set(ALL_SRC_LIST ${SRC_C} ${UNIT_TESTS_C} ${UNIT_TEST_C} ${MODEL_C} ${API_C})
|
||||
cmake_policy(SET CMP0063 NEW)
|
||||
|
||||
set(CMAKE_C_VISIBILITY_PRESET default)
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET default)
|
||||
set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
|
||||
include(CTest)
|
||||
include_directories(include)
|
||||
include_directories(external/include)
|
||||
include_directories(model)
|
||||
include_directories(api)
|
||||
set(pkgName "openapi_petstore")
|
||||
|
||||
find_program(VALGRIND valgrind)
|
||||
if(VALGRIND)
|
||||
set(CMAKE_MEMORYCHECK_COMMAND valgrind)
|
||||
set(CMAKE_MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --track-origins=yes --read-var-info=yes --show-leak-kinds=all --error-exitcode=1")
|
||||
set(VALGRIND_LIST "")
|
||||
endif()
|
||||
|
||||
find_package(CURL 7.61.1 REQUIRED)
|
||||
find_package(CURL 7.58.0 REQUIRED)
|
||||
if(CURL_FOUND)
|
||||
include_directories(${CURL_INCLUDE_DIR})
|
||||
set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${CURL_LIBRARIES} )
|
||||
@@ -31,64 +18,68 @@ else(CURL_FOUND)
|
||||
message(FATAL_ERROR "Could not find the CURL library and development files.")
|
||||
endif()
|
||||
|
||||
foreach(ELEMENT ${UNIT_TESTS_C})
|
||||
get_filename_component(ELEMENT_NAME ${ELEMENT} NAME_WE)
|
||||
string(REGEX REPLACE "\\.c$" "" ELEMENT_REPLACED ${ELEMENT_NAME})
|
||||
set(EXE_NAME unit-${ELEMENT_REPLACED})
|
||||
add_executable(${EXE_NAME} ${ELEMENT} ${SRC_C} ${MODEL_C} ${API_C} ${EXTERNAL_SRC_C})
|
||||
target_link_libraries(${EXE_NAME} ${CURL_LIBRARIES})
|
||||
add_test(NAME ${EXE_NAME} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME})
|
||||
set(SRCS
|
||||
src/list.c
|
||||
src/apiKey.c
|
||||
src/apiClient.c
|
||||
external/cJSON.c
|
||||
model/api_response.c
|
||||
model/category.c
|
||||
model/order.c
|
||||
model/pet.c
|
||||
model/tag.c
|
||||
model/user.c
|
||||
api/PetAPI.c
|
||||
api/StoreAPI.c
|
||||
api/UserAPI.c
|
||||
|
||||
if(VALGRIND)
|
||||
set(memcheck_command "${CMAKE_MEMORYCHECK_COMMAND} ${CMAKE_MEMORYCHECK_COMMAND_OPTIONS}")
|
||||
separate_arguments(memcheck_command)
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME valgrind-test-${ELEMENT_REPLACED}
|
||||
COMMAND ${memcheck_command} ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
set(HDRS
|
||||
include/apiClient.h
|
||||
include/list.h
|
||||
include/keyValuePair.h
|
||||
external/cJSON.h
|
||||
model/api_response.h
|
||||
model/category.h
|
||||
model/order.h
|
||||
model/pet.h
|
||||
model/tag.h
|
||||
model/user.h
|
||||
api/PetAPI.h
|
||||
api/StoreAPI.h
|
||||
api/UserAPI.h
|
||||
|
||||
# comment out below as auto-generated test file is not supported at the moment
|
||||
#foreach(ELEMENT ${UNIT_TEST_C})
|
||||
#get_filename_component(ELEMENT_NAME ${ELEMENT} NAME_WE)
|
||||
#string(REGEX REPLACE "\\.c$" "" ELEMENT_REPLACED ${ELEMENT_NAME})
|
||||
#set(EXE_NAME unit-${ELEMENT_REPLACED})
|
||||
#add_executable(${EXE_NAME} ${ELEMENT} ${SRC_C} ${MODEL_C} ${API_C} ${EXTERNAL_SRC_C})
|
||||
#target_link_libraries(${EXE_NAME} ${CURL_LIBRARIES})
|
||||
#add_test(NAME ${EXE_NAME} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME})
|
||||
#
|
||||
#if(VALGRIND)
|
||||
#set(memcheck_command "${CMAKE_MEMORYCHECK_COMMAND} ${CMAKE_MEMORYCHECK_COMMAND_OPTIONS}")
|
||||
#separate_arguments(memcheck_command)
|
||||
#
|
||||
#add_test(
|
||||
#NAME valgrind-test-${ELEMENT_REPLACED}
|
||||
#COMMAND ${memcheck_command} ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}
|
||||
#WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
#)
|
||||
#endif()
|
||||
#endforeach()
|
||||
)
|
||||
|
||||
#For common coding standard (code beautifier/pretty printing)
|
||||
find_program(UNCRUSTIFY uncrustify)
|
||||
if(UNCRUSTIFY)
|
||||
add_custom_target(
|
||||
uncrustify
|
||||
)
|
||||
add_library(${pkgName} SHARED ${SRCS} ${HDRS})
|
||||
target_link_libraries(${pkgName} ${CURL_LIBRARIES} )
|
||||
install(TARGETS ${pkgName} DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
|
||||
foreach(ELEMENT ${ALL_SRC_LIST})
|
||||
string(REGEX REPLACE "/" "_" ELEMENT_NAME ${ELEMENT})
|
||||
set(DEP_NAME "uncrustify-${ELEMENT_NAME}")
|
||||
add_custom_target(
|
||||
${DEP_NAME}
|
||||
uncrustify -c uncrustify-rules.cfg --no-backup ${ELEMENT}
|
||||
DEPENDS ${ELEMENT}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
VERBATIM
|
||||
)
|
||||
add_dependencies(uncrustify ${DEP_NAME})
|
||||
endforeach()
|
||||
endif()
|
||||
set(SRCS "")
|
||||
set(HDRS "")
|
||||
|
||||
# This section shows how to use the above compiled libary to compile the source files
|
||||
# set source files
|
||||
set(SRCS
|
||||
unit-tests/manual-PetAPI.c
|
||||
unit-tests/manual-StoreAPI.c
|
||||
unit-tests/manual-UserAPI.c
|
||||
unit-tests/manual-order.c
|
||||
unit-tests/manual-user.c)
|
||||
|
||||
#set header files
|
||||
set(HDRS
|
||||
)
|
||||
|
||||
# loop over all files in SRCS variable
|
||||
foreach(SOURCE_FILE ${SRCS})
|
||||
# Get only the file name from the file as add_executable doesnot support executable with slash("/")
|
||||
get_filename_component(FILE_NAME_ONLY ${SOURCE_FILE} NAME_WE)
|
||||
# Remove .c from the file name and set it as executable name
|
||||
string( REPLACE ".c" "" EXECUTABLE_FILE ${FILE_NAME_ONLY})
|
||||
# Add executable for every source file in SRCS
|
||||
add_executable(unit-${EXECUTABLE_FILE} ${SOURCE_FILE})
|
||||
# Link above created libary to executable and dependent libary curl
|
||||
target_link_libraries(unit-${EXECUTABLE_FILE} ${CURL_LIBRARIES} ${pkgName} )
|
||||
endforeach(SOURCE_FILE ${SRCS})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# C API client for
|
||||
# C API client for openapi_petstore
|
||||
|
||||
## Overview
|
||||
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI spec](https://openapis.org) from a remote server, you can easily generate an API client.
|
||||
@@ -8,20 +8,21 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
|
||||
- Build package: org.openapitools.codegen.languages.CLibcurlClientCodegen
|
||||
|
||||
## Installation
|
||||
You'll need the `curl 7.61.1` package in order to build the API. To have code formatted nicely you also need to have uncrustify version 0.67.
|
||||
You'll need the `curl 7.58.0` package in order to build the API. To have code formatted nicely you also need to have uncrustify version 0.67.
|
||||
|
||||
### Prerequisites
|
||||
Install the `curl 7.61.1` package with the following command on Linux.
|
||||
# Prerequisites
|
||||
|
||||
## Install the `curl 7.58.0` package with the following command on Linux.
|
||||
```bash
|
||||
sudo apt remove curl
|
||||
wget http://curl.haxx.se/download/curl-7.61.1.tar.gz
|
||||
tar -xvf curl-7.61.1.tar.gz
|
||||
cd curl-7.61.1/
|
||||
wget http://curl.haxx.se/download/curl-7.58.0.tar.gz
|
||||
tar -xvf curl-7.58.0.tar.gz
|
||||
cd curl-7.58.0/
|
||||
./configure
|
||||
make
|
||||
sudo make install
|
||||
```
|
||||
Install the `uncrustify 0.67` package with the following command on Linux.
|
||||
## Install the `uncrustify 0.67` package with the following command on Linux.
|
||||
```bash
|
||||
git clone https://github.com/uncrustify/uncrustify.git
|
||||
cd uncrustify
|
||||
@@ -32,6 +33,30 @@ make
|
||||
sudo make install
|
||||
```
|
||||
|
||||
## Compile the sample:
|
||||
This will compile the generated code and create a library in build folder which has to be linked to the codes where API will be used.
|
||||
```bash
|
||||
mkdir build
|
||||
cd build
|
||||
// To install library to specific location use following command
|
||||
cmake -DCMAKE_INSTALL_PREFIX=/pathtolocaiton ..
|
||||
// for normal install use following command
|
||||
cmake ..
|
||||
make
|
||||
sudo make install
|
||||
```
|
||||
## How to use compiled library
|
||||
Considering the test/source code which uses the API is written in main.c(respective api include is written and all objects necessary are defined and created)
|
||||
|
||||
To compile main.c(considering the file is present in build folder) use following command
|
||||
-L - locaiton of the library(not required if cmake with normal installation is performed)
|
||||
-l library name
|
||||
```bash
|
||||
gcc main.c -L. -lpetstore -o main
|
||||
```
|
||||
once compile, you can run it with ``` ./main ```
|
||||
|
||||
Note: You dont need to specify includes for models and include folder seperately as they are path linked. You just have to import the api.h file in your code, the include linking will work.
|
||||
|
||||
## Author
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "apiClient.h"
|
||||
#include "cJSON.h"
|
||||
#include "keyValuePair.h"
|
||||
#include "api_response.h"
|
||||
#include "pet.h"
|
||||
#include "PetAPI.h"
|
||||
|
||||
|
||||
#define MAX_BUFFER_LENGTH 4096
|
||||
#define intToStr(dst, src) \
|
||||
@@ -16,7 +13,7 @@
|
||||
|
||||
// Add a new pet to the store
|
||||
//
|
||||
void PetAPI_addPet(apiClient_t *apiClient, pet_t *pet) {
|
||||
void PetAPI_addPet(apiClient_t *apiClient, pet_t *body) {
|
||||
list_t *localVarQueryParameters = NULL;
|
||||
list_t *localVarHeaderParameters = NULL;
|
||||
list_t *localVarFormParameters = NULL;
|
||||
@@ -30,13 +27,15 @@ void PetAPI_addPet(apiClient_t *apiClient, pet_t *pet) {
|
||||
snprintf(localVarPath, sizeOfPath, "/pet");
|
||||
|
||||
|
||||
|
||||
|
||||
// Body Param
|
||||
cJSON *localVarSingleItemJSON_pet;
|
||||
if(pet != NULL) {
|
||||
cJSON *localVarSingleItemJSON_body;
|
||||
if(body != NULL) {
|
||||
// string
|
||||
localVarSingleItemJSON_pet = pet_convertToJSON(pet);
|
||||
localVarSingleItemJSON_body = pet_convertToJSON(body);
|
||||
localVarBodyParameters =
|
||||
cJSON_Print(localVarSingleItemJSON_pet);
|
||||
cJSON_Print(localVarSingleItemJSON_body);
|
||||
}
|
||||
list_addElement(localVarContentType, "application/json"); // consumes
|
||||
list_addElement(localVarContentType, "application/xml"); // consumes
|
||||
@@ -54,14 +53,17 @@ void PetAPI_addPet(apiClient_t *apiClient, pet_t *pet) {
|
||||
printf("%s\n", "Invalid input");
|
||||
}
|
||||
// No return type
|
||||
end: apiClient_free(apiClient);
|
||||
end:
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
list_free(localVarContentType);
|
||||
free(localVarPath);
|
||||
cJSON_Delete(localVarSingleItemJSON_pet);
|
||||
cJSON_Delete(localVarSingleItemJSON_body);
|
||||
free(localVarBodyParameters);
|
||||
}
|
||||
|
||||
@@ -83,13 +85,12 @@ void PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key) {
|
||||
|
||||
// Path Params
|
||||
long sizeOfPathParams_petId = sizeof(petId) + 3 + strlen("{ petId }");
|
||||
|
||||
if(petId == 0) {
|
||||
goto end;
|
||||
}
|
||||
char *localVarToReplace_petId = malloc(sizeOfPathParams_petId);
|
||||
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "%s%s%s", "{",
|
||||
"petId", "}");
|
||||
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}",
|
||||
"petId");
|
||||
|
||||
char localVarBuff_petId[256];
|
||||
intToStr(localVarBuff_petId, petId);
|
||||
@@ -98,18 +99,21 @@ void PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key) {
|
||||
localVarBuff_petId);
|
||||
|
||||
|
||||
|
||||
|
||||
// header parameters
|
||||
char *keyHeader_api_key;
|
||||
char *valueHeader_api_key;
|
||||
keyValuePair_t *keyPairHeader_api_key = 0;
|
||||
if(api_key) {
|
||||
keyHeader_api_key = strdup("api_key");
|
||||
valueHeader_api_key = strdup(api_key);
|
||||
valueHeader_api_key = strdup((api_key));
|
||||
keyPairHeader_api_key = keyValuePair_create(keyHeader_api_key,
|
||||
valueHeader_api_key);
|
||||
list_addElement(localVarHeaderParameters,
|
||||
keyPairHeader_api_key);
|
||||
}
|
||||
|
||||
apiClient_invoke(apiClient,
|
||||
localVarPath,
|
||||
localVarQueryParameters,
|
||||
@@ -124,7 +128,10 @@ void PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key) {
|
||||
printf("%s\n", "Invalid pet value");
|
||||
}
|
||||
// No return type
|
||||
end: apiClient_free(apiClient);
|
||||
end:
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
list_free(localVarHeaderParameters);
|
||||
|
||||
@@ -155,10 +162,11 @@ list_t *PetAPI_findPetsByStatus(apiClient_t *apiClient, list_t *status) {
|
||||
snprintf(localVarPath, sizeOfPath, "/pet/findByStatus");
|
||||
|
||||
|
||||
|
||||
|
||||
// query parameters
|
||||
if(status) {
|
||||
// listContainer
|
||||
localVarQueryParameters = status;
|
||||
list_addElement(localVarQueryParameters, status);
|
||||
}
|
||||
list_addElement(localVarHeaderType, "application/xml"); // produces
|
||||
list_addElement(localVarHeaderType, "application/json"); // produces
|
||||
@@ -196,7 +204,9 @@ list_t *PetAPI_findPetsByStatus(apiClient_t *apiClient, list_t *status) {
|
||||
cJSON_Delete(PetAPIlocalVarJSON);
|
||||
cJSON_Delete(VarJSON);
|
||||
// return type
|
||||
apiClient_free(apiClient);
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
list_free(localVarQueryParameters);
|
||||
|
||||
|
||||
@@ -226,10 +236,11 @@ list_t *PetAPI_findPetsByTags(apiClient_t *apiClient, list_t *tags) {
|
||||
snprintf(localVarPath, sizeOfPath, "/pet/findByTags");
|
||||
|
||||
|
||||
|
||||
|
||||
// query parameters
|
||||
if(tags) {
|
||||
// listContainer
|
||||
localVarQueryParameters = tags;
|
||||
list_addElement(localVarQueryParameters, tags);
|
||||
}
|
||||
list_addElement(localVarHeaderType, "application/xml"); // produces
|
||||
list_addElement(localVarHeaderType, "application/json"); // produces
|
||||
@@ -267,7 +278,9 @@ list_t *PetAPI_findPetsByTags(apiClient_t *apiClient, list_t *tags) {
|
||||
cJSON_Delete(PetAPIlocalVarJSON);
|
||||
cJSON_Delete(VarJSON);
|
||||
// return type
|
||||
apiClient_free(apiClient);
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
list_free(localVarQueryParameters);
|
||||
|
||||
|
||||
@@ -299,13 +312,12 @@ pet_t *PetAPI_getPetById(apiClient_t *apiClient, long petId) {
|
||||
|
||||
// Path Params
|
||||
long sizeOfPathParams_petId = sizeof(petId) + 3 + strlen("{ petId }");
|
||||
|
||||
if(petId == 0) {
|
||||
goto end;
|
||||
}
|
||||
char *localVarToReplace_petId = malloc(sizeOfPathParams_petId);
|
||||
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "%s%s%s", "{",
|
||||
"petId", "}");
|
||||
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}",
|
||||
"petId");
|
||||
|
||||
char localVarBuff_petId[256];
|
||||
intToStr(localVarBuff_petId, petId);
|
||||
@@ -313,6 +325,8 @@ pet_t *PetAPI_getPetById(apiClient_t *apiClient, long petId) {
|
||||
localVarPath = strReplace(localVarPath, localVarToReplace_petId,
|
||||
localVarBuff_petId);
|
||||
|
||||
|
||||
|
||||
list_addElement(localVarHeaderType, "application/xml"); // produces
|
||||
list_addElement(localVarHeaderType, "application/json"); // produces
|
||||
apiClient_invoke(apiClient,
|
||||
@@ -335,13 +349,17 @@ pet_t *PetAPI_getPetById(apiClient_t *apiClient, long petId) {
|
||||
printf("%s\n", "Pet not found");
|
||||
}
|
||||
// nonprimitive not container
|
||||
pet_t *elementToReturn = pet_parseFromJSON(apiClient->dataReceived);
|
||||
cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
|
||||
pet_t *elementToReturn = pet_parseFromJSON(PetAPIlocalVarJSON);
|
||||
cJSON_Delete(PetAPIlocalVarJSON);
|
||||
if(elementToReturn == NULL) {
|
||||
// return 0;
|
||||
}
|
||||
|
||||
// return type
|
||||
apiClient_free(apiClient);
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -356,7 +374,7 @@ end:
|
||||
|
||||
// Update an existing pet
|
||||
//
|
||||
void PetAPI_updatePet(apiClient_t *apiClient, pet_t *pet) {
|
||||
void PetAPI_updatePet(apiClient_t *apiClient, pet_t *body) {
|
||||
list_t *localVarQueryParameters = NULL;
|
||||
list_t *localVarHeaderParameters = NULL;
|
||||
list_t *localVarFormParameters = NULL;
|
||||
@@ -370,13 +388,15 @@ void PetAPI_updatePet(apiClient_t *apiClient, pet_t *pet) {
|
||||
snprintf(localVarPath, sizeOfPath, "/pet");
|
||||
|
||||
|
||||
|
||||
|
||||
// Body Param
|
||||
cJSON *localVarSingleItemJSON_pet;
|
||||
if(pet != NULL) {
|
||||
cJSON *localVarSingleItemJSON_body;
|
||||
if(body != NULL) {
|
||||
// string
|
||||
localVarSingleItemJSON_pet = pet_convertToJSON(pet);
|
||||
localVarSingleItemJSON_body = pet_convertToJSON(body);
|
||||
localVarBodyParameters =
|
||||
cJSON_Print(localVarSingleItemJSON_pet);
|
||||
cJSON_Print(localVarSingleItemJSON_body);
|
||||
}
|
||||
list_addElement(localVarContentType, "application/json"); // consumes
|
||||
list_addElement(localVarContentType, "application/xml"); // consumes
|
||||
@@ -400,14 +420,17 @@ void PetAPI_updatePet(apiClient_t *apiClient, pet_t *pet) {
|
||||
printf("%s\n", "Validation exception");
|
||||
}
|
||||
// No return type
|
||||
end: apiClient_free(apiClient);
|
||||
end:
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
list_free(localVarContentType);
|
||||
free(localVarPath);
|
||||
cJSON_Delete(localVarSingleItemJSON_pet);
|
||||
cJSON_Delete(localVarSingleItemJSON_body);
|
||||
free(localVarBodyParameters);
|
||||
}
|
||||
|
||||
@@ -430,13 +453,12 @@ void PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name,
|
||||
|
||||
// Path Params
|
||||
long sizeOfPathParams_petId = sizeof(petId) + 3 + strlen("{ petId }");
|
||||
|
||||
if(petId == 0) {
|
||||
goto end;
|
||||
}
|
||||
char *localVarToReplace_petId = malloc(sizeOfPathParams_petId);
|
||||
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "%s%s%s", "{",
|
||||
"petId", "}");
|
||||
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}",
|
||||
"petId");
|
||||
|
||||
char localVarBuff_petId[256];
|
||||
intToStr(localVarBuff_petId, petId);
|
||||
@@ -445,28 +467,30 @@ void PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name,
|
||||
localVarBuff_petId);
|
||||
|
||||
|
||||
|
||||
|
||||
// form parameters
|
||||
char *keyForm_name;
|
||||
char *valueForm_name;
|
||||
keyValuePair_t *keyPairForm_name = 0;
|
||||
if(name) {
|
||||
if(name != NULL) {
|
||||
keyForm_name = strdup("name");
|
||||
valueForm_name = strdup(name);
|
||||
valueForm_name = strdup((name));
|
||||
keyPairForm_name = keyValuePair_create(keyForm_name,
|
||||
valueForm_name);
|
||||
list_addElement(localVarFormParameters, keyPairForm_name); // String
|
||||
list_addElement(localVarFormParameters, keyPairForm_name);
|
||||
}
|
||||
|
||||
// form parameters
|
||||
char *keyForm_status;
|
||||
char *valueForm_status;
|
||||
keyValuePair_t *keyPairForm_status = 0;
|
||||
if(status) {
|
||||
if(status != NULL) {
|
||||
keyForm_status = strdup("status");
|
||||
valueForm_status = strdup(status);
|
||||
valueForm_status = strdup((status));
|
||||
keyPairForm_status = keyValuePair_create(keyForm_status,
|
||||
valueForm_status);
|
||||
list_addElement(localVarFormParameters, keyPairForm_status); // String
|
||||
list_addElement(localVarFormParameters, keyPairForm_status);
|
||||
}
|
||||
list_addElement(localVarContentType,
|
||||
"application/x-www-form-urlencoded"); // consumes
|
||||
@@ -484,7 +508,10 @@ void PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name,
|
||||
printf("%s\n", "Invalid input");
|
||||
}
|
||||
// No return type
|
||||
end: apiClient_free(apiClient);
|
||||
end:
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
list_free(localVarFormParameters);
|
||||
@@ -503,7 +530,7 @@ end: apiClient_free(apiClient);
|
||||
// uploads an image
|
||||
//
|
||||
api_response_t *PetAPI_uploadFile(apiClient_t *apiClient, long petId,
|
||||
char *additionalMetadata, FILE *file) {
|
||||
char *additionalMetadata, binary_t *file) {
|
||||
list_t *localVarQueryParameters = NULL;
|
||||
list_t *localVarHeaderParameters = NULL;
|
||||
list_t *localVarFormParameters = list_create();
|
||||
@@ -519,13 +546,12 @@ api_response_t *PetAPI_uploadFile(apiClient_t *apiClient, long petId,
|
||||
|
||||
// Path Params
|
||||
long sizeOfPathParams_petId = sizeof(petId) + 3 + strlen("{ petId }");
|
||||
|
||||
if(petId == 0) {
|
||||
goto end;
|
||||
}
|
||||
char *localVarToReplace_petId = malloc(sizeOfPathParams_petId);
|
||||
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "%s%s%s", "{",
|
||||
"petId", "}");
|
||||
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}",
|
||||
"petId");
|
||||
|
||||
char localVarBuff_petId[256];
|
||||
intToStr(localVarBuff_petId, petId);
|
||||
@@ -534,43 +560,31 @@ api_response_t *PetAPI_uploadFile(apiClient_t *apiClient, long petId,
|
||||
localVarBuff_petId);
|
||||
|
||||
|
||||
|
||||
|
||||
// form parameters
|
||||
char *keyForm_additionalMetadata;
|
||||
char *valueForm_additionalMetadata;
|
||||
keyValuePair_t *keyPairForm_additionalMetadata = 0;
|
||||
if(additionalMetadata) {
|
||||
if(additionalMetadata != NULL) {
|
||||
keyForm_additionalMetadata = strdup("additionalMetadata");
|
||||
valueForm_additionalMetadata = strdup(additionalMetadata);
|
||||
valueForm_additionalMetadata = strdup((additionalMetadata));
|
||||
keyPairForm_additionalMetadata = keyValuePair_create(
|
||||
keyForm_additionalMetadata,
|
||||
valueForm_additionalMetadata);
|
||||
list_addElement(localVarFormParameters,
|
||||
keyPairForm_additionalMetadata); // String
|
||||
keyPairForm_additionalMetadata);
|
||||
}
|
||||
|
||||
// form parameters
|
||||
|
||||
char *keyForm_file;
|
||||
FileStruct *fileVar_file;
|
||||
binary_t *valueForm_file;
|
||||
keyValuePair_t *keyPairForm_file = 0;
|
||||
if(file != NULL) {
|
||||
fseek(file, 0, SEEK_END);
|
||||
long f_size = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
fileVar_file = malloc(sizeof(FileStruct));
|
||||
keyForm_file = strdup("file");
|
||||
fileVar_file->fileData = malloc((f_size) * sizeof(char *));
|
||||
|
||||
fread(fileVar_file->fileData, f_size, 1, file);
|
||||
fileVar_file->fileData[f_size] = '\0';
|
||||
|
||||
fileVar_file->fileSize = f_size;
|
||||
char valueFile_file[sizeof(fileVar_file)];
|
||||
|
||||
memcpy(valueFile_file, &fileVar_file, sizeof(fileVar_file));
|
||||
|
||||
valueForm_file = file;
|
||||
keyPairForm_file = keyValuePair_create(keyForm_file,
|
||||
valueFile_file);
|
||||
&valueForm_file);
|
||||
list_addElement(localVarFormParameters, keyPairForm_file); // file adding
|
||||
}
|
||||
list_addElement(localVarHeaderType, "application/json"); // produces
|
||||
@@ -589,14 +603,18 @@ api_response_t *PetAPI_uploadFile(apiClient_t *apiClient, long petId,
|
||||
printf("%s\n", "successful operation");
|
||||
}
|
||||
// nonprimitive not container
|
||||
cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
|
||||
api_response_t *elementToReturn = api_response_parseFromJSON(
|
||||
apiClient->dataReceived);
|
||||
PetAPIlocalVarJSON);
|
||||
cJSON_Delete(PetAPIlocalVarJSON);
|
||||
if(elementToReturn == NULL) {
|
||||
// return 0;
|
||||
}
|
||||
|
||||
// return type
|
||||
apiClient_free(apiClient);
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
list_free(localVarFormParameters);
|
||||
@@ -608,8 +626,8 @@ api_response_t *PetAPI_uploadFile(apiClient_t *apiClient, long petId,
|
||||
free(valueForm_additionalMetadata);
|
||||
free(keyPairForm_additionalMetadata);
|
||||
free(keyForm_file);
|
||||
free(fileVar_file->fileData);
|
||||
free(fileVar_file);
|
||||
// free(fileVar_file->data);
|
||||
// free(fileVar_file);
|
||||
free(keyPairForm_file);
|
||||
return elementToReturn;
|
||||
end:
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "apiClient.h"
|
||||
#include "cJSON.h"
|
||||
#include "api_response.h"
|
||||
#include "pet.h"
|
||||
#include "../include/apiClient.h"
|
||||
#include "../include/list.h"
|
||||
#include "../external/cJSON.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
#include "../model/api_response.h"
|
||||
#include "../model/pet.h"
|
||||
|
||||
|
||||
// Add a new pet to the store
|
||||
//
|
||||
void PetAPI_addPet(apiClient_t *apiClient, pet_t *pet);
|
||||
|
||||
void PetAPI_addPet(apiClient_t *apiClient, pet_t *body);
|
||||
|
||||
|
||||
// Deletes a pet
|
||||
@@ -17,7 +18,6 @@ void PetAPI_addPet(apiClient_t *apiClient, pet_t *pet);
|
||||
void PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key);
|
||||
|
||||
|
||||
|
||||
// Finds Pets by status
|
||||
//
|
||||
// Multiple status values can be provided with comma separated strings
|
||||
@@ -25,7 +25,6 @@ void PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key);
|
||||
list_t *PetAPI_findPetsByStatus(apiClient_t *apiClient, list_t *status);
|
||||
|
||||
|
||||
|
||||
// Finds Pets by tags
|
||||
//
|
||||
// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
@@ -33,7 +32,6 @@ list_t *PetAPI_findPetsByStatus(apiClient_t *apiClient, list_t *status);
|
||||
list_t *PetAPI_findPetsByTags(apiClient_t *apiClient, list_t *tags);
|
||||
|
||||
|
||||
|
||||
// Find pet by ID
|
||||
//
|
||||
// Returns a single pet
|
||||
@@ -41,11 +39,9 @@ list_t *PetAPI_findPetsByTags(apiClient_t *apiClient, list_t *tags);
|
||||
pet_t *PetAPI_getPetById(apiClient_t *apiClient, long petId);
|
||||
|
||||
|
||||
|
||||
// Update an existing pet
|
||||
//
|
||||
void PetAPI_updatePet(apiClient_t *apiClient, pet_t *pet);
|
||||
|
||||
void PetAPI_updatePet(apiClient_t *apiClient, pet_t *body);
|
||||
|
||||
|
||||
// Updates a pet in the store with form data
|
||||
@@ -54,8 +50,7 @@ void PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name,
|
||||
char *status);
|
||||
|
||||
|
||||
|
||||
// uploads an image
|
||||
//
|
||||
api_response_t *PetAPI_uploadFile(apiClient_t *apiClient, long petId,
|
||||
char *additionalMetadata, FILE *file);
|
||||
char *additionalMetadata, binary_t *file);
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "apiClient.h"
|
||||
#include "cJSON.h"
|
||||
#include "keyValuePair.h"
|
||||
#include "order.h"
|
||||
#include "StoreAPI.h"
|
||||
|
||||
|
||||
#define MAX_BUFFER_LENGTH 4096
|
||||
#define intToStr(dst, src) \
|
||||
@@ -34,15 +32,16 @@ void StoreAPI_deleteOrder(apiClient_t *apiClient, char *orderId) {
|
||||
// Path Params
|
||||
long sizeOfPathParams_orderId = strlen(orderId) + 3 + strlen(
|
||||
"{ orderId }");
|
||||
|
||||
if(orderId == NULL) {
|
||||
goto end;
|
||||
}
|
||||
char *localVarToReplace_orderId = malloc(sizeOfPathParams_orderId);
|
||||
sprintf(localVarToReplace_orderId, "%s%s%s", "{", "orderId", "}");
|
||||
sprintf(localVarToReplace_orderId, "{%s}", "orderId");
|
||||
|
||||
localVarPath = strReplace(localVarPath, localVarToReplace_orderId,
|
||||
orderId);
|
||||
|
||||
|
||||
apiClient_invoke(apiClient,
|
||||
localVarPath,
|
||||
localVarQueryParameters,
|
||||
@@ -60,7 +59,10 @@ void StoreAPI_deleteOrder(apiClient_t *apiClient, char *orderId) {
|
||||
printf("%s\n", "Order not found");
|
||||
}
|
||||
// No return type
|
||||
end: apiClient_free(apiClient);
|
||||
end:
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -87,6 +89,8 @@ list_t *StoreAPI_getInventory(apiClient_t *apiClient) {
|
||||
char *localVarPath = malloc(sizeOfPath);
|
||||
snprintf(localVarPath, sizeOfPath, "/store/inventory");
|
||||
|
||||
|
||||
|
||||
list_addElement(localVarHeaderType, "application/json"); // produces
|
||||
apiClient_invoke(apiClient,
|
||||
localVarPath,
|
||||
@@ -107,14 +111,15 @@ list_t *StoreAPI_getInventory(apiClient_t *apiClient) {
|
||||
list_t *elementToReturn = list_create();
|
||||
cJSON_ArrayForEach(VarJSON, localVarJSON) {
|
||||
keyValuePair_t *keyPair =
|
||||
keyValuePair_create(strdup(
|
||||
VarJSON->string), cJSON_Print(
|
||||
keyValuePair_create(strdup(VarJSON->string), cJSON_Print(
|
||||
VarJSON));
|
||||
list_addElement(elementToReturn, keyPair);
|
||||
}
|
||||
cJSON_Delete(localVarJSON);
|
||||
|
||||
apiClient_free(apiClient);
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -147,13 +152,12 @@ order_t *StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) {
|
||||
// Path Params
|
||||
long sizeOfPathParams_orderId = sizeof(orderId) + 3 + strlen(
|
||||
"{ orderId }");
|
||||
|
||||
if(orderId == 0) {
|
||||
goto end;
|
||||
}
|
||||
char *localVarToReplace_orderId = malloc(sizeOfPathParams_orderId);
|
||||
snprintf(localVarToReplace_orderId, sizeOfPathParams_orderId, "%s%s%s",
|
||||
"{", "orderId", "}");
|
||||
snprintf(localVarToReplace_orderId, sizeOfPathParams_orderId, "{%s}",
|
||||
"orderId");
|
||||
|
||||
char localVarBuff_orderId[256];
|
||||
intToStr(localVarBuff_orderId, orderId);
|
||||
@@ -161,6 +165,8 @@ order_t *StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) {
|
||||
localVarPath = strReplace(localVarPath, localVarToReplace_orderId,
|
||||
localVarBuff_orderId);
|
||||
|
||||
|
||||
|
||||
list_addElement(localVarHeaderType, "application/xml"); // produces
|
||||
list_addElement(localVarHeaderType, "application/json"); // produces
|
||||
apiClient_invoke(apiClient,
|
||||
@@ -183,13 +189,17 @@ order_t *StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) {
|
||||
printf("%s\n", "Order not found");
|
||||
}
|
||||
// nonprimitive not container
|
||||
order_t *elementToReturn = order_parseFromJSON(apiClient->dataReceived);
|
||||
cJSON *StoreAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
|
||||
order_t *elementToReturn = order_parseFromJSON(StoreAPIlocalVarJSON);
|
||||
cJSON_Delete(StoreAPIlocalVarJSON);
|
||||
if(elementToReturn == NULL) {
|
||||
// return 0;
|
||||
}
|
||||
|
||||
// return type
|
||||
apiClient_free(apiClient);
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -204,7 +214,7 @@ end:
|
||||
|
||||
// Place an order for a pet
|
||||
//
|
||||
order_t *StoreAPI_placeOrder(apiClient_t *apiClient, order_t *order) {
|
||||
order_t *StoreAPI_placeOrder(apiClient_t *apiClient, order_t *body) {
|
||||
list_t *localVarQueryParameters = NULL;
|
||||
list_t *localVarHeaderParameters = NULL;
|
||||
list_t *localVarFormParameters = NULL;
|
||||
@@ -218,13 +228,15 @@ order_t *StoreAPI_placeOrder(apiClient_t *apiClient, order_t *order) {
|
||||
snprintf(localVarPath, sizeOfPath, "/store/order");
|
||||
|
||||
|
||||
|
||||
|
||||
// Body Param
|
||||
cJSON *localVarSingleItemJSON_order;
|
||||
if(order != NULL) {
|
||||
cJSON *localVarSingleItemJSON_body;
|
||||
if(body != NULL) {
|
||||
// string
|
||||
localVarSingleItemJSON_order = order_convertToJSON(order);
|
||||
localVarBodyParameters = cJSON_Print(
|
||||
localVarSingleItemJSON_order);
|
||||
localVarSingleItemJSON_body = order_convertToJSON(body);
|
||||
localVarBodyParameters =
|
||||
cJSON_Print(localVarSingleItemJSON_body);
|
||||
}
|
||||
list_addElement(localVarHeaderType, "application/xml"); // produces
|
||||
list_addElement(localVarHeaderType, "application/json"); // produces
|
||||
@@ -245,20 +257,24 @@ order_t *StoreAPI_placeOrder(apiClient_t *apiClient, order_t *order) {
|
||||
printf("%s\n", "Invalid Order");
|
||||
}
|
||||
// nonprimitive not container
|
||||
order_t *elementToReturn = order_parseFromJSON(apiClient->dataReceived);
|
||||
cJSON *StoreAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
|
||||
order_t *elementToReturn = order_parseFromJSON(StoreAPIlocalVarJSON);
|
||||
cJSON_Delete(StoreAPIlocalVarJSON);
|
||||
if(elementToReturn == NULL) {
|
||||
// return 0;
|
||||
}
|
||||
|
||||
// return type
|
||||
apiClient_free(apiClient);
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
list_free(localVarHeaderType);
|
||||
|
||||
free(localVarPath);
|
||||
cJSON_Delete(localVarSingleItemJSON_order);
|
||||
cJSON_Delete(localVarSingleItemJSON_body);
|
||||
free(localVarBodyParameters);
|
||||
return elementToReturn;
|
||||
end:
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "apiClient.h"
|
||||
#include "cJSON.h"
|
||||
#include "order.h"
|
||||
#include "../include/apiClient.h"
|
||||
#include "../include/list.h"
|
||||
#include "../external/cJSON.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
#include "../model/order.h"
|
||||
|
||||
|
||||
// Delete purchase order by ID
|
||||
@@ -12,7 +14,6 @@
|
||||
void StoreAPI_deleteOrder(apiClient_t *apiClient, char *orderId);
|
||||
|
||||
|
||||
|
||||
// Returns pet inventories by status
|
||||
//
|
||||
// Returns a map of status codes to quantities
|
||||
@@ -20,7 +21,6 @@ void StoreAPI_deleteOrder(apiClient_t *apiClient, char *orderId);
|
||||
list_t *StoreAPI_getInventory(apiClient_t *apiClient);
|
||||
|
||||
|
||||
|
||||
// Find purchase order by ID
|
||||
//
|
||||
// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
@@ -28,7 +28,6 @@ list_t *StoreAPI_getInventory(apiClient_t *apiClient);
|
||||
order_t *StoreAPI_getOrderById(apiClient_t *apiClient, long orderId);
|
||||
|
||||
|
||||
|
||||
// Place an order for a pet
|
||||
//
|
||||
order_t *StoreAPI_placeOrder(apiClient_t *apiClient, order_t *order);
|
||||
order_t *StoreAPI_placeOrder(apiClient_t *apiClient, order_t *body);
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "apiClient.h"
|
||||
#include "cJSON.h"
|
||||
#include "keyValuePair.h"
|
||||
#include "list.h"
|
||||
#include "user.h"
|
||||
#include "UserAPI.h"
|
||||
|
||||
|
||||
#define MAX_BUFFER_LENGTH 4096
|
||||
#define intToStr(dst, src) \
|
||||
@@ -18,7 +15,7 @@
|
||||
//
|
||||
// This can only be done by the logged in user.
|
||||
//
|
||||
void UserAPI_createUser(apiClient_t *apiClient, user_t *user) {
|
||||
void UserAPI_createUser(apiClient_t *apiClient, user_t *body) {
|
||||
list_t *localVarQueryParameters = NULL;
|
||||
list_t *localVarHeaderParameters = NULL;
|
||||
list_t *localVarFormParameters = NULL;
|
||||
@@ -32,13 +29,15 @@ void UserAPI_createUser(apiClient_t *apiClient, user_t *user) {
|
||||
snprintf(localVarPath, sizeOfPath, "/user");
|
||||
|
||||
|
||||
|
||||
|
||||
// Body Param
|
||||
cJSON *localVarSingleItemJSON_user;
|
||||
if(user != NULL) {
|
||||
cJSON *localVarSingleItemJSON_body;
|
||||
if(body != NULL) {
|
||||
// string
|
||||
localVarSingleItemJSON_user = user_convertToJSON(user);
|
||||
localVarSingleItemJSON_body = user_convertToJSON(body);
|
||||
localVarBodyParameters =
|
||||
cJSON_Print(localVarSingleItemJSON_user);
|
||||
cJSON_Print(localVarSingleItemJSON_body);
|
||||
}
|
||||
apiClient_invoke(apiClient,
|
||||
localVarPath,
|
||||
@@ -54,20 +53,23 @@ void UserAPI_createUser(apiClient_t *apiClient, user_t *user) {
|
||||
printf("%s\n", "successful operation");
|
||||
}
|
||||
// No return type
|
||||
end: apiClient_free(apiClient);
|
||||
end:
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
free(localVarPath);
|
||||
cJSON_Delete(localVarSingleItemJSON_user);
|
||||
cJSON_Delete(localVarSingleItemJSON_body);
|
||||
free(localVarBodyParameters);
|
||||
}
|
||||
|
||||
// Creates list of users with given input array
|
||||
//
|
||||
void UserAPI_createUsersWithArrayInput(apiClient_t *apiClient, list_t *user) {
|
||||
void UserAPI_createUsersWithArrayInput(apiClient_t *apiClient, list_t *body) {
|
||||
list_t *localVarQueryParameters = NULL;
|
||||
list_t *localVarHeaderParameters = NULL;
|
||||
list_t *localVarFormParameters = NULL;
|
||||
@@ -81,42 +83,34 @@ void UserAPI_createUsersWithArrayInput(apiClient_t *apiClient, list_t *user) {
|
||||
snprintf(localVarPath, sizeOfPath, "/user/createWithArray");
|
||||
|
||||
|
||||
|
||||
|
||||
// Body Param
|
||||
// notstring
|
||||
cJSON *localVar_user;
|
||||
cJSON *localVarItemJSON_user;
|
||||
cJSON *localVarSingleItemJSON_user;
|
||||
if(user != NULL) {
|
||||
localVarItemJSON_user = cJSON_CreateObject();
|
||||
localVarSingleItemJSON_user = cJSON_AddArrayToObject(
|
||||
localVarItemJSON_user, "user");
|
||||
if(localVarSingleItemJSON_user == NULL) {
|
||||
cJSON *localVar_body;
|
||||
cJSON *localVarItemJSON_body;
|
||||
cJSON *localVarSingleItemJSON_body;
|
||||
if(body != NULL) {
|
||||
localVarItemJSON_body = cJSON_CreateObject();
|
||||
localVarSingleItemJSON_body = cJSON_AddArrayToObject(
|
||||
localVarItemJSON_body, "body");
|
||||
if(localVarSingleItemJSON_body == NULL) {
|
||||
// nonprimitive container
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if(error_ptr != NULL) {
|
||||
fprintf(stderr, "Error Before: %s\n",
|
||||
error_ptr);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
listEntry_t *userBodyListEntry;
|
||||
|
||||
list_ForEach(userBodyListEntry, user) {
|
||||
localVar_user = user_convertToJSON(
|
||||
userBodyListEntry->data);
|
||||
if(localVar_user == NULL) {
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if(error_ptr != NULL) {
|
||||
fprintf(stderr, "Error Before: %s\n",
|
||||
error_ptr);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
cJSON_AddItemToArray(localVarSingleItemJSON_user,
|
||||
localVar_user);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
localVarBodyParameters = cJSON_Print(localVarItemJSON_user);
|
||||
listEntry_t *bodyBodyListEntry;
|
||||
list_ForEach(bodyBodyListEntry, body)
|
||||
{
|
||||
localVar_body = user_convertToJSON(bodyBodyListEntry->data);
|
||||
if(localVar_body == NULL) {
|
||||
goto end;
|
||||
}
|
||||
cJSON_AddItemToArray(localVarSingleItemJSON_body,
|
||||
localVar_body);
|
||||
localVarBodyParameters = cJSON_Print(localVarItemJSON_body);
|
||||
}
|
||||
apiClient_invoke(apiClient,
|
||||
localVarPath,
|
||||
@@ -132,22 +126,25 @@ void UserAPI_createUsersWithArrayInput(apiClient_t *apiClient, list_t *user) {
|
||||
printf("%s\n", "successful operation");
|
||||
}
|
||||
// No return type
|
||||
end: apiClient_free(apiClient);
|
||||
end:
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
free(localVarPath);
|
||||
cJSON_Delete(localVarItemJSON_user);
|
||||
cJSON_Delete(localVarSingleItemJSON_user);
|
||||
cJSON_Delete(localVar_user);
|
||||
cJSON_Delete(localVarItemJSON_body);
|
||||
cJSON_Delete(localVarSingleItemJSON_body);
|
||||
cJSON_Delete(localVar_body);
|
||||
free(localVarBodyParameters);
|
||||
}
|
||||
|
||||
// Creates list of users with given input array
|
||||
//
|
||||
void UserAPI_createUsersWithListInput(apiClient_t *apiClient, list_t *user) {
|
||||
void UserAPI_createUsersWithListInput(apiClient_t *apiClient, list_t *body) {
|
||||
list_t *localVarQueryParameters = NULL;
|
||||
list_t *localVarHeaderParameters = NULL;
|
||||
list_t *localVarFormParameters = NULL;
|
||||
@@ -161,42 +158,34 @@ void UserAPI_createUsersWithListInput(apiClient_t *apiClient, list_t *user) {
|
||||
snprintf(localVarPath, sizeOfPath, "/user/createWithList");
|
||||
|
||||
|
||||
|
||||
|
||||
// Body Param
|
||||
// notstring
|
||||
cJSON *localVar_user;
|
||||
cJSON *localVarItemJSON_user;
|
||||
cJSON *localVarSingleItemJSON_user;
|
||||
if(user != NULL) {
|
||||
localVarItemJSON_user = cJSON_CreateObject();
|
||||
localVarSingleItemJSON_user = cJSON_AddArrayToObject(
|
||||
localVarItemJSON_user, "user");
|
||||
if(localVarSingleItemJSON_user == NULL) {
|
||||
cJSON *localVar_body;
|
||||
cJSON *localVarItemJSON_body;
|
||||
cJSON *localVarSingleItemJSON_body;
|
||||
if(body != NULL) {
|
||||
localVarItemJSON_body = cJSON_CreateObject();
|
||||
localVarSingleItemJSON_body = cJSON_AddArrayToObject(
|
||||
localVarItemJSON_body, "body");
|
||||
if(localVarSingleItemJSON_body == NULL) {
|
||||
// nonprimitive container
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if(error_ptr != NULL) {
|
||||
fprintf(stderr, "Error Before: %s\n",
|
||||
error_ptr);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
listEntry_t *userBodyListEntry;
|
||||
|
||||
list_ForEach(userBodyListEntry, user) {
|
||||
localVar_user = user_convertToJSON(
|
||||
userBodyListEntry->data);
|
||||
if(localVar_user == NULL) {
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if(error_ptr != NULL) {
|
||||
fprintf(stderr, "Error Before: %s\n",
|
||||
error_ptr);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
cJSON_AddItemToArray(localVarSingleItemJSON_user,
|
||||
localVar_user);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
localVarBodyParameters = cJSON_Print(localVarItemJSON_user);
|
||||
listEntry_t *bodyBodyListEntry;
|
||||
list_ForEach(bodyBodyListEntry, body)
|
||||
{
|
||||
localVar_body = user_convertToJSON(bodyBodyListEntry->data);
|
||||
if(localVar_body == NULL) {
|
||||
goto end;
|
||||
}
|
||||
cJSON_AddItemToArray(localVarSingleItemJSON_body,
|
||||
localVar_body);
|
||||
localVarBodyParameters = cJSON_Print(localVarItemJSON_body);
|
||||
}
|
||||
apiClient_invoke(apiClient,
|
||||
localVarPath,
|
||||
@@ -212,16 +201,19 @@ void UserAPI_createUsersWithListInput(apiClient_t *apiClient, list_t *user) {
|
||||
printf("%s\n", "successful operation");
|
||||
}
|
||||
// No return type
|
||||
end: apiClient_free(apiClient);
|
||||
end:
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
free(localVarPath);
|
||||
cJSON_Delete(localVarItemJSON_user);
|
||||
cJSON_Delete(localVarSingleItemJSON_user);
|
||||
cJSON_Delete(localVar_user);
|
||||
cJSON_Delete(localVarItemJSON_body);
|
||||
cJSON_Delete(localVarSingleItemJSON_body);
|
||||
cJSON_Delete(localVar_body);
|
||||
free(localVarBodyParameters);
|
||||
}
|
||||
|
||||
@@ -246,15 +238,16 @@ void UserAPI_deleteUser(apiClient_t *apiClient, char *username) {
|
||||
// Path Params
|
||||
long sizeOfPathParams_username = strlen(username) + 3 + strlen(
|
||||
"{ username }");
|
||||
|
||||
if(username == NULL) {
|
||||
goto end;
|
||||
}
|
||||
char *localVarToReplace_username = malloc(sizeOfPathParams_username);
|
||||
sprintf(localVarToReplace_username, "%s%s%s", "{", "username", "}");
|
||||
sprintf(localVarToReplace_username, "{%s}", "username");
|
||||
|
||||
localVarPath = strReplace(localVarPath, localVarToReplace_username,
|
||||
username);
|
||||
|
||||
|
||||
apiClient_invoke(apiClient,
|
||||
localVarPath,
|
||||
localVarQueryParameters,
|
||||
@@ -272,7 +265,10 @@ void UserAPI_deleteUser(apiClient_t *apiClient, char *username) {
|
||||
printf("%s\n", "User not found");
|
||||
}
|
||||
// No return type
|
||||
end: apiClient_free(apiClient);
|
||||
end:
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -301,15 +297,16 @@ user_t *UserAPI_getUserByName(apiClient_t *apiClient, char *username) {
|
||||
// Path Params
|
||||
long sizeOfPathParams_username = strlen(username) + 3 + strlen(
|
||||
"{ username }");
|
||||
|
||||
if(username == NULL) {
|
||||
goto end;
|
||||
}
|
||||
char *localVarToReplace_username = malloc(sizeOfPathParams_username);
|
||||
sprintf(localVarToReplace_username, "%s%s%s", "{", "username", "}");
|
||||
sprintf(localVarToReplace_username, "{%s}", "username");
|
||||
|
||||
localVarPath = strReplace(localVarPath, localVarToReplace_username,
|
||||
username);
|
||||
|
||||
|
||||
list_addElement(localVarHeaderType, "application/xml"); // produces
|
||||
list_addElement(localVarHeaderType, "application/json"); // produces
|
||||
apiClient_invoke(apiClient,
|
||||
@@ -332,13 +329,17 @@ user_t *UserAPI_getUserByName(apiClient_t *apiClient, char *username) {
|
||||
printf("%s\n", "User not found");
|
||||
}
|
||||
// nonprimitive not container
|
||||
user_t *elementToReturn = user_parseFromJSON(apiClient->dataReceived);
|
||||
cJSON *UserAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
|
||||
user_t *elementToReturn = user_parseFromJSON(UserAPIlocalVarJSON);
|
||||
cJSON_Delete(UserAPIlocalVarJSON);
|
||||
if(elementToReturn == NULL) {
|
||||
// return 0;
|
||||
}
|
||||
|
||||
// return type
|
||||
apiClient_free(apiClient);
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -368,14 +369,15 @@ char *UserAPI_loginUser(apiClient_t *apiClient, char *username,
|
||||
snprintf(localVarPath, sizeOfPath, "/user/login");
|
||||
|
||||
|
||||
|
||||
|
||||
// query parameters
|
||||
char *keyQuery_username;
|
||||
char *valueQuery_username;
|
||||
keyValuePair_t *keyPairQuery_username = 0;
|
||||
if(username) {
|
||||
// string
|
||||
keyQuery_username = strdup("username");
|
||||
valueQuery_username = strdup(username);
|
||||
valueQuery_username = strdup((username));
|
||||
keyPairQuery_username = keyValuePair_create(keyQuery_username,
|
||||
valueQuery_username);
|
||||
list_addElement(localVarQueryParameters, keyPairQuery_username);
|
||||
@@ -386,9 +388,8 @@ char *UserAPI_loginUser(apiClient_t *apiClient, char *username,
|
||||
char *valueQuery_password;
|
||||
keyValuePair_t *keyPairQuery_password = 0;
|
||||
if(password) {
|
||||
// string
|
||||
keyQuery_password = strdup("password");
|
||||
valueQuery_password = strdup(password);
|
||||
valueQuery_password = strdup((password));
|
||||
keyPairQuery_password = keyValuePair_create(keyQuery_password,
|
||||
valueQuery_password);
|
||||
list_addElement(localVarQueryParameters, keyPairQuery_password);
|
||||
@@ -414,7 +415,9 @@ char *UserAPI_loginUser(apiClient_t *apiClient, char *username,
|
||||
// primitive reutrn type simple
|
||||
char *elementToReturn = strdup((char *) apiClient->dataReceived);
|
||||
|
||||
apiClient_free(apiClient);
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
list_free(localVarQueryParameters);
|
||||
|
||||
|
||||
@@ -447,6 +450,8 @@ void UserAPI_logoutUser(apiClient_t *apiClient) {
|
||||
char *localVarPath = malloc(sizeOfPath);
|
||||
snprintf(localVarPath, sizeOfPath, "/user/logout");
|
||||
|
||||
|
||||
|
||||
apiClient_invoke(apiClient,
|
||||
localVarPath,
|
||||
localVarQueryParameters,
|
||||
@@ -461,7 +466,10 @@ void UserAPI_logoutUser(apiClient_t *apiClient) {
|
||||
printf("%s\n", "successful operation");
|
||||
}
|
||||
// No return type
|
||||
end: apiClient_free(apiClient);
|
||||
end:
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -474,7 +482,7 @@ end: apiClient_free(apiClient);
|
||||
//
|
||||
// This can only be done by the logged in user.
|
||||
//
|
||||
void UserAPI_updateUser(apiClient_t *apiClient, char *username, user_t *user) {
|
||||
void UserAPI_updateUser(apiClient_t *apiClient, char *username, user_t *body) {
|
||||
list_t *localVarQueryParameters = NULL;
|
||||
list_t *localVarHeaderParameters = NULL;
|
||||
list_t *localVarFormParameters = NULL;
|
||||
@@ -491,23 +499,24 @@ void UserAPI_updateUser(apiClient_t *apiClient, char *username, user_t *user) {
|
||||
// Path Params
|
||||
long sizeOfPathParams_username = strlen(username) + 3 + strlen(
|
||||
"{ username }");
|
||||
|
||||
if(username == NULL) {
|
||||
goto end;
|
||||
}
|
||||
char *localVarToReplace_username = malloc(sizeOfPathParams_username);
|
||||
sprintf(localVarToReplace_username, "%s%s%s", "{", "username", "}");
|
||||
sprintf(localVarToReplace_username, "{%s}", "username");
|
||||
|
||||
localVarPath = strReplace(localVarPath, localVarToReplace_username,
|
||||
username);
|
||||
|
||||
|
||||
|
||||
// Body Param
|
||||
cJSON *localVarSingleItemJSON_user;
|
||||
if(user != NULL) {
|
||||
cJSON *localVarSingleItemJSON_body;
|
||||
if(body != NULL) {
|
||||
// string
|
||||
localVarSingleItemJSON_user = user_convertToJSON(user);
|
||||
localVarSingleItemJSON_body = user_convertToJSON(body);
|
||||
localVarBodyParameters =
|
||||
cJSON_Print(localVarSingleItemJSON_user);
|
||||
cJSON_Print(localVarSingleItemJSON_body);
|
||||
}
|
||||
apiClient_invoke(apiClient,
|
||||
localVarPath,
|
||||
@@ -526,7 +535,10 @@ void UserAPI_updateUser(apiClient_t *apiClient, char *username, user_t *user) {
|
||||
printf("%s\n", "User not found");
|
||||
}
|
||||
// No return type
|
||||
end: apiClient_free(apiClient);
|
||||
end:
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -534,6 +546,6 @@ end: apiClient_free(apiClient);
|
||||
|
||||
free(localVarPath);
|
||||
free(localVarToReplace_username);
|
||||
cJSON_Delete(localVarSingleItemJSON_user);
|
||||
cJSON_Delete(localVarSingleItemJSON_body);
|
||||
free(localVarBodyParameters);
|
||||
}
|
||||
|
||||
@@ -1,29 +1,27 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "apiClient.h"
|
||||
#include "cJSON.h"
|
||||
#include "list.h"
|
||||
#include "user.h"
|
||||
#include "../include/apiClient.h"
|
||||
#include "../include/list.h"
|
||||
#include "../external/cJSON.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
#include "../model/user.h"
|
||||
|
||||
|
||||
// Create user
|
||||
//
|
||||
// This can only be done by the logged in user.
|
||||
//
|
||||
void UserAPI_createUser(apiClient_t *apiClient, user_t *user);
|
||||
|
||||
void UserAPI_createUser(apiClient_t *apiClient, user_t *body);
|
||||
|
||||
|
||||
// Creates list of users with given input array
|
||||
//
|
||||
void UserAPI_createUsersWithArrayInput(apiClient_t *apiClient, list_t *user);
|
||||
|
||||
void UserAPI_createUsersWithArrayInput(apiClient_t *apiClient, list_t *body);
|
||||
|
||||
|
||||
// Creates list of users with given input array
|
||||
//
|
||||
void UserAPI_createUsersWithListInput(apiClient_t *apiClient, list_t *user);
|
||||
|
||||
void UserAPI_createUsersWithListInput(apiClient_t *apiClient, list_t *body);
|
||||
|
||||
|
||||
// Delete user
|
||||
@@ -33,27 +31,23 @@ void UserAPI_createUsersWithListInput(apiClient_t *apiClient, list_t *user);
|
||||
void UserAPI_deleteUser(apiClient_t *apiClient, char *username);
|
||||
|
||||
|
||||
|
||||
// Get user by user name
|
||||
//
|
||||
user_t *UserAPI_getUserByName(apiClient_t *apiClient, char *username);
|
||||
|
||||
|
||||
|
||||
// Logs user into the system
|
||||
//
|
||||
char *UserAPI_loginUser(apiClient_t *apiClient, char *username, char *password);
|
||||
|
||||
|
||||
|
||||
// Logs out current logged in user session
|
||||
//
|
||||
void UserAPI_logoutUser(apiClient_t *apiClient);
|
||||
|
||||
|
||||
|
||||
// Updated user
|
||||
//
|
||||
// This can only be done by the logged in user.
|
||||
//
|
||||
void UserAPI_updateUser(apiClient_t *apiClient, char *username, user_t *user);
|
||||
void UserAPI_updateUser(apiClient_t *apiClient, char *username, user_t *body);
|
||||
|
||||
@@ -1,35 +1,26 @@
|
||||
#ifndef INCLUDE_API_CLIENT_H
|
||||
#define INCLUDE_API_CLIENT_H
|
||||
|
||||
#include "list.h"
|
||||
|
||||
typedef int bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "../include/list.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
|
||||
typedef struct apiClient_t {
|
||||
char *basePath;
|
||||
void *dataReceived;
|
||||
long response_code;
|
||||
// this would only be generated for basic authentication
|
||||
#ifdef BASIC_AUTH
|
||||
char *username;
|
||||
char *password;
|
||||
#endif // BASIC_AUTH
|
||||
// this would only be generated for OAUTH2 authentication
|
||||
#ifdef OAUTH2
|
||||
char *accessToken;
|
||||
#endif // OAUTH2
|
||||
#ifdef API_KEY
|
||||
// this would only be generated for apiKey authentication
|
||||
list_t *apiKeys;
|
||||
#endif // API_KEY
|
||||
char *accessToken;
|
||||
} apiClient_t;
|
||||
|
||||
typedef struct FileStruct {
|
||||
char *fileData;
|
||||
long fileSize;
|
||||
} FileStruct;
|
||||
typedef struct binary_t {
|
||||
uint8_t *data;
|
||||
unsigned int len;
|
||||
} binary_t;
|
||||
|
||||
apiClient_t *apiClient_create();
|
||||
|
||||
@@ -43,4 +34,8 @@ void apiClient_invoke(apiClient_t *apiClient, char *operationParameter,
|
||||
|
||||
char *strReplace(char *orig, char *rep, char *with);
|
||||
|
||||
char *base64encode(const void *b64_encode_this, int encode_this_many_bytes);
|
||||
|
||||
char *base64decode(const void *b64_decode_this, int decode_this_many_bytes);
|
||||
|
||||
#endif // INCLUDE_API_CLIENT_H
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#ifndef _keyValuePair_H_
|
||||
#define _keyValuePair_H_
|
||||
|
||||
#include <string.h>
|
||||
|
||||
typedef struct keyValuePair_t {
|
||||
@@ -8,3 +11,5 @@ typedef struct keyValuePair_t {
|
||||
keyValuePair_t *keyValuePair_create(char *key, void *value);
|
||||
|
||||
void keyValuePair_free(keyValuePair_t *keyValuePair);
|
||||
|
||||
#endif /* _keyValuePair_H_ */
|
||||
@@ -1,7 +1,8 @@
|
||||
#ifndef INCLUDE_LIST_H
|
||||
#define INCLUDE_LIST_H
|
||||
|
||||
#include "cJSON.h"
|
||||
#include "../external/cJSON.h"
|
||||
#include "../include/list.h"
|
||||
|
||||
typedef struct list_t list_t;
|
||||
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "cJSON.h"
|
||||
#include "list.h"
|
||||
#include "keyValuePair.h"
|
||||
#include "api_response.h"
|
||||
|
||||
|
||||
api_response_t *api_response_create(int code, char *type, char *message) {
|
||||
api_response_t *api_response = malloc(sizeof(api_response_t));
|
||||
api_response->code = code;
|
||||
api_response->type = type;
|
||||
api_response->message = message;
|
||||
|
||||
return api_response;
|
||||
api_response_t *api_response_create(int code, char *type, char *message) {
|
||||
api_response_t *api_response_local_var = malloc(sizeof(api_response_t));
|
||||
if(!api_response_local_var) {
|
||||
return NULL;
|
||||
}
|
||||
api_response_local_var->code = code;
|
||||
api_response_local_var->type = type;
|
||||
api_response_local_var->message = message;
|
||||
|
||||
return api_response_local_var;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,80 +22,87 @@ void api_response_free(api_response_t *api_response) {
|
||||
listEntry_t *listEntry;
|
||||
free(api_response->type);
|
||||
free(api_response->message);
|
||||
|
||||
free(api_response);
|
||||
}
|
||||
|
||||
cJSON *api_response_convertToJSON(api_response_t *api_response) {
|
||||
cJSON *item = cJSON_CreateObject();
|
||||
|
||||
// api_response->code
|
||||
if(cJSON_AddNumberToObject(item, "code", api_response->code) == NULL) {
|
||||
goto fail; // Numeric
|
||||
if(api_response->code) {
|
||||
if(cJSON_AddNumberToObject(item, "code",
|
||||
api_response->code) == NULL)
|
||||
{
|
||||
goto fail; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// api_response->type
|
||||
if(cJSON_AddStringToObject(item, "type", api_response->type) == NULL) {
|
||||
goto fail; // String
|
||||
if(api_response->type) {
|
||||
if(cJSON_AddStringToObject(item, "type",
|
||||
api_response->type) == NULL)
|
||||
{
|
||||
goto fail; // String
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// api_response->message
|
||||
if(cJSON_AddStringToObject(item, "message",
|
||||
api_response->message) == NULL)
|
||||
{
|
||||
goto fail; // String
|
||||
if(api_response->message) {
|
||||
if(cJSON_AddStringToObject(item, "message",
|
||||
api_response->message) == NULL)
|
||||
{
|
||||
goto fail; // String
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
fail:
|
||||
cJSON_Delete(item);
|
||||
if(item) {
|
||||
cJSON_Delete(item);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
api_response_t *api_response_parseFromJSON(char *jsonString) {
|
||||
api_response_t *api_response = NULL;
|
||||
cJSON *api_responseJSON = cJSON_Parse(jsonString);
|
||||
if(api_responseJSON == NULL) {
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if(error_ptr != NULL) {
|
||||
fprintf(stderr, "Error Before: %s\n", error_ptr);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
api_response_t *api_response_parseFromJSON(cJSON *api_responseJSON) {
|
||||
api_response_t *api_response_local_var = NULL;
|
||||
|
||||
// api_response->code
|
||||
cJSON *code =
|
||||
cJSON_GetObjectItemCaseSensitive(api_responseJSON, "code");
|
||||
if(!cJSON_IsNumber(code)) {
|
||||
goto end; // Numeric
|
||||
if(code) {
|
||||
if(!cJSON_IsNumber(code)) {
|
||||
goto end; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
// api_response->type
|
||||
cJSON *type =
|
||||
cJSON_GetObjectItemCaseSensitive(api_responseJSON, "type");
|
||||
if(!cJSON_IsString(type) ||
|
||||
(type->valuestring == NULL))
|
||||
{
|
||||
goto end; // String
|
||||
if(type) {
|
||||
if(!cJSON_IsString(type)) {
|
||||
goto end; // String
|
||||
}
|
||||
}
|
||||
|
||||
// api_response->message
|
||||
cJSON *message = cJSON_GetObjectItemCaseSensitive(api_responseJSON,
|
||||
"message");
|
||||
if(!cJSON_IsString(message) ||
|
||||
(message->valuestring == NULL))
|
||||
{
|
||||
goto end; // String
|
||||
if(message) {
|
||||
if(!cJSON_IsString(message)) {
|
||||
goto end; // String
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
api_response = api_response_create(
|
||||
code->valuedouble,
|
||||
strdup(type->valuestring),
|
||||
strdup(message->valuestring)
|
||||
api_response_local_var = api_response_create(
|
||||
code ? code->valuedouble : 0,
|
||||
type ? strdup(type->valuestring) : NULL,
|
||||
message ? strdup(message->valuestring) : NULL
|
||||
);
|
||||
cJSON_Delete(api_responseJSON);
|
||||
return api_response;
|
||||
|
||||
return api_response_local_var;
|
||||
end:
|
||||
cJSON_Delete(api_responseJSON);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -8,22 +8,23 @@
|
||||
#define _api_response_H_
|
||||
|
||||
#include <string.h>
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "../external/cJSON.h"
|
||||
#include "../include/list.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
|
||||
|
||||
|
||||
typedef struct api_response_t {
|
||||
int code; // numeric
|
||||
char *type; // no enum string
|
||||
char *message; // no enum string
|
||||
char *type; // string
|
||||
char *message; // string
|
||||
} api_response_t;
|
||||
|
||||
api_response_t *api_response_create(int code, char *type, char *message);
|
||||
|
||||
void api_response_free(api_response_t *api_response);
|
||||
|
||||
api_response_t *api_response_parseFromJSON(char *jsonString);
|
||||
api_response_t *api_response_parseFromJSON(cJSON *api_responseJSON);
|
||||
|
||||
cJSON *api_response_convertToJSON(api_response_t *api_response);
|
||||
|
||||
|
||||
@@ -1,79 +1,82 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "cJSON.h"
|
||||
#include "list.h"
|
||||
#include "keyValuePair.h"
|
||||
#include "category.h"
|
||||
|
||||
|
||||
category_t *category_create(long id, char *name) {
|
||||
category_t *category = malloc(sizeof(category_t));
|
||||
category->id = id;
|
||||
category->name = name;
|
||||
|
||||
return category;
|
||||
category_t *category_create(long id, char *name) {
|
||||
category_t *category_local_var = malloc(sizeof(category_t));
|
||||
if(!category_local_var) {
|
||||
return NULL;
|
||||
}
|
||||
category_local_var->id = id;
|
||||
category_local_var->name = name;
|
||||
|
||||
return category_local_var;
|
||||
}
|
||||
|
||||
|
||||
void category_free(category_t *category) {
|
||||
listEntry_t *listEntry;
|
||||
free(category->name);
|
||||
|
||||
free(category);
|
||||
}
|
||||
|
||||
cJSON *category_convertToJSON(category_t *category) {
|
||||
cJSON *item = cJSON_CreateObject();
|
||||
|
||||
// category->id
|
||||
if(cJSON_AddNumberToObject(item, "id", category->id) == NULL) {
|
||||
goto fail; // Numeric
|
||||
if(category->id) {
|
||||
if(cJSON_AddNumberToObject(item, "id", category->id) == NULL) {
|
||||
goto fail; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// category->name
|
||||
if(cJSON_AddStringToObject(item, "name", category->name) == NULL) {
|
||||
goto fail; // String
|
||||
if(category->name) {
|
||||
if(cJSON_AddStringToObject(item, "name",
|
||||
category->name) == NULL)
|
||||
{
|
||||
goto fail; // String
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
fail:
|
||||
cJSON_Delete(item);
|
||||
if(item) {
|
||||
cJSON_Delete(item);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
category_t *category_parseFromJSON(char *jsonString) {
|
||||
category_t *category = NULL;
|
||||
cJSON *categoryJSON = cJSON_Parse(jsonString);
|
||||
if(categoryJSON == NULL) {
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if(error_ptr != NULL) {
|
||||
fprintf(stderr, "Error Before: %s\n", error_ptr);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
category_t *category_parseFromJSON(cJSON *categoryJSON) {
|
||||
category_t *category_local_var = NULL;
|
||||
|
||||
// category->id
|
||||
cJSON *id = cJSON_GetObjectItemCaseSensitive(categoryJSON, "id");
|
||||
if(!cJSON_IsNumber(id)) {
|
||||
goto end; // Numeric
|
||||
if(id) {
|
||||
if(!cJSON_IsNumber(id)) {
|
||||
goto end; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
// category->name
|
||||
cJSON *name = cJSON_GetObjectItemCaseSensitive(categoryJSON, "name");
|
||||
if(!cJSON_IsString(name) ||
|
||||
(name->valuestring == NULL))
|
||||
{
|
||||
goto end; // String
|
||||
if(name) {
|
||||
if(!cJSON_IsString(name)) {
|
||||
goto end; // String
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
category = category_create(
|
||||
id->valuedouble,
|
||||
strdup(name->valuestring)
|
||||
category_local_var = category_create(
|
||||
id ? id->valuedouble : 0,
|
||||
name ? strdup(name->valuestring) : NULL
|
||||
);
|
||||
cJSON_Delete(categoryJSON);
|
||||
return category;
|
||||
|
||||
return category_local_var;
|
||||
end:
|
||||
cJSON_Delete(categoryJSON);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -8,21 +8,22 @@
|
||||
#define _category_H_
|
||||
|
||||
#include <string.h>
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "../external/cJSON.h"
|
||||
#include "../include/list.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
|
||||
|
||||
|
||||
typedef struct category_t {
|
||||
long id; // numeric
|
||||
char *name; // no enum string
|
||||
char *name; // string
|
||||
} category_t;
|
||||
|
||||
category_t *category_create(long id, char *name);
|
||||
|
||||
void category_free(category_t *category);
|
||||
|
||||
category_t *category_parseFromJSON(char *jsonString);
|
||||
category_t *category_parseFromJSON(cJSON *categoryJSON);
|
||||
|
||||
cJSON *category_convertToJSON(category_t *category);
|
||||
|
||||
|
||||
31
samples/client/petstore/c/model/object.c
Normal file
31
samples/client/petstore/c/model/object.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "object.h"
|
||||
|
||||
object_t *object_create() {
|
||||
object_t *object = malloc(sizeof(object_t));
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
void object_free(object_t *object) {
|
||||
free(object);
|
||||
}
|
||||
|
||||
cJSON *object_convertToJSON(object_t *object) {
|
||||
cJSON *item = cJSON_CreateObject();
|
||||
|
||||
return item;
|
||||
fail:
|
||||
cJSON_Delete(item);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
object_t *object_parseFromJSON(char *jsonString) {
|
||||
object_t *object = NULL;
|
||||
|
||||
return object;
|
||||
end:
|
||||
return NULL;
|
||||
}
|
||||
26
samples/client/petstore/c/model/object.h
Normal file
26
samples/client/petstore/c/model/object.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* object.h
|
||||
*/
|
||||
|
||||
#ifndef _object_H_
|
||||
#define _object_H_
|
||||
|
||||
#include <string.h>
|
||||
#include "../external/cJSON.h"
|
||||
#include "../include/list.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
|
||||
|
||||
typedef struct object_t {
|
||||
void *temporary;
|
||||
} object_t;
|
||||
|
||||
object_t *object_create();
|
||||
|
||||
void object_free(object_t *object);
|
||||
|
||||
object_t *object_parseFromJSON(char *jsonString);
|
||||
|
||||
cJSON *object_convertToJSON(object_t *object);
|
||||
|
||||
#endif /* _object_H_ */
|
||||
@@ -1,11 +1,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "cJSON.h"
|
||||
#include "list.h"
|
||||
#include "keyValuePair.h"
|
||||
#include "order.h"
|
||||
|
||||
|
||||
char *statusorder_ToString(status_e status) {
|
||||
char *statusArray[] = { "placed", "approved", "delivered" };
|
||||
return statusArray[status];
|
||||
@@ -21,138 +19,167 @@ status_e statusorder_FromString(char *status) {
|
||||
}
|
||||
stringToReturn++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
order_t *order_create(long id, long petId, int quantity, char *shipDate,
|
||||
status_e status, bool complete) {
|
||||
order_t *order = malloc(sizeof(order_t));
|
||||
order->id = id;
|
||||
order->petId = petId;
|
||||
order->quantity = quantity;
|
||||
order->shipDate = shipDate;
|
||||
order->status = status;
|
||||
order->complete = complete;
|
||||
status_e status, int complete) {
|
||||
order_t *order_local_var = malloc(sizeof(order_t));
|
||||
if(!order_local_var) {
|
||||
return NULL;
|
||||
}
|
||||
order_local_var->id = id;
|
||||
order_local_var->petId = petId;
|
||||
order_local_var->quantity = quantity;
|
||||
order_local_var->shipDate = shipDate;
|
||||
order_local_var->status = status;
|
||||
order_local_var->complete = complete;
|
||||
|
||||
return order;
|
||||
return order_local_var;
|
||||
}
|
||||
|
||||
|
||||
void order_free(order_t *order) {
|
||||
listEntry_t *listEntry;
|
||||
free(order->shipDate);
|
||||
|
||||
free(order);
|
||||
}
|
||||
|
||||
cJSON *order_convertToJSON(order_t *order) {
|
||||
cJSON *item = cJSON_CreateObject();
|
||||
|
||||
// order->id
|
||||
if(cJSON_AddNumberToObject(item, "id", order->id) == NULL) {
|
||||
goto fail; // Numeric
|
||||
if(order->id) {
|
||||
if(cJSON_AddNumberToObject(item, "id", order->id) == NULL) {
|
||||
goto fail; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// order->petId
|
||||
if(cJSON_AddNumberToObject(item, "petId", order->petId) == NULL) {
|
||||
goto fail; // Numeric
|
||||
if(order->petId) {
|
||||
if(cJSON_AddNumberToObject(item, "petId",
|
||||
order->petId) == NULL)
|
||||
{
|
||||
goto fail; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// order->quantity
|
||||
if(cJSON_AddNumberToObject(item, "quantity", order->quantity) == NULL) {
|
||||
goto fail; // Numeric
|
||||
if(order->quantity) {
|
||||
if(cJSON_AddNumberToObject(item, "quantity",
|
||||
order->quantity) == NULL)
|
||||
{
|
||||
goto fail; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// order->shipDate
|
||||
if(cJSON_AddStringToObject(item, "shipDate", order->shipDate) == NULL) {
|
||||
goto fail; // String
|
||||
if(order->shipDate) {
|
||||
if(cJSON_AddStringToObject(item, "shipDate",
|
||||
order->shipDate) == NULL)
|
||||
{
|
||||
goto fail; // Date-Time
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// order->status
|
||||
|
||||
if(cJSON_AddStringToObject(item, "status",
|
||||
statusorder_ToString(order->status)) == NULL)
|
||||
{
|
||||
goto fail; // String
|
||||
goto fail; // Enum
|
||||
}
|
||||
|
||||
|
||||
|
||||
// order->complete
|
||||
if(cJSON_AddBoolToObject(item, "complete", order->complete) == NULL) {
|
||||
goto fail; // Numeric
|
||||
if(order->complete) {
|
||||
if(cJSON_AddBoolToObject(item, "complete",
|
||||
order->complete) == NULL)
|
||||
{
|
||||
goto fail; // Bool
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
fail:
|
||||
cJSON_Delete(item);
|
||||
if(item) {
|
||||
cJSON_Delete(item);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
order_t *order_parseFromJSON(char *jsonString) {
|
||||
order_t *order = NULL;
|
||||
cJSON *orderJSON = cJSON_Parse(jsonString);
|
||||
if(orderJSON == NULL) {
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if(error_ptr != NULL) {
|
||||
fprintf(stderr, "Error Before: %s\n", error_ptr);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
order_t *order_parseFromJSON(cJSON *orderJSON) {
|
||||
order_t *order_local_var = NULL;
|
||||
|
||||
// order->id
|
||||
cJSON *id = cJSON_GetObjectItemCaseSensitive(orderJSON, "id");
|
||||
if(!cJSON_IsNumber(id)) {
|
||||
goto end; // Numeric
|
||||
if(id) {
|
||||
if(!cJSON_IsNumber(id)) {
|
||||
goto end; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
// order->petId
|
||||
cJSON *petId = cJSON_GetObjectItemCaseSensitive(orderJSON, "petId");
|
||||
if(!cJSON_IsNumber(petId)) {
|
||||
goto end; // Numeric
|
||||
if(petId) {
|
||||
if(!cJSON_IsNumber(petId)) {
|
||||
goto end; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
// order->quantity
|
||||
cJSON *quantity =
|
||||
cJSON_GetObjectItemCaseSensitive(orderJSON, "quantity");
|
||||
if(!cJSON_IsNumber(quantity)) {
|
||||
goto end; // Numeric
|
||||
if(quantity) {
|
||||
if(!cJSON_IsNumber(quantity)) {
|
||||
goto end; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
// order->shipDate
|
||||
cJSON *shipDate =
|
||||
cJSON_GetObjectItemCaseSensitive(orderJSON, "shipDate");
|
||||
if(!cJSON_IsString(shipDate) ||
|
||||
(shipDate->valuestring == NULL))
|
||||
{
|
||||
goto end; // String
|
||||
if(shipDate) {
|
||||
if(!cJSON_IsString(shipDate)) {
|
||||
goto end; // DateTime
|
||||
}
|
||||
}
|
||||
|
||||
// order->status
|
||||
status_e statusVariable;
|
||||
cJSON *status = cJSON_GetObjectItemCaseSensitive(orderJSON, "status");
|
||||
if(!cJSON_IsString(status) ||
|
||||
(status->valuestring == NULL))
|
||||
{
|
||||
goto end; // String
|
||||
status_e statusVariable;
|
||||
if(status) {
|
||||
if(!cJSON_IsString(status)) {
|
||||
goto end; // Enum
|
||||
}
|
||||
statusVariable = statusorder_FromString(status->valuestring);
|
||||
}
|
||||
|
||||
statusVariable = statusorder_FromString(status->valuestring);
|
||||
|
||||
// order->complete
|
||||
cJSON *complete =
|
||||
cJSON_GetObjectItemCaseSensitive(orderJSON, "complete");
|
||||
if(!cJSON_IsBool(complete)) {
|
||||
goto end; // Numeric
|
||||
if(complete) {
|
||||
if(!cJSON_IsBool(complete)) {
|
||||
goto end; // Bool
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
order = order_create(
|
||||
id->valuedouble,
|
||||
petId->valuedouble,
|
||||
quantity->valuedouble,
|
||||
strdup(shipDate->valuestring),
|
||||
statusVariable,
|
||||
complete->valueint
|
||||
order_local_var = order_create(
|
||||
id ? id->valuedouble : 0,
|
||||
petId ? petId->valuedouble : 0,
|
||||
quantity ? quantity->valuedouble : 0,
|
||||
shipDate ? strdup(shipDate->valuestring) : NULL,
|
||||
status ? statusVariable : -1,
|
||||
complete ? complete->valueint : 0
|
||||
);
|
||||
cJSON_Delete(orderJSON);
|
||||
return order;
|
||||
|
||||
return order_local_var;
|
||||
end:
|
||||
cJSON_Delete(orderJSON);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -8,33 +8,32 @@
|
||||
#define _order_H_
|
||||
|
||||
#include <string.h>
|
||||
#include "cJSON.h"
|
||||
|
||||
typedef int bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
#include "../external/cJSON.h"
|
||||
#include "../include/list.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
|
||||
typedef enum { placed, approved, delivered } status_e;
|
||||
|
||||
char *statusorder_ToString(status_e status);
|
||||
char *status_ToString(status_e status);
|
||||
|
||||
status_e status_FromString(char *status);
|
||||
|
||||
status_e statusorder_FromString(char *status);
|
||||
|
||||
typedef struct order_t {
|
||||
long id; // numeric
|
||||
long petId; // numeric
|
||||
int quantity; // numeric
|
||||
char *shipDate; // date time string
|
||||
status_e status; // enum string
|
||||
bool complete; // boolean
|
||||
char *shipDate; // date time
|
||||
status_e status; // enum
|
||||
int complete; // boolean
|
||||
} order_t;
|
||||
|
||||
order_t *order_create(long id, long petId, int quantity, char *shipDate,
|
||||
status_e status, bool complete);
|
||||
status_e status, int complete);
|
||||
|
||||
void order_free(order_t *order);
|
||||
|
||||
order_t *order_parseFromJSON(char *jsonString);
|
||||
order_t *order_parseFromJSON(cJSON *orderJSON);
|
||||
|
||||
cJSON *order_convertToJSON(order_t *order);
|
||||
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "cJSON.h"
|
||||
#include "list.h"
|
||||
#include "keyValuePair.h"
|
||||
#include "pet.h"
|
||||
#include "category.h"
|
||||
#include "list.h"
|
||||
#include "tag.h"
|
||||
|
||||
|
||||
char *statuspet_ToString(status_e status) {
|
||||
char *statusArray[] = { "available", "pending", "sold" };
|
||||
@@ -24,19 +19,23 @@ status_e statuspet_FromString(char *status) {
|
||||
}
|
||||
stringToReturn++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pet_t *pet_create(long id, category_t *category, char *name, list_t *photoUrls,
|
||||
list_t *tags, status_e status) {
|
||||
pet_t *pet = malloc(sizeof(pet_t));
|
||||
pet->id = id;
|
||||
pet->category = category;
|
||||
pet->name = name;
|
||||
pet->photoUrls = photoUrls;
|
||||
pet->tags = tags;
|
||||
pet->status = status;
|
||||
pet_t *pet_local_var = malloc(sizeof(pet_t));
|
||||
if(!pet_local_var) {
|
||||
return NULL;
|
||||
}
|
||||
pet_local_var->id = id;
|
||||
pet_local_var->category = category;
|
||||
pet_local_var->name = name;
|
||||
pet_local_var->photoUrls = photoUrls;
|
||||
pet_local_var->tags = tags;
|
||||
pet_local_var->status = status;
|
||||
|
||||
return pet;
|
||||
return pet_local_var;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,33 +51,49 @@ void pet_free(pet_t *pet) {
|
||||
tag_free(listEntry->data);
|
||||
}
|
||||
list_free(pet->tags);
|
||||
|
||||
free(pet);
|
||||
}
|
||||
|
||||
cJSON *pet_convertToJSON(pet_t *pet) {
|
||||
cJSON *item = cJSON_CreateObject();
|
||||
|
||||
// pet->id
|
||||
if(cJSON_AddNumberToObject(item, "id", pet->id) == NULL) {
|
||||
goto fail; // Numeric
|
||||
if(pet->id) {
|
||||
if(cJSON_AddNumberToObject(item, "id", pet->id) == NULL) {
|
||||
goto fail; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// pet->category
|
||||
cJSON *category = category_convertToJSON(pet->category);
|
||||
if(category == NULL) {
|
||||
goto fail; // nonprimitive
|
||||
if(pet->category) {
|
||||
cJSON *category_local_JSON = category_convertToJSON(
|
||||
pet->category);
|
||||
if(category_local_JSON == NULL) {
|
||||
goto fail; // model
|
||||
}
|
||||
cJSON_AddItemToObject(item, "category", category_local_JSON);
|
||||
if(item->child == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
cJSON_AddItemToObject(item, "category", category);
|
||||
if(item->child == NULL) {
|
||||
|
||||
|
||||
// pet->name
|
||||
if(!pet->name) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
// pet->name
|
||||
if(cJSON_AddStringToObject(item, "name", pet->name) == NULL) {
|
||||
goto fail; // String
|
||||
}
|
||||
|
||||
|
||||
// pet->photoUrls
|
||||
if(!pet->photoUrls) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
cJSON *photo_urls = cJSON_AddArrayToObject(item, "photoUrls");
|
||||
if(photo_urls == NULL) {
|
||||
goto fail; // primitive container
|
||||
@@ -94,136 +109,142 @@ cJSON *pet_convertToJSON(pet_t *pet) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// pet->tags
|
||||
cJSON *tags = cJSON_AddArrayToObject(item, "tags");
|
||||
if(tags == NULL) {
|
||||
goto fail; // nonprimitive container
|
||||
if(pet->tags) {
|
||||
cJSON *tags = cJSON_AddArrayToObject(item, "tags");
|
||||
if(tags == NULL) {
|
||||
goto fail; // nonprimitive container
|
||||
}
|
||||
|
||||
listEntry_t *tagsListEntry;
|
||||
if(pet->tags) {
|
||||
list_ForEach(tagsListEntry, pet->tags) {
|
||||
cJSON *itemLocal = tag_convertToJSON(
|
||||
tagsListEntry->data);
|
||||
if(itemLocal == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
cJSON_AddItemToArray(tags, itemLocal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
listEntry_t *tagsListEntry;
|
||||
list_ForEach(tagsListEntry, pet->tags) {
|
||||
cJSON *item = tag_convertToJSON(tagsListEntry->data);
|
||||
if(item == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
cJSON_AddItemToArray(tags, item);
|
||||
}
|
||||
|
||||
// pet->status
|
||||
|
||||
if(cJSON_AddStringToObject(item, "status",
|
||||
statuspet_ToString(pet->status)) == NULL)
|
||||
{
|
||||
goto fail; // String
|
||||
goto fail; // Enum
|
||||
}
|
||||
|
||||
|
||||
return item;
|
||||
fail:
|
||||
cJSON_Delete(item);
|
||||
if(item) {
|
||||
cJSON_Delete(item);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pet_t *pet_parseFromJSON(char *jsonString) {
|
||||
pet_t *pet = NULL;
|
||||
cJSON *petJSON = cJSON_Parse(jsonString);
|
||||
if(petJSON == NULL) {
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if(error_ptr != NULL) {
|
||||
fprintf(stderr, "Error Before: %s\n", error_ptr);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
pet_t *pet_parseFromJSON(cJSON *petJSON) {
|
||||
pet_t *pet_local_var = NULL;
|
||||
|
||||
// pet->id
|
||||
cJSON *id = cJSON_GetObjectItemCaseSensitive(petJSON, "id");
|
||||
if(!cJSON_IsNumber(id)) {
|
||||
goto end; // Numeric
|
||||
if(id) {
|
||||
if(!cJSON_IsNumber(id)) {
|
||||
goto end; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
// pet->category
|
||||
category_t *category;
|
||||
cJSON *categoryJSON = cJSON_GetObjectItemCaseSensitive(petJSON,
|
||||
"category");
|
||||
if(petJSON == NULL) {
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if(error_ptr != NULL) {
|
||||
fprintf(stderr, "Error Before: %s\n", error_ptr);
|
||||
}
|
||||
goto end; // nonprimitive
|
||||
cJSON *category = cJSON_GetObjectItemCaseSensitive(petJSON, "category");
|
||||
category_t *category_local_nonprim = NULL;
|
||||
if(category) {
|
||||
category_local_nonprim = category_parseFromJSON(category); // nonprimitive
|
||||
}
|
||||
char *categoryJSONData = cJSON_Print(categoryJSON);
|
||||
category = category_parseFromJSON(categoryJSONData);
|
||||
|
||||
// pet->name
|
||||
cJSON *name = cJSON_GetObjectItemCaseSensitive(petJSON, "name");
|
||||
if(!cJSON_IsString(name) ||
|
||||
(name->valuestring == NULL))
|
||||
{
|
||||
if(!name) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
if(!cJSON_IsString(name)) {
|
||||
goto end; // String
|
||||
}
|
||||
|
||||
// pet->photoUrls
|
||||
cJSON *photo_urls;
|
||||
cJSON *photoUrlsJSON = cJSON_GetObjectItemCaseSensitive(petJSON,
|
||||
"photoUrls");
|
||||
if(!cJSON_IsArray(photoUrlsJSON)) {
|
||||
cJSON *photoUrls =
|
||||
cJSON_GetObjectItemCaseSensitive(petJSON, "photoUrls");
|
||||
if(!photoUrls) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
list_t *photo_urlsList;
|
||||
|
||||
cJSON *photo_urls_local;
|
||||
if(!cJSON_IsArray(photoUrls)) {
|
||||
goto end; // primitive container
|
||||
}
|
||||
list_t *photo_urlsList = list_create();
|
||||
photo_urlsList = list_create();
|
||||
|
||||
cJSON_ArrayForEach(photo_urls, photoUrlsJSON)
|
||||
cJSON_ArrayForEach(photo_urls_local, photoUrls)
|
||||
{
|
||||
if(!cJSON_IsString(photo_urls)) {
|
||||
if(!cJSON_IsString(photo_urls_local)) {
|
||||
goto end;
|
||||
}
|
||||
list_addElement(photo_urlsList,
|
||||
strdup(photo_urls->valuestring));
|
||||
strdup(photo_urls_local->valuestring));
|
||||
}
|
||||
|
||||
// pet->tags
|
||||
cJSON *tags;
|
||||
cJSON *tagsJSON = cJSON_GetObjectItemCaseSensitive(petJSON, "tags");
|
||||
if(!cJSON_IsArray(tagsJSON)) {
|
||||
goto end; // nonprimitive container
|
||||
}
|
||||
|
||||
list_t *tagsList = list_create();
|
||||
|
||||
cJSON_ArrayForEach(tags, tagsJSON)
|
||||
{
|
||||
if(!cJSON_IsObject(tags)) {
|
||||
goto end;
|
||||
cJSON *tags = cJSON_GetObjectItemCaseSensitive(petJSON, "tags");
|
||||
list_t *tagsList;
|
||||
if(tags) {
|
||||
cJSON *tags_local_nonprimitive;
|
||||
if(!cJSON_IsArray(tags)) {
|
||||
goto end; // nonprimitive container
|
||||
}
|
||||
char *JSONData = cJSON_Print(tags);
|
||||
tag_t *tagsItem = tag_parseFromJSON(JSONData);
|
||||
|
||||
list_addElement(tagsList, tagsItem);
|
||||
free(JSONData);
|
||||
tagsList = list_create();
|
||||
|
||||
cJSON_ArrayForEach(tags_local_nonprimitive, tags)
|
||||
{
|
||||
if(!cJSON_IsObject(tags_local_nonprimitive)) {
|
||||
goto end;
|
||||
}
|
||||
tag_t *tagsItem = tag_parseFromJSON(
|
||||
tags_local_nonprimitive);
|
||||
|
||||
list_addElement(tagsList, tagsItem);
|
||||
}
|
||||
}
|
||||
|
||||
// pet->status
|
||||
status_e statusVariable;
|
||||
cJSON *status = cJSON_GetObjectItemCaseSensitive(petJSON, "status");
|
||||
if(!cJSON_IsString(status) ||
|
||||
(status->valuestring == NULL))
|
||||
{
|
||||
goto end; // String
|
||||
status_e statusVariable;
|
||||
if(status) {
|
||||
if(!cJSON_IsString(status)) {
|
||||
goto end; // Enum
|
||||
}
|
||||
statusVariable = statuspet_FromString(status->valuestring);
|
||||
}
|
||||
|
||||
statusVariable = statuspet_FromString(status->valuestring);
|
||||
|
||||
|
||||
pet = pet_create(
|
||||
id->valuedouble,
|
||||
category,
|
||||
pet_local_var = pet_create(
|
||||
id ? id->valuedouble : 0,
|
||||
category ? category_local_nonprim : NULL,
|
||||
strdup(name->valuestring),
|
||||
photo_urlsList,
|
||||
tagsList,
|
||||
statusVariable
|
||||
tags ? tagsList : NULL,
|
||||
status ? statusVariable : -1
|
||||
);
|
||||
free(categoryJSONData);
|
||||
cJSON_Delete(petJSON);
|
||||
return pet;
|
||||
|
||||
return pet_local_var;
|
||||
end:
|
||||
cJSON_Delete(petJSON);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -8,25 +8,26 @@
|
||||
#define _pet_H_
|
||||
|
||||
#include <string.h>
|
||||
#include "cJSON.h"
|
||||
#include "../external/cJSON.h"
|
||||
#include "../include/list.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
#include "category.h"
|
||||
#include "list.h"
|
||||
#include "tag.h"
|
||||
|
||||
|
||||
typedef enum { available, pending, sold } status_e;
|
||||
|
||||
char *statuspet_ToString(status_e status);
|
||||
char *status_ToString(status_e status);
|
||||
|
||||
status_e status_FromString(char *status);
|
||||
|
||||
status_e statuspet_FromString(char *status);
|
||||
|
||||
typedef struct pet_t {
|
||||
long id; // numeric
|
||||
category_t *category; // nonprimitive
|
||||
char *name; // no enum string
|
||||
category_t *category; // model
|
||||
char *name; // string
|
||||
list_t *photoUrls; // primitive container
|
||||
list_t *tags; // nonprimitive container
|
||||
status_e status; // enum string
|
||||
status_e status; // enum
|
||||
} pet_t;
|
||||
|
||||
pet_t *pet_create(long id, category_t *category, char *name, list_t *photoUrls,
|
||||
@@ -34,7 +35,7 @@ pet_t *pet_create(long id, category_t *category, char *name, list_t *photoUrls,
|
||||
|
||||
void pet_free(pet_t *pet);
|
||||
|
||||
pet_t *pet_parseFromJSON(char *jsonString);
|
||||
pet_t *pet_parseFromJSON(cJSON *petJSON);
|
||||
|
||||
cJSON *pet_convertToJSON(pet_t *pet);
|
||||
|
||||
|
||||
@@ -1,79 +1,80 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "cJSON.h"
|
||||
#include "list.h"
|
||||
#include "keyValuePair.h"
|
||||
#include "tag.h"
|
||||
|
||||
|
||||
tag_t *tag_create(long id, char *name) {
|
||||
tag_t *tag = malloc(sizeof(tag_t));
|
||||
tag->id = id;
|
||||
tag->name = name;
|
||||
|
||||
return tag;
|
||||
tag_t *tag_create(long id, char *name) {
|
||||
tag_t *tag_local_var = malloc(sizeof(tag_t));
|
||||
if(!tag_local_var) {
|
||||
return NULL;
|
||||
}
|
||||
tag_local_var->id = id;
|
||||
tag_local_var->name = name;
|
||||
|
||||
return tag_local_var;
|
||||
}
|
||||
|
||||
|
||||
void tag_free(tag_t *tag) {
|
||||
listEntry_t *listEntry;
|
||||
free(tag->name);
|
||||
|
||||
free(tag);
|
||||
}
|
||||
|
||||
cJSON *tag_convertToJSON(tag_t *tag) {
|
||||
cJSON *item = cJSON_CreateObject();
|
||||
|
||||
// tag->id
|
||||
if(cJSON_AddNumberToObject(item, "id", tag->id) == NULL) {
|
||||
goto fail; // Numeric
|
||||
if(tag->id) {
|
||||
if(cJSON_AddNumberToObject(item, "id", tag->id) == NULL) {
|
||||
goto fail; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// tag->name
|
||||
if(cJSON_AddStringToObject(item, "name", tag->name) == NULL) {
|
||||
goto fail; // String
|
||||
if(tag->name) {
|
||||
if(cJSON_AddStringToObject(item, "name", tag->name) == NULL) {
|
||||
goto fail; // String
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
fail:
|
||||
cJSON_Delete(item);
|
||||
if(item) {
|
||||
cJSON_Delete(item);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tag_t *tag_parseFromJSON(char *jsonString) {
|
||||
tag_t *tag = NULL;
|
||||
cJSON *tagJSON = cJSON_Parse(jsonString);
|
||||
if(tagJSON == NULL) {
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if(error_ptr != NULL) {
|
||||
fprintf(stderr, "Error Before: %s\n", error_ptr);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
tag_t *tag_parseFromJSON(cJSON *tagJSON) {
|
||||
tag_t *tag_local_var = NULL;
|
||||
|
||||
// tag->id
|
||||
cJSON *id = cJSON_GetObjectItemCaseSensitive(tagJSON, "id");
|
||||
if(!cJSON_IsNumber(id)) {
|
||||
goto end; // Numeric
|
||||
if(id) {
|
||||
if(!cJSON_IsNumber(id)) {
|
||||
goto end; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
// tag->name
|
||||
cJSON *name = cJSON_GetObjectItemCaseSensitive(tagJSON, "name");
|
||||
if(!cJSON_IsString(name) ||
|
||||
(name->valuestring == NULL))
|
||||
{
|
||||
goto end; // String
|
||||
if(name) {
|
||||
if(!cJSON_IsString(name)) {
|
||||
goto end; // String
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tag = tag_create(
|
||||
id->valuedouble,
|
||||
strdup(name->valuestring)
|
||||
tag_local_var = tag_create(
|
||||
id ? id->valuedouble : 0,
|
||||
name ? strdup(name->valuestring) : NULL
|
||||
);
|
||||
cJSON_Delete(tagJSON);
|
||||
return tag;
|
||||
|
||||
return tag_local_var;
|
||||
end:
|
||||
cJSON_Delete(tagJSON);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -8,21 +8,22 @@
|
||||
#define _tag_H_
|
||||
|
||||
#include <string.h>
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "../external/cJSON.h"
|
||||
#include "../include/list.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
|
||||
|
||||
|
||||
typedef struct tag_t {
|
||||
long id; // numeric
|
||||
char *name; // no enum string
|
||||
char *name; // string
|
||||
} tag_t;
|
||||
|
||||
tag_t *tag_create(long id, char *name);
|
||||
|
||||
void tag_free(tag_t *tag);
|
||||
|
||||
tag_t *tag_parseFromJSON(char *jsonString);
|
||||
tag_t *tag_parseFromJSON(cJSON *tagJSON);
|
||||
|
||||
cJSON *tag_convertToJSON(tag_t *tag);
|
||||
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "cJSON.h"
|
||||
#include "list.h"
|
||||
#include "keyValuePair.h"
|
||||
#include "user.h"
|
||||
|
||||
|
||||
|
||||
user_t *user_create(long id, char *username, char *firstName, char *lastName,
|
||||
char *email, char *password, char *phone, int userStatus) {
|
||||
user_t *user = malloc(sizeof(user_t));
|
||||
user->id = id;
|
||||
user->username = username;
|
||||
user->firstName = firstName;
|
||||
user->lastName = lastName;
|
||||
user->email = email;
|
||||
user->password = password;
|
||||
user->phone = phone;
|
||||
user->userStatus = userStatus;
|
||||
user_t *user_local_var = malloc(sizeof(user_t));
|
||||
if(!user_local_var) {
|
||||
return NULL;
|
||||
}
|
||||
user_local_var->id = id;
|
||||
user_local_var->username = username;
|
||||
user_local_var->firstName = firstName;
|
||||
user_local_var->lastName = lastName;
|
||||
user_local_var->email = email;
|
||||
user_local_var->password = password;
|
||||
user_local_var->phone = phone;
|
||||
user_local_var->userStatus = userStatus;
|
||||
|
||||
return user;
|
||||
return user_local_var;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,152 +32,182 @@ void user_free(user_t *user) {
|
||||
free(user->email);
|
||||
free(user->password);
|
||||
free(user->phone);
|
||||
|
||||
free(user);
|
||||
}
|
||||
|
||||
cJSON *user_convertToJSON(user_t *user) {
|
||||
cJSON *item = cJSON_CreateObject();
|
||||
|
||||
// user->id
|
||||
if(cJSON_AddNumberToObject(item, "id", user->id) == NULL) {
|
||||
goto fail; // Numeric
|
||||
if(user->id) {
|
||||
if(cJSON_AddNumberToObject(item, "id", user->id) == NULL) {
|
||||
goto fail; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// user->username
|
||||
if(cJSON_AddStringToObject(item, "username", user->username) == NULL) {
|
||||
goto fail; // String
|
||||
if(user->username) {
|
||||
if(cJSON_AddStringToObject(item, "username",
|
||||
user->username) == NULL)
|
||||
{
|
||||
goto fail; // String
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// user->firstName
|
||||
if(cJSON_AddStringToObject(item, "firstName",
|
||||
user->firstName) == NULL)
|
||||
{
|
||||
goto fail; // String
|
||||
if(user->firstName) {
|
||||
if(cJSON_AddStringToObject(item, "firstName",
|
||||
user->firstName) == NULL)
|
||||
{
|
||||
goto fail; // String
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// user->lastName
|
||||
if(cJSON_AddStringToObject(item, "lastName", user->lastName) == NULL) {
|
||||
goto fail; // String
|
||||
if(user->lastName) {
|
||||
if(cJSON_AddStringToObject(item, "lastName",
|
||||
user->lastName) == NULL)
|
||||
{
|
||||
goto fail; // String
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// user->email
|
||||
if(cJSON_AddStringToObject(item, "email", user->email) == NULL) {
|
||||
goto fail; // String
|
||||
if(user->email) {
|
||||
if(cJSON_AddStringToObject(item, "email",
|
||||
user->email) == NULL)
|
||||
{
|
||||
goto fail; // String
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// user->password
|
||||
if(cJSON_AddStringToObject(item, "password", user->password) == NULL) {
|
||||
goto fail; // String
|
||||
if(user->password) {
|
||||
if(cJSON_AddStringToObject(item, "password",
|
||||
user->password) == NULL)
|
||||
{
|
||||
goto fail; // String
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// user->phone
|
||||
if(cJSON_AddStringToObject(item, "phone", user->phone) == NULL) {
|
||||
goto fail; // String
|
||||
if(user->phone) {
|
||||
if(cJSON_AddStringToObject(item, "phone",
|
||||
user->phone) == NULL)
|
||||
{
|
||||
goto fail; // String
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// user->userStatus
|
||||
if(cJSON_AddNumberToObject(item, "userStatus",
|
||||
user->userStatus) == NULL)
|
||||
{
|
||||
goto fail; // Numeric
|
||||
if(user->userStatus) {
|
||||
if(cJSON_AddNumberToObject(item, "userStatus",
|
||||
user->userStatus) == NULL)
|
||||
{
|
||||
goto fail; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
fail:
|
||||
cJSON_Delete(item);
|
||||
if(item) {
|
||||
cJSON_Delete(item);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
user_t *user_parseFromJSON(char *jsonString) {
|
||||
user_t *user = NULL;
|
||||
cJSON *userJSON = cJSON_Parse(jsonString);
|
||||
if(userJSON == NULL) {
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if(error_ptr != NULL) {
|
||||
fprintf(stderr, "Error Before: %s\n", error_ptr);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
user_t *user_parseFromJSON(cJSON *userJSON) {
|
||||
user_t *user_local_var = NULL;
|
||||
|
||||
// user->id
|
||||
cJSON *id = cJSON_GetObjectItemCaseSensitive(userJSON, "id");
|
||||
if(!cJSON_IsNumber(id)) {
|
||||
goto end; // Numeric
|
||||
if(id) {
|
||||
if(!cJSON_IsNumber(id)) {
|
||||
goto end; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
// user->username
|
||||
cJSON *username =
|
||||
cJSON_GetObjectItemCaseSensitive(userJSON, "username");
|
||||
if(!cJSON_IsString(username) ||
|
||||
(username->valuestring == NULL))
|
||||
{
|
||||
goto end; // String
|
||||
if(username) {
|
||||
if(!cJSON_IsString(username)) {
|
||||
goto end; // String
|
||||
}
|
||||
}
|
||||
|
||||
// user->firstName
|
||||
cJSON *firstName = cJSON_GetObjectItemCaseSensitive(userJSON,
|
||||
"firstName");
|
||||
if(!cJSON_IsString(firstName) ||
|
||||
(firstName->valuestring == NULL))
|
||||
{
|
||||
goto end; // String
|
||||
if(firstName) {
|
||||
if(!cJSON_IsString(firstName)) {
|
||||
goto end; // String
|
||||
}
|
||||
}
|
||||
|
||||
// user->lastName
|
||||
cJSON *lastName =
|
||||
cJSON_GetObjectItemCaseSensitive(userJSON, "lastName");
|
||||
if(!cJSON_IsString(lastName) ||
|
||||
(lastName->valuestring == NULL))
|
||||
{
|
||||
goto end; // String
|
||||
if(lastName) {
|
||||
if(!cJSON_IsString(lastName)) {
|
||||
goto end; // String
|
||||
}
|
||||
}
|
||||
|
||||
// user->email
|
||||
cJSON *email = cJSON_GetObjectItemCaseSensitive(userJSON, "email");
|
||||
if(!cJSON_IsString(email) ||
|
||||
(email->valuestring == NULL))
|
||||
{
|
||||
goto end; // String
|
||||
if(email) {
|
||||
if(!cJSON_IsString(email)) {
|
||||
goto end; // String
|
||||
}
|
||||
}
|
||||
|
||||
// user->password
|
||||
cJSON *password =
|
||||
cJSON_GetObjectItemCaseSensitive(userJSON, "password");
|
||||
if(!cJSON_IsString(password) ||
|
||||
(password->valuestring == NULL))
|
||||
{
|
||||
goto end; // String
|
||||
if(password) {
|
||||
if(!cJSON_IsString(password)) {
|
||||
goto end; // String
|
||||
}
|
||||
}
|
||||
|
||||
// user->phone
|
||||
cJSON *phone = cJSON_GetObjectItemCaseSensitive(userJSON, "phone");
|
||||
if(!cJSON_IsString(phone) ||
|
||||
(phone->valuestring == NULL))
|
||||
{
|
||||
goto end; // String
|
||||
if(phone) {
|
||||
if(!cJSON_IsString(phone)) {
|
||||
goto end; // String
|
||||
}
|
||||
}
|
||||
|
||||
// user->userStatus
|
||||
cJSON *userStatus = cJSON_GetObjectItemCaseSensitive(userJSON,
|
||||
"userStatus");
|
||||
if(!cJSON_IsNumber(userStatus)) {
|
||||
goto end; // Numeric
|
||||
if(userStatus) {
|
||||
if(!cJSON_IsNumber(userStatus)) {
|
||||
goto end; // Numeric
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
user = user_create(
|
||||
id->valuedouble,
|
||||
strdup(username->valuestring),
|
||||
strdup(firstName->valuestring),
|
||||
strdup(lastName->valuestring),
|
||||
strdup(email->valuestring),
|
||||
strdup(password->valuestring),
|
||||
strdup(phone->valuestring),
|
||||
userStatus->valuedouble
|
||||
user_local_var = user_create(
|
||||
id ? id->valuedouble : 0,
|
||||
username ? strdup(username->valuestring) : NULL,
|
||||
firstName ? strdup(firstName->valuestring) : NULL,
|
||||
lastName ? strdup(lastName->valuestring) : NULL,
|
||||
email ? strdup(email->valuestring) : NULL,
|
||||
password ? strdup(password->valuestring) : NULL,
|
||||
phone ? strdup(phone->valuestring) : NULL,
|
||||
userStatus ? userStatus->valuedouble : 0
|
||||
);
|
||||
cJSON_Delete(userJSON);
|
||||
return user;
|
||||
|
||||
return user_local_var;
|
||||
end:
|
||||
cJSON_Delete(userJSON);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -8,19 +8,20 @@
|
||||
#define _user_H_
|
||||
|
||||
#include <string.h>
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "../external/cJSON.h"
|
||||
#include "../include/list.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
|
||||
|
||||
|
||||
typedef struct user_t {
|
||||
long id; // numeric
|
||||
char *username; // no enum string
|
||||
char *firstName; // no enum string
|
||||
char *lastName; // no enum string
|
||||
char *email; // no enum string
|
||||
char *password; // no enum string
|
||||
char *phone; // no enum string
|
||||
char *username; // string
|
||||
char *firstName; // string
|
||||
char *lastName; // string
|
||||
char *email; // string
|
||||
char *password; // string
|
||||
char *phone; // string
|
||||
int userStatus; // numeric
|
||||
} user_t;
|
||||
|
||||
@@ -29,7 +30,7 @@ user_t *user_create(long id, char *username, char *firstName, char *lastName,
|
||||
|
||||
void user_free(user_t *user);
|
||||
|
||||
user_t *user_parseFromJSON(char *jsonString);
|
||||
user_t *user_parseFromJSON(cJSON *userJSON);
|
||||
|
||||
cJSON *user_convertToJSON(user_t *user);
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "apiClient.h"
|
||||
#include "keyValuePair.h"
|
||||
#include "../include/apiClient.h"
|
||||
#ifdef OPENSSL
|
||||
#include "openssl/pem.h"
|
||||
#endif
|
||||
|
||||
size_t writeDataCallback(void *buffer, size_t size, size_t nmemb, void *userp);
|
||||
|
||||
@@ -13,19 +15,18 @@ apiClient_t *apiClient_create() {
|
||||
apiClient->basePath = "http://petstore.swagger.io/v2";
|
||||
apiClient->dataReceived = NULL;
|
||||
apiClient->response_code = 0;
|
||||
#ifdef BASIC_AUTH
|
||||
apiClient->username = NULL;
|
||||
apiClient->password = NULL;
|
||||
#endif // BASIC_AUTH
|
||||
#ifdef OAUTH2
|
||||
apiClient->apiKeys = NULL;
|
||||
apiClient->accessToken = NULL;
|
||||
#endif // OAUTH2
|
||||
|
||||
return apiClient;
|
||||
}
|
||||
|
||||
void apiClient_free(apiClient_t *apiClient) {
|
||||
if(apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
if(apiClient->apiKeys) {
|
||||
list_free(apiClient->apiKeys);
|
||||
}
|
||||
if(apiClient->accessToken) {
|
||||
free(apiClient->accessToken);
|
||||
}
|
||||
free(apiClient);
|
||||
curl_global_cleanup();
|
||||
@@ -138,7 +139,7 @@ void apiClient_invoke(apiClient_t *apiClient, char *operationParameter,
|
||||
struct curl_slist *headers = NULL;
|
||||
char *buffContent = NULL;
|
||||
char *buffHeader = NULL;
|
||||
FileStruct *fileVar = NULL;
|
||||
binary_t *fileVar = NULL;
|
||||
char *formString = NULL;
|
||||
|
||||
if(headerType != NULL) {
|
||||
@@ -250,18 +251,12 @@ void apiClient_invoke(apiClient_t *apiClient, char *operationParameter,
|
||||
if(strcmp(keyValuePair->key,
|
||||
"file") == 0)
|
||||
{
|
||||
printf(
|
||||
"Size of fileVar - %p\n",
|
||||
fileVar);
|
||||
memcpy(&fileVar,
|
||||
keyValuePair->value,
|
||||
sizeof(fileVar));
|
||||
printf(
|
||||
"Size of fileVar1 - %p\n",
|
||||
fileVar);
|
||||
curl_mime_data(part,
|
||||
fileVar->fileData,
|
||||
fileVar->fileSize);
|
||||
fileVar->data,
|
||||
fileVar->len);
|
||||
curl_mime_filename(part,
|
||||
"image.png");
|
||||
} else {
|
||||
@@ -288,19 +283,22 @@ void apiClient_invoke(apiClient_t *apiClient, char *operationParameter,
|
||||
}
|
||||
}
|
||||
// this would only be generated for apiKey authentication
|
||||
#ifdef API_KEY
|
||||
list_ForEach(listEntry, apiClient->apiKeys) {
|
||||
keyValuePair_t *apiKey = listEntry->data;
|
||||
if((apiKey->key != NULL) &&
|
||||
(apiKey->value != NULL) )
|
||||
{
|
||||
char *headerValueToWrite = assembleHeaderField(
|
||||
apiKey->key, apiKey->value);
|
||||
curl_slist_append(headers, headerValueToWrite);
|
||||
free(headerValueToWrite);
|
||||
if(apiClient->apiKeys != NULL) {
|
||||
list_ForEach(listEntry, apiClient->apiKeys) {
|
||||
keyValuePair_t *apiKey = listEntry->data;
|
||||
if((apiKey->key != NULL) &&
|
||||
(apiKey->value != NULL) )
|
||||
{
|
||||
char *headerValueToWrite =
|
||||
assembleHeaderField(
|
||||
apiKey->key,
|
||||
apiKey->value);
|
||||
curl_slist_append(headers,
|
||||
headerValueToWrite);
|
||||
free(headerValueToWrite);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // API_KEY
|
||||
|
||||
char *targetUrl =
|
||||
assembleTargetUrl(apiClient->basePath,
|
||||
@@ -316,43 +314,14 @@ void apiClient_invoke(apiClient_t *apiClient, char *operationParameter,
|
||||
&apiClient->dataReceived);
|
||||
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
|
||||
curl_easy_setopt(handle, CURLOPT_VERBOSE, 0); // to get curl debug msg 0: to disable, 1L:to enable
|
||||
|
||||
// this would only be generated for OAuth2 authentication
|
||||
#ifdef OAUTH2
|
||||
if(apiClient->accessToken != NULL) {
|
||||
// curl_easy_setopt(handle, CURLOPT_HTTPAUTH, CURLAUTH_BEARER);
|
||||
curl_easy_setopt(handle,
|
||||
CURLOPT_XOAUTH2_BEARER,
|
||||
apiClient->accessToken);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// this would only be generated for basic authentication:
|
||||
#ifdef BASIC_AUTH
|
||||
char *authenticationToken;
|
||||
|
||||
if((apiClient->username != NULL) &&
|
||||
(apiClient->password != NULL) )
|
||||
{
|
||||
authenticationToken = malloc(strlen(
|
||||
apiClient->username) +
|
||||
strlen(
|
||||
apiClient->password) +
|
||||
2);
|
||||
sprintf(authenticationToken,
|
||||
"%s:%s",
|
||||
apiClient->username,
|
||||
apiClient->password);
|
||||
|
||||
curl_easy_setopt(handle,
|
||||
CURLOPT_HTTPAUTH,
|
||||
CURLAUTH_BASIC);
|
||||
curl_easy_setopt(handle,
|
||||
CURLOPT_USERPWD,
|
||||
authenticationToken);
|
||||
}
|
||||
|
||||
#endif // BASIC_AUTH
|
||||
|
||||
if(bodyParameters != NULL) {
|
||||
postData(handle, bodyParameters);
|
||||
@@ -372,16 +341,17 @@ void apiClient_invoke(apiClient_t *apiClient, char *operationParameter,
|
||||
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE,
|
||||
&apiClient->response_code);
|
||||
} else {
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
||||
char *url, *ip, *scheme;
|
||||
long port;
|
||||
curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
|
||||
curl_easy_getinfo(handle, CURLINFO_PRIMARY_IP, &ip);
|
||||
curl_easy_getinfo(handle, CURLINFO_PRIMARY_PORT, &port);
|
||||
curl_easy_getinfo(handle, CURLINFO_SCHEME, &scheme);
|
||||
fprintf(stderr,
|
||||
"curl_easy_perform() failed\n\nURL: %s\nIP: %s\nPORT: %li\nSCHEME: %s\nStrERROR: %s\n", url, ip, port, scheme,
|
||||
curl_easy_strerror(res));
|
||||
}
|
||||
#ifdef BASIC_AUTH
|
||||
if((apiClient->username != NULL) &&
|
||||
(apiClient->password != NULL) )
|
||||
{
|
||||
free(authenticationToken);
|
||||
}
|
||||
#endif // BASIC_AUTH
|
||||
|
||||
curl_easy_cleanup(handle);
|
||||
if(formParameters != NULL) {
|
||||
free(formString);
|
||||
@@ -448,3 +418,43 @@ char *strReplace(char *orig, char *rep, char *with) {
|
||||
free(originalPointer);
|
||||
return result;
|
||||
}
|
||||
|
||||
char *sbi_base64encode(const void *b64_encode_this,
|
||||
int encode_this_many_bytes) {
|
||||
#ifdef OPENSSL
|
||||
BIO *b64_bio, *mem_bio; // Declares two OpenSSL BIOs: a base64 filter and a memory BIO.
|
||||
BUF_MEM *mem_bio_mem_ptr; // Pointer to a "memory BIO" structure holding our base64 data.
|
||||
b64_bio = BIO_new(BIO_f_base64()); // Initialize our base64 filter BIO.
|
||||
mem_bio = BIO_new(BIO_s_mem()); // Initialize our memory sink BIO.
|
||||
BIO_push(b64_bio, mem_bio); // Link the BIOs by creating a filter-sink BIO chain.
|
||||
BIO_set_flags(b64_bio, BIO_FLAGS_BASE64_NO_NL); // No newlines every 64 characters or less.
|
||||
BIO_write(b64_bio, b64_encode_this, encode_this_many_bytes); // Records base64 encoded data.
|
||||
BIO_flush(b64_bio); // Flush data. Necessary for b64 encoding, because of pad characters.
|
||||
BIO_get_mem_ptr(mem_bio, &mem_bio_mem_ptr); // Store address of mem_bio's memory structure.
|
||||
BIO_set_close(mem_bio, BIO_NOCLOSE); // Permit access to mem_ptr after BIOs are destroyed.
|
||||
BIO_free_all(b64_bio); // Destroys all BIOs in chain, starting with b64 (i.e. the 1st one).
|
||||
BUF_MEM_grow(mem_bio_mem_ptr, (*mem_bio_mem_ptr).length + 1); // Makes space for end null.
|
||||
(*mem_bio_mem_ptr).data[(*mem_bio_mem_ptr).length] = '\0'; // Adds null-terminator to tail.
|
||||
return (*mem_bio_mem_ptr).data; // Returns base-64 encoded data. (See: "buf_mem_st" struct).
|
||||
#endif
|
||||
}
|
||||
|
||||
char *sbi_base64decode(const void *b64_decode_this,
|
||||
int decode_this_many_bytes) {
|
||||
#ifdef OPENSSL
|
||||
BIO *b64_bio, *mem_bio; // Declares two OpenSSL BIOs: a base64 filter and a memory BIO.
|
||||
char *base64_decoded = calloc( (decode_this_many_bytes * 3) / 4 + 1,
|
||||
sizeof(char) ); // +1 = null.
|
||||
b64_bio = BIO_new(BIO_f_base64()); // Initialize our base64 filter BIO.
|
||||
mem_bio = BIO_new(BIO_s_mem()); // Initialize our memory source BIO.
|
||||
BIO_write(mem_bio, b64_decode_this, decode_this_many_bytes); // Base64 data saved in source.
|
||||
BIO_push(b64_bio, mem_bio); // Link the BIOs by creating a filter-source BIO chain.
|
||||
BIO_set_flags(b64_bio, BIO_FLAGS_BASE64_NO_NL); // Don't require trailing newlines.
|
||||
int decoded_byte_index = 0; // Index where the next base64_decoded byte should be written.
|
||||
while(0 < BIO_read(b64_bio, base64_decoded + decoded_byte_index, 1) ) { // Read byte-by-byte.
|
||||
decoded_byte_index++; // Increment the index until read of BIO decoded data is complete.
|
||||
} // Once we're done reading decoded data, BIO_read returns -1 even though there's no error.
|
||||
BIO_free_all(b64_bio); // Destroys all BIOs in chain, starting with b64 (i.e. the 1st one).
|
||||
return base64_decoded; // Returns base-64 decoded data with trailing null terminator.
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "keyValuePair.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
|
||||
keyValuePair_t *keyValuePair_create(char *key, void *value) {
|
||||
keyValuePair_t *keyValuePair = malloc(sizeof(keyValuePair_t));
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "cJSON.h"
|
||||
#include "list.h"
|
||||
|
||||
#include "../include/list.h"
|
||||
static listEntry_t *listEntry_create(void *data) {
|
||||
listEntry_t *createdListEntry = malloc(sizeof(listEntry_t));
|
||||
if(createdListEntry == NULL) {
|
||||
|
||||
@@ -2,13 +2,8 @@
|
||||
#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"
|
||||
#include "../api/PetAPI.h"
|
||||
|
||||
|
||||
#define EXAMPLE_CATEGORY_NAME "Example Category"
|
||||
#define EXAMPLE_CATEGORY_ID 5
|
||||
@@ -70,8 +65,13 @@ int main() {
|
||||
status);
|
||||
|
||||
PetAPI_addPet(apiClient, pet);
|
||||
cJSON *JSONR_local = pet_convertToJSON(pet);
|
||||
char *toPrint = cJSON_Print(JSONR_local);
|
||||
printf("Data is:%s\n", toPrint);
|
||||
free(toPrint);
|
||||
pet_free(pet);
|
||||
|
||||
cJSON_Delete(JSONR_local);
|
||||
apiClient_free(apiClient);
|
||||
|
||||
// Pet update with form test
|
||||
char *petName1 = "Rocky Handsome";
|
||||
@@ -81,7 +81,7 @@ int main() {
|
||||
apiClient_t *apiClient1 = apiClient_create();
|
||||
PetAPI_updatePetWithForm(apiClient1, EXAMPLE_PET_ID, petName1,
|
||||
petName2);
|
||||
|
||||
apiClient_free(apiClient1);
|
||||
|
||||
// Get pet by id test
|
||||
apiClient_t *apiClient2 = apiClient_create();
|
||||
@@ -111,19 +111,32 @@ int main() {
|
||||
free(petJson);
|
||||
cJSON_Delete(JSONR);
|
||||
pet_free(mypet);
|
||||
apiClient_free(apiClient2);
|
||||
|
||||
// Pet upload file Test
|
||||
apiClient_t *apiClient3 = apiClient_create();
|
||||
FILE *file = fopen("/opt/image.png", "r");
|
||||
char *buff;
|
||||
int read_size, len;
|
||||
binary_t *data = malloc(sizeof(binary_t));
|
||||
if(file) {
|
||||
fseek(file, 0, SEEK_END);
|
||||
read_size = 2 * ftell(file);
|
||||
rewind(file);
|
||||
data->data = (char *) malloc(read_size + 1);
|
||||
data->len = fread((void *) data->data, 1, read_size, file);
|
||||
data->data[read_size] = '\0';
|
||||
}
|
||||
if(file != NULL) {
|
||||
api_response_t *respo = PetAPI_uploadFile(apiClient3,
|
||||
EXAMPLE_PET_ID,
|
||||
"dec",
|
||||
file);
|
||||
data);
|
||||
|
||||
api_response_free(respo);
|
||||
free(data->data);
|
||||
free(data);
|
||||
fclose(file);
|
||||
} else {
|
||||
apiClient_free(apiClient3);
|
||||
}
|
||||
}
|
||||
apiClient_free(apiClient3);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "apiClient.h"
|
||||
#include "cJSON.h"
|
||||
#include "order.h"
|
||||
#include "StoreAPI.h"
|
||||
#include "keyValuePair.h"
|
||||
#include "../api/StoreAPI.h"
|
||||
|
||||
|
||||
#define ORDER_ID 1234
|
||||
#define PET_ID 12345
|
||||
@@ -44,6 +41,7 @@ int main() {
|
||||
order_free(returnorder);
|
||||
cJSON_Delete(JSONNODE);
|
||||
free(dataToPrint);
|
||||
apiClient_free(apiClient);
|
||||
|
||||
// order get by id test
|
||||
apiClient_t *apiClient2 = apiClient_create();
|
||||
@@ -59,6 +57,7 @@ int main() {
|
||||
order_free(neworder);
|
||||
cJSON_Delete(JSONNODE);
|
||||
free(dataToPrint1);
|
||||
apiClient_free(apiClient2);
|
||||
|
||||
// delete order test
|
||||
apiClient_t *apiClient3 = apiClient_create();
|
||||
@@ -70,6 +69,7 @@ int main() {
|
||||
|
||||
printf("Order Deleted \n");
|
||||
free(orderid);
|
||||
apiClient_free(apiClient3);
|
||||
|
||||
|
||||
// get order by id test
|
||||
@@ -80,21 +80,24 @@ int main() {
|
||||
if(neworder == NULL) {
|
||||
printf("Order Not present \n");
|
||||
}
|
||||
order_free(neworder);
|
||||
apiClient_free(apiClient4);
|
||||
|
||||
// get inventory test
|
||||
apiClient_t *apiClient5 = apiClient_create();
|
||||
list_t *elementToReturn;
|
||||
elementToReturn = StoreAPI_getInventory(apiClient5);
|
||||
listEntry_t *listEntry;
|
||||
list_ForEach(listEntry, elementToReturn) {
|
||||
keyValuePair_t *pair = (keyValuePair_t*)listEntry->data;
|
||||
printf("%s - %s\n",pair->key,pair->value );
|
||||
}
|
||||
list_ForEach(listEntry, elementToReturn) {
|
||||
keyValuePair_t *pair = (keyValuePair_t*)listEntry->data;
|
||||
free(pair->key);
|
||||
free(pair->value);
|
||||
keyValuePair_free(pair);
|
||||
keyValuePair_t *pair = (keyValuePair_t *) listEntry->data;
|
||||
printf("%s - %s\n", pair->key, (char *) pair->value);
|
||||
}
|
||||
list_ForEach(listEntry, elementToReturn) {
|
||||
keyValuePair_t *pair = (keyValuePair_t *) listEntry->data;
|
||||
free(pair->key);
|
||||
free(pair->value);
|
||||
keyValuePair_free(pair);
|
||||
}
|
||||
list_free(elementToReturn);
|
||||
apiClient_free(apiClient5);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "apiClient.h"
|
||||
#include "cJSON.h"
|
||||
#include "keyValuePair.h"
|
||||
#include "user.h"
|
||||
#include "UserAPI.h"
|
||||
#include "../api/UserAPI.h"
|
||||
|
||||
#define USER_ID 1234
|
||||
#define USER_NAME "example123"
|
||||
@@ -47,6 +43,7 @@ int main() {
|
||||
|
||||
UserAPI_createUser(apiClient, newuser);
|
||||
user_free(newuser);
|
||||
apiClient_free(apiClient);
|
||||
|
||||
// get user by name test
|
||||
apiClient_t *apiClient1 = apiClient_create();
|
||||
@@ -60,6 +57,7 @@ int main() {
|
||||
user_free(returnUser);
|
||||
cJSON_Delete(JSONNODE);
|
||||
free(dataToPrint);
|
||||
apiClient_free(apiClient1);
|
||||
|
||||
// update user test
|
||||
{
|
||||
@@ -88,6 +86,7 @@ int main() {
|
||||
|
||||
UserAPI_updateUser(apiClient2, username1, newuser1);
|
||||
user_free(newuser1);
|
||||
apiClient_free(apiClient2);
|
||||
}
|
||||
|
||||
// login user test
|
||||
@@ -106,16 +105,19 @@ int main() {
|
||||
free(loginuserreturn);
|
||||
free(username1);
|
||||
free(password);
|
||||
apiClient_free(apiClient3);
|
||||
}
|
||||
|
||||
// logout user test
|
||||
apiClient_t *apiClient4 = apiClient_create();
|
||||
|
||||
UserAPI_logoutUser(apiClient4);
|
||||
apiClient_free(apiClient4);
|
||||
|
||||
|
||||
// delete user test
|
||||
apiClient_t *apiClient5 = apiClient_create();
|
||||
|
||||
UserAPI_deleteUser(apiClient5, "example123");
|
||||
apiClient_free(apiClient5);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "cJSON.h"
|
||||
#include "order.h"
|
||||
#include "../model/order.h"
|
||||
|
||||
|
||||
#define ORDER_ID 1234
|
||||
@@ -25,7 +24,7 @@ int main() {
|
||||
|
||||
printf("Created Order is: \n%s\n", dataToPrint);
|
||||
|
||||
order_t *parsedOrder = order_parseFromJSON(dataToPrint);
|
||||
order_t *parsedOrder = order_parseFromJSON(JSONNODE);
|
||||
|
||||
cJSON *fromJSON = order_convertToJSON(parsedOrder);
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "cJSON.h"
|
||||
#include "user.h"
|
||||
#include "../model/user.h"
|
||||
|
||||
|
||||
#define USER_ID 1234
|
||||
@@ -25,7 +24,7 @@ int main() {
|
||||
|
||||
printf("Created User is: \n%s\n", dataToPrint);
|
||||
|
||||
user_t *pasrsedUser = user_parseFromJSON(dataToPrint);
|
||||
user_t *pasrsedUser = user_parseFromJSON(JSONNODE);
|
||||
|
||||
cJSON *fromJSON = user_convertToJSON(pasrsedUser);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user