9898// { {{.} }}
9999//
100100{ {/notes} }
101- { {#returnType} }{ {#returnTypeIsPrimitive} }{ {#returnSimpleType} }{ {{.} }}* { {/returnSimpleType} }{ {^returnSimpleType} }{ {#isArray} }{ {{.} }}_t*{ {/isArray} }{ {#isMap} }{ {{.} }}{ {/isMap} }{ {/returnSimpleType} }{ {/returnTypeIsPrimitive} }{ {^returnTypeIsPrimitive} }{ {#returnProperty} }{ {^isEnum} }{ {{returnType} }}_t*{ {/isEnum} }{ {#isEnum} }{ {projectName} }_{ {{returnType} }}_{ {returnEnumName} }_e{ {/isEnum} }{ {/returnProperty} }{ {/returnTypeIsPrimitive} }{ {/returnType} }{ {^returnType} }void{ {/returnType} }
101+ { {#returnType} }{ {#returnTypeIsPrimitive} }{ {#returnSimpleType} }{ {{.} }}{ {#returnProperty } } { {#isString } }* { {/isString } } { {/returnProperty } } { {/returnSimpleType} }{ {^returnSimpleType} }{ {#isArray} }{ {{.} }}_t*{ {/isArray} }{ {#isMap} }{ {{.} }}{ {/isMap} }{ {/returnSimpleType} }{ {/returnTypeIsPrimitive} }{ {^returnTypeIsPrimitive} }{ {#returnProperty} }{ {^isEnum} }{ {{returnType} }}_t*{ {/isEnum} }{ {#isEnum} }{ {projectName} }_{ {{returnType} }}_{ {returnEnumName} }_e{ {/isEnum} }{ {/returnProperty} }{ {/returnTypeIsPrimitive} }{ {/returnType} }{ {^returnType} }void{ {/returnType} }
102102{{{classname}}}_{{{operationId}}}(apiClient_t *apiClient{{#allParams}}, {{#isPrimitiveType}}{{#isNumber}}{{{dataType}}} {{/isNumber}}{{#isLong}}{{{dataType}}} {{/isLong}}{{#isInteger}}{{{dataType}}} *{{/isInteger}}{{#isDouble}}{{{dataType}}} {{/isDouble}}{{#isFloat}}{{{dataType}}} {{/isFloat}}{{#isBoolean}}{{dataType}} *{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e {{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}} *{{/isByteArray}}{{#isDate}}{{{dataType}}} {{/isDate}}{{#isDateTime}}{{{dataType}}} {{/isDateTime}}{{#isFile}}{{{dataType}}} {{/isFile}}{{#isFreeFormObject}}{{dataType}}_t *{{/isFreeFormObject}}{{/isPrimitiveType}}{{^isArray}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e {{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e {{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}} {{/isEmail}}{{/isPrimitiveType}}{{/isArray}}{{#isContainer}}{{#isArray}}{{dataType}}_t *{{/isArray}}{{#isMap}}{{dataType}} {{/isMap}}{{/isContainer}}{{{paramName}}}{{/allParams}})
103103{
104104 list_t *localVarQueryParameters = {{#hasQueryParams} }list_createList();{ {/hasQueryParams} }{ {^hasQueryParams} }NULL;{ {/hasQueryParams} }
@@ -108,11 +108,21 @@ end:
108108 list_t *localVarContentType = { {#hasConsumes} }list_createList();{ {/hasConsumes} }{ {^hasConsumes} }NULL;{ {/hasConsumes} }
109109 char *localVarBodyParameters = NULL;
110110
111+ // clear the error code from the previous api call
112+ apiClient->response_code = 0;
113+
111114 // create the path
112115 long sizeOfPath = strlen("{ {{path} }}")+1;
113116 char *localVarPath = malloc(sizeOfPath);
114117 snprintf(localVarPath, sizeOfPath, "{ {{path} }}");
115118
119+ { {#pathParams} }
120+ { {#isString} }
121+ if(!{ {paramName} })
122+ goto end;
123+ { {/isString} }
124+ { {/pathParams} }
125+
116126 { {#pathParams} }
117127
118128 // Path Params
@@ -363,51 +373,80 @@ end:
363373 { {#returnType} }
364374 { {#returnTypeIsPrimitive} }
365375 { {#returnSimpleType} }
366- //primitive return type simple
367- { {returnType} }* elementToReturn = strdup(({ {returnType} }*)apiClient->dataReceived);
376+ { {#returnProperty} }
377+ { {#isBinary} }
378+ //primitive return type simple binary
379+ { {returnType} } elementToReturn = NULL;
380+ if(apiClient->response_code >= 200 && apiClient->response_code < 300)
381+ elementToReturn = instantiate_binary_t(apiClient->dataReceived, apiClient->dataReceivedLen);
382+
383+ { {/isBinary} }
384+ { {#isString} }
385+ //primitive return type simple string
386+ { {returnType} }* elementToReturn = NULL;
387+ if(apiClient->response_code >= 200 && apiClient->response_code < 300)
388+ elementToReturn = strdup(({ {returnType} }*)apiClient->dataReceived);
368389
390+ { {/isString} }
391+ { {#isInteger} }
392+ //primitive return type simple integer
393+ { {returnType} } elementToReturn = 0;
394+ if(apiClient->response_code >= 200 && apiClient->response_code < 300)
395+ elementToReturn = atoi(apiClient->dataReceived);
396+
397+ { {/isInteger} }
398+ { {/returnProperty} }
369399 { {/returnSimpleType} }
370400 { {^returnSimpleType} }
371401 //primitive return type not simple
372- cJSON *{ {paramName} }localVarJSON = cJSON_Parse(apiClient->dataReceived);
373- cJSON *{ {{paramName} }}VarJSON;
374- list_t *elementToReturn = list_createList();
375- cJSON_ArrayForEach({ {{paramName} }}VarJSON, { {paramName} }localVarJSON){
376- keyValuePair_t *keyPair = keyValuePair_create(strdup({{{paramName} }}VarJSON->string), { {{cJSONPrint} }}({ {{paramName} }}VarJSON));
377- list_addElement(elementToReturn, keyPair);
402+ list_t *elementToReturn = NULL;
403+ if(apiClient->response_code >= 200 && apiClient->response_code < 300) {
404+ cJSON *{{paramName} }localVarJSON = cJSON_Parse(apiClient->dataReceived);
405+ cJSON *{ {{paramName} }}VarJSON;
406+ elementToReturn = list_createList();
407+ cJSON_ArrayForEach({ {{paramName} }}VarJSON, { {paramName} }localVarJSON){
408+ keyValuePair_t *keyPair = keyValuePair_create(strdup({{{paramName} }}VarJSON->string), { {{cJSONPrint} }}({ {{paramName} }}VarJSON));
409+ list_addElement(elementToReturn, keyPair);
410+ }
411+ cJSON_Delete({ {paramName} }localVarJSON);
378412 }
379- cJSON_Delete({ {paramName} }localVarJSON);
380413
381414 { {/returnSimpleType} }
382415 { {/returnTypeIsPrimitive} }
383416 { {^returnTypeIsPrimitive} }
384417 { {#returnContainer} }
385- cJSON * { {classname } }localVarJSON = cJSON_Parse(apiClient->dataReceived) ;
386- if(!cJSON_IsArray( { {classname } }localVarJSON) ) {
387- return 0;//nonprimitive container
388- }
389- list_t *elementToReturn = list_createList();
390- cJSON * { {{paramName } }}VarJSON;
391- cJSON_ArrayForEach( { {{paramName } }}VarJSON, { {classname } }localVarJSON)
392- {
393- if ( ! cJSON_IsObject( {{{paramName} }}VarJSON) )
418+ list_t *elementToReturn = NULL ;
419+ if(apiClient->response_code >= 200 && apiClient->response_code < 300 ) {
420+ cJSON *{{classname } }localVarJSON = cJSON_Parse(apiClient->dataReceived);
421+ if(!cJSON_IsArray( { {classname } }localVarJSON)) {
422+ return 0;//nonprimitive container
423+ }
424+ elementToReturn = list_createList();
425+ cJSON * { {{paramName } }}VarJSON;
426+ cJSON_ArrayForEach( { {{paramName} }}VarJSON, { {classname } }localVarJSON )
394427 {
395- // return 0;
428+ if (! cJSON_IsObject({{{paramName} }}VarJSON))
429+ {
430+ // return 0;
431+ }
432+ char *localVarJSONToChar = { {{cJSONPrint} }}({ {{paramName} }}VarJSON);
433+ list_addElement(elementToReturn , localVarJSONToChar);
396434 }
397- char *localVarJSONToChar = { {{cJSONPrint} }}({ {{paramName} }}VarJSON);
398- list_addElement(elementToReturn , localVarJSONToChar);
399- }
400435
401- cJSON_Delete( { {classname} }localVarJSON);
402- cJSON_Delete( { {{paramName} }}VarJSON);
436+ cJSON_Delete( { {classname} }localVarJSON);
437+ cJSON_Delete( { {{paramName} }}VarJSON);
438+ }
403439 { {/returnContainer} }
404440 { {^returnContainer} }
405441 //nonprimitive not container
406- cJSON *{ {classname} }localVarJSON = cJSON_Parse(apiClient->dataReceived);
407- { {#returnProperty} }{ {^isEnum} }{ {{returnBaseType} }}_t *{ {/isEnum} }{ {#isEnum} }{ {projectName} }_{ {{returnType} }}_{ {returnEnumName} }_e { {/isEnum} }{ {/returnProperty} }elementToReturn = { {{returnBaseType} }}_parseFromJSON({ {classname} }localVarJSON);
408- cJSON_Delete({ {classname} }localVarJSON);
409- if(elementToReturn == { {#returnProperty} }{ {^isEnum} }NULL{ {/isEnum} }{ {#isEnum} }0{ {/isEnum} }{ {/returnProperty} }) {
410- // return 0;
442+ { {#returnProperty} }{ {^isEnum} }{ {{returnBaseType} }}_t *{ {/isEnum} }{ {#isEnum} }{ {projectName} }_{ {{returnType} }}_{ {returnEnumName} }_e { {/isEnum} }{ {/returnProperty} }elementToReturn = { {#returnProperty} }{ {^isEnum} }NULL{ {/isEnum} }{ {#isEnum} }0{ {/isEnum} }{ {/returnProperty} };
443+ if(apiClient->response_code >= 200 && apiClient->response_code < 300) {
444+ cJSON *{{classname} }localVarJSON = cJSON_Parse(apiClient->dataReceived);
445+ elementToReturn = { {{returnBaseType} }}_parseFromJSON({ {classname} }localVarJSON);
446+ cJSON_Delete({ {classname} }localVarJSON);
447+ if(elementToReturn == { {#returnProperty} }{ {^isEnum} }NULL{ {/isEnum} }{ {#isEnum} }0{ {/isEnum} }{ {/returnProperty} }) {
448+ // return 0;
449+ }
411450 }
412451
413452 { {/returnContainer} }
550589 return elementToReturn;
551590end:
552591 free(localVarPath);
553- return { {#returnProperty} }{ {^ isEnum} }NULL{ {/isEnum} }{ {#isEnum} }0{ {/isEnum} }{ {/returnProperty} };
592+ return { {#returnProperty} }{ {#isInteger } }0 { {/isInteger } } { {^isInteger } } { {^ isEnum} }NULL{ {/isEnum} }{ {#isEnum} }0{ {/isEnum} } { {/isInteger } }{ {/returnProperty} };
554593 { {/returnType} }
555594 { {^returnType} }
556595 //No return type
0 commit comments