Skip to content

Commit fa1e003

Browse files
authored
minor enhancement to c client generaotr (#4457)
1 parent 440e3f3 commit fa1e003

10 files changed

Lines changed: 34 additions & 25 deletions

File tree

modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,14 @@ set(HDRS "")
7373
## This section shows how to use the above compiled libary to compile the source files
7474
## set source files
7575
#set(SRCS
76-
# unit-tests/manual-PetAPI.c
77-
# unit-tests/manual-StoreAPI.c
78-
# unit-tests/manual-UserAPI.c
79-
# unit-tests/manual-order.c
80-
# unit-tests/manual-user.c)
76+
{{#apiInfo}}
77+
{{#apis}}
78+
{{#operations}}
79+
# unit-tests/manual-{{classname}}.c
80+
{{/operations}}
81+
{{/apis}}
82+
{{/apiInfo}}
83+
#)
8184

8285
##set header files
8386
#set(HDRS

modules/openapi-generator/src/main/resources/C-libcurl/README.md.mustache

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
1414
{{/infoUrl}}
1515

1616
## Installation
17-
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.
17+
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.
1818

1919
# Prerequisites
2020

@@ -40,11 +40,11 @@ sudo make install
4040
```
4141

4242
## Compile the sample:
43-
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.
43+
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.
4444
```bash
4545
mkdir build
4646
cd build
47-
// To install library to specific location use following command
47+
// To install library to specific location, use following commands
4848
cmake -DCMAKE_INSTALL_PREFIX=/pathtolocaiton ..
4949
// for normal install use following command
5050
cmake ..
@@ -58,11 +58,11 @@ To compile main.c(considering the file is present in build folder) use following
5858
-L - locaiton of the library(not required if cmake with normal installation is performed)
5959
-l library name
6060
```bash
61-
gcc main.c -L. -lpetstore -o main
61+
gcc main.c -L. -l{{projectName}} -o main
6262
```
63-
once compile, you can run it with ``` ./main ```
63+
Once compiled, you can run it with ``` ./main ```
6464

65-
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.
65+
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.
6666

6767
## Author
6868

samples/client/petstore/c/.openapi-generator-ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121
#docs/*.md
2222
# Then explicitly reverse the ignore rule for a single file:
2323
#!docs/README.md
24+
CMakeLists.txt
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.0-SNAPSHOT
1+
4.2.1-SNAPSHOT

samples/client/petstore/c/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ set(HDRS
5252

5353
)
5454

55+
# Add library with project file with projectname as library name
5556
add_library(${pkgName} SHARED ${SRCS} ${HDRS})
57+
# Link dependent libraries
5658
target_link_libraries(${pkgName} ${CURL_LIBRARIES} )
59+
#install library to destination
5760
install(TARGETS ${pkgName} DESTINATION ${CMAKE_INSTALL_PREFIX})
5861

62+
# Setting file variables to null
5963
set(SRCS "")
6064
set(HDRS "")
6165

samples/client/petstore/c/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
88
- Build package: org.openapitools.codegen.languages.CLibcurlClientCodegen
99

1010
## Installation
11-
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.
11+
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.
1212

1313
# Prerequisites
1414

@@ -34,11 +34,11 @@ sudo make install
3434
```
3535

3636
## Compile the sample:
37-
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.
37+
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.
3838
```bash
3939
mkdir build
4040
cd build
41-
// To install library to specific location use following command
41+
// To install library to specific location, use following commands
4242
cmake -DCMAKE_INSTALL_PREFIX=/pathtolocaiton ..
4343
// for normal install use following command
4444
cmake ..
@@ -52,11 +52,11 @@ To compile main.c(considering the file is present in build folder) use following
5252
-L - locaiton of the library(not required if cmake with normal installation is performed)
5353
-l library name
5454
```bash
55-
gcc main.c -L. -lpetstore -o main
55+
gcc main.c -L. -lopenapi_petstore -o main
5656
```
57-
once compile, you can run it with ``` ./main ```
57+
Once compiled, you can run it with ``` ./main ```
5858

59-
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.
59+
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.
6060

6161
## Author
6262

samples/client/petstore/c/api/PetAPI.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ pet_t *PetAPI_getPetById(apiClient_t *apiClient, long petId) {
351351
// nonprimitive not container
352352
cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
353353
pet_t *elementToReturn = pet_parseFromJSON(PetAPIlocalVarJSON);
354-
cJSON_Delete(PetAPIlocalVarJSON);
354+
cJSON_Delete(PetAPIlocalVarJSON);
355355
if(elementToReturn == NULL) {
356356
// return 0;
357357
}
@@ -606,7 +606,7 @@ api_response_t *PetAPI_uploadFile(apiClient_t *apiClient, long petId,
606606
cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
607607
api_response_t *elementToReturn = api_response_parseFromJSON(
608608
PetAPIlocalVarJSON);
609-
cJSON_Delete(PetAPIlocalVarJSON);
609+
cJSON_Delete(PetAPIlocalVarJSON);
610610
if(elementToReturn == NULL) {
611611
// return 0;
612612
}

samples/client/petstore/c/api/StoreAPI.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ list_t *StoreAPI_getInventory(apiClient_t *apiClient) {
111111
list_t *elementToReturn = list_create();
112112
cJSON_ArrayForEach(VarJSON, localVarJSON) {
113113
keyValuePair_t *keyPair =
114-
keyValuePair_create(strdup(VarJSON->string), cJSON_Print(
114+
keyValuePair_create(strdup(
115+
VarJSON->string), cJSON_Print(
115116
VarJSON));
116117
list_addElement(elementToReturn, keyPair);
117118
}
@@ -191,7 +192,7 @@ order_t *StoreAPI_getOrderById(apiClient_t *apiClient, long orderId) {
191192
// nonprimitive not container
192193
cJSON *StoreAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
193194
order_t *elementToReturn = order_parseFromJSON(StoreAPIlocalVarJSON);
194-
cJSON_Delete(StoreAPIlocalVarJSON);
195+
cJSON_Delete(StoreAPIlocalVarJSON);
195196
if(elementToReturn == NULL) {
196197
// return 0;
197198
}
@@ -259,7 +260,7 @@ order_t *StoreAPI_placeOrder(apiClient_t *apiClient, order_t *body) {
259260
// nonprimitive not container
260261
cJSON *StoreAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
261262
order_t *elementToReturn = order_parseFromJSON(StoreAPIlocalVarJSON);
262-
cJSON_Delete(StoreAPIlocalVarJSON);
263+
cJSON_Delete(StoreAPIlocalVarJSON);
263264
if(elementToReturn == NULL) {
264265
// return 0;
265266
}

samples/client/petstore/c/api/UserAPI.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ user_t *UserAPI_getUserByName(apiClient_t *apiClient, char *username) {
331331
// nonprimitive not container
332332
cJSON *UserAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
333333
user_t *elementToReturn = user_parseFromJSON(UserAPIlocalVarJSON);
334-
cJSON_Delete(UserAPIlocalVarJSON);
334+
cJSON_Delete(UserAPIlocalVarJSON);
335335
if(elementToReturn == NULL) {
336336
// return 0;
337337
}

samples/client/petstore/c/src/apiClient.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ apiClient_t *apiClient_create() {
2222
}
2323

2424
void apiClient_free(apiClient_t *apiClient) {
25-
if(apiClient->apiKeys) {
25+
if(apiClient->accessToken) {
2626
list_free(apiClient->apiKeys);
2727
}
2828
if(apiClient->accessToken) {

0 commit comments

Comments
 (0)