minor enhancement to c client generaotr (#4457)

This commit is contained in:
William Cheng 2019-11-13 13:34:31 +08:00 committed by GitHub
parent 440e3f301d
commit fa1e003a3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 34 additions and 25 deletions

View File

@ -73,11 +73,14 @@ set(HDRS "")
## This section shows how to use the above compiled libary to compile the source files ## This section shows how to use the above compiled libary to compile the source files
## set source files ## set source files
#set(SRCS #set(SRCS
# unit-tests/manual-PetAPI.c {{#apiInfo}}
# unit-tests/manual-StoreAPI.c {{#apis}}
# unit-tests/manual-UserAPI.c {{#operations}}
# unit-tests/manual-order.c # unit-tests/manual-{{classname}}.c
# unit-tests/manual-user.c) {{/operations}}
{{/apis}}
{{/apiInfo}}
#)
##set header files ##set header files
#set(HDRS #set(HDRS

View File

@ -14,7 +14,7 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}} {{/infoUrl}}
## Installation ## Installation
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. 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 or later.
# Prerequisites # Prerequisites
@ -40,11 +40,11 @@ sudo make install
``` ```
## Compile the sample: ## 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. This will compile the generated code and create a library in the build folder which has to be linked to the codes where API will be used.
```bash ```bash
mkdir build mkdir build
cd build cd build
// To install library to specific location use following command // To install library to specific location, use following commands
cmake -DCMAKE_INSTALL_PREFIX=/pathtolocaiton .. cmake -DCMAKE_INSTALL_PREFIX=/pathtolocaiton ..
// for normal install use following command // for normal install use following command
cmake .. cmake ..
@ -58,11 +58,11 @@ To compile main.c(considering the file is present in build folder) use following
-L - locaiton of the library(not required if cmake with normal installation is performed) -L - locaiton of the library(not required if cmake with normal installation is performed)
-l library name -l library name
```bash ```bash
gcc main.c -L. -lpetstore -o main gcc main.c -L. -l{{projectName}} -o main
``` ```
once compile, you can run it with ``` ./main ``` Once compiled, 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. Note: You don't 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 ## Author

View File

@ -21,3 +21,4 @@
#docs/*.md #docs/*.md
# Then explicitly reverse the ignore rule for a single file: # Then explicitly reverse the ignore rule for a single file:
#!docs/README.md #!docs/README.md
CMakeLists.txt

View File

@ -1 +1 @@
4.0.0-SNAPSHOT 4.2.1-SNAPSHOT

View File

@ -52,10 +52,14 @@ set(HDRS
) )
# Add library with project file with projectname as library name
add_library(${pkgName} SHARED ${SRCS} ${HDRS}) add_library(${pkgName} SHARED ${SRCS} ${HDRS})
# Link dependent libraries
target_link_libraries(${pkgName} ${CURL_LIBRARIES} ) target_link_libraries(${pkgName} ${CURL_LIBRARIES} )
#install library to destination
install(TARGETS ${pkgName} DESTINATION ${CMAKE_INSTALL_PREFIX}) install(TARGETS ${pkgName} DESTINATION ${CMAKE_INSTALL_PREFIX})
# Setting file variables to null
set(SRCS "") set(SRCS "")
set(HDRS "") set(HDRS "")

View File

@ -8,7 +8,7 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
- Build package: org.openapitools.codegen.languages.CLibcurlClientCodegen - Build package: org.openapitools.codegen.languages.CLibcurlClientCodegen
## Installation ## Installation
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. 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 or later.
# Prerequisites # Prerequisites
@ -34,11 +34,11 @@ sudo make install
``` ```
## Compile the sample: ## 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. This will compile the generated code and create a library in the build folder which has to be linked to the codes where API will be used.
```bash ```bash
mkdir build mkdir build
cd build cd build
// To install library to specific location use following command // To install library to specific location, use following commands
cmake -DCMAKE_INSTALL_PREFIX=/pathtolocaiton .. cmake -DCMAKE_INSTALL_PREFIX=/pathtolocaiton ..
// for normal install use following command // for normal install use following command
cmake .. cmake ..
@ -52,11 +52,11 @@ To compile main.c(considering the file is present in build folder) use following
-L - locaiton of the library(not required if cmake with normal installation is performed) -L - locaiton of the library(not required if cmake with normal installation is performed)
-l library name -l library name
```bash ```bash
gcc main.c -L. -lpetstore -o main gcc main.c -L. -lopenapi_petstore -o main
``` ```
once compile, you can run it with ``` ./main ``` Once compiled, 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. Note: You don't 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 ## Author

View File

@ -111,7 +111,8 @@ list_t *StoreAPI_getInventory(apiClient_t *apiClient) {
list_t *elementToReturn = list_create(); list_t *elementToReturn = list_create();
cJSON_ArrayForEach(VarJSON, localVarJSON) { cJSON_ArrayForEach(VarJSON, localVarJSON) {
keyValuePair_t *keyPair = keyValuePair_t *keyPair =
keyValuePair_create(strdup(VarJSON->string), cJSON_Print( keyValuePair_create(strdup(
VarJSON->string), cJSON_Print(
VarJSON)); VarJSON));
list_addElement(elementToReturn, keyPair); list_addElement(elementToReturn, keyPair);
} }

View File

@ -22,7 +22,7 @@ apiClient_t *apiClient_create() {
} }
void apiClient_free(apiClient_t *apiClient) { void apiClient_free(apiClient_t *apiClient) {
if(apiClient->apiKeys) { if(apiClient->accessToken) {
list_free(apiClient->apiKeys); list_free(apiClient->apiKeys);
} }
if(apiClient->accessToken) { if(apiClient->accessToken) {