Skip to content

Commit 86c5e7b

Browse files
zhemantwing328
authored andcommitted
[C] Function addition and modification of major structs (#1020)
* added readme file * fixed parameters in api headers functions * made changes to add readme file and typemapping of array to list * fixed header import statement in apiheader files * modified struct of model type in model header * updated sample * modified README file * updated sample * parse from json function added * modified struct and create function * added include for model * modified parsefromjson function * modified struct and create function for more datatypes * added mapping for date-time and modified model import return statement * modified function parameters * modified include statement * fix function in api body * updated sample
1 parent e84ea25 commit 86c5e7b

33 files changed

+1132
-415
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ public CLibcurlClientCodegen() {
144144
typeMapping.put("binary", "char");
145145
typeMapping.put("ByteArray", "char");
146146
typeMapping.put("UUID", "char");
147-
147+
typeMapping.put("array", "list");
148+
typeMapping.put("date-time", "char");
149+
148150
// remove modelPackage and apiPackage added by default
149151
Iterator<CliOption> itr = cliOptions.iterator();
150152
while (itr.hasNext()) {
@@ -179,6 +181,7 @@ public void processOpts() {
179181
supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", "", "CMakeLists.txt"));
180182
supportingFiles.add(new SupportingFile("libcurl.licence.mustache", "", "libcurl.licence"));
181183
supportingFiles.add(new SupportingFile("uncrustify-rules.cfg.mustache", "", "uncrustify-rules.cfg"));
184+
supportingFiles.add(new SupportingFile("README.md.mustache", "", "README.md"));
182185
// src folder
183186
supportingFiles.add(new SupportingFile("apiClient.c.mustache", "src", "apiClient.c"));
184187
supportingFiles.add(new SupportingFile("apiKey.c.mustache", "src", "apiKey.c"));
@@ -485,6 +488,11 @@ public String toOperationId(String operationId) {
485488
public String toApiImport(String name) {
486489
return apiPackage() + "/" + toApiFilename(name);
487490
}
491+
492+
@Override
493+
public String toModelImport(String name) {
494+
return "#include \"" + name + ".h\"";
495+
}
488496

489497
@Override
490498
public void setParameterExampleValue(CodegenParameter p) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(ALL_SRC_LIST ${SRC_C} ${UNIT_TESTS_C} ${MODEL_C} ${API_C})
1111
include(CTest)
1212
include_directories(include)
1313
include_directories(external/include)
14+
include_directories(model)
1415

1516
find_program(VALGRIND valgrind)
1617
if(VALGRIND)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# C API client for {{{projectName}}}
2+
3+
## Overview
4+
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.
5+
6+
- API version: {{appVersion}}
7+
- Package version: {{packageVersion}}
8+
{{^hideGenerationTimestamp}}
9+
- Build date: {{generatedDate}}
10+
{{/hideGenerationTimestamp}}
11+
- Build package: {{generatorClass}}
12+
{{#infoUrl}}
13+
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
14+
{{/infoUrl}}
15+
16+
## Installation
17+
You'll need the `curl 7.61` package in order to build the API.
18+
19+
### Prerequisites
20+
Install the `curl 7.61` package with the following command on Linux.
21+
```C
22+
sudo apt remove curl
23+
wget http://curl.haxx.se/download/curl-7.60.0.tar.gz
24+
tar -xvf curl-7.61.0.tar.gz
25+
cd curl-7.61.0/
26+
./configure
27+
make
28+
sudo make install
29+
```
30+
31+
32+
## Author
33+
34+
{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}}
35+
{{/hasMore}}{{/apis}}{{/apiInfo}}

modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#include <stdio.h>
33
#include "apiClient.h"
44
#include "cJSON.h"
5-
{{#imports}}
6-
#include "{{{import}}}.h" // TODO will fix the import later
5+
{{#imports}}{{{import}}}
76
{{/imports}}
87

98
#define MAX_BUFFER_LENGTH 4096
@@ -23,7 +22,7 @@
2322
// {{{notes}}}
2423
//
2524
{{/notes}}
26-
{{#returnType}}{{{.}}}_t{{/returnType}}{{^returnType}}void{{/returnType}} *{{{classname}}}_{{{operationId}}}(apiClient_t *apiClient{{#allParams}}, {{{dataType}}} {{paramName}}{{/allParams}}) {
25+
{{#returnType}}{{{.}}}_t{{/returnType}}{{^returnType}}void{{/returnType}} *{{{classname}}}_{{{operationId}}}(apiClient_t *apiClient{{#allParams}}, {{{dataType}}}{{#isListContainer}}_t*{{/isListContainer}}{{^isListContainer}}{{#isPrimitiveType}}{{#isString}}*{{/isString}}{{/isPrimitiveType}}{{^isPrimitiveType}}_t*{{/isPrimitiveType}}{{/isListContainer}} {{paramName}}{{/allParams}}) {
2726
list_t *localVarQueryParameters,
2827
list_t *localVarHeaderParameters,
2928
list_t *localVarFormParameters,
@@ -89,7 +88,7 @@
8988
{{/bodyParam}}
9089
{{#bodyParam}}
9190
free(localVarBodyParameters);
92-
cJSON_Delete()
91+
cJSON_Delete({{{paramName}}}JSONObject);
9392
{{/bodyParam}}
9493
{{/allParams}}
9594
{{#returnType}}

modules/openapi-generator/src/main/resources/C-libcurl/api-header.mustache

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#include <stdio.h>
33
#include "apiClient.h"
44
#include "cJSON.h"
5-
{{#imports}}
6-
#include "{{{import}}}.h" // TODO will fix the import later
5+
{{#imports}}{{{import}}}
76
{{/imports}}
87

8+
99
{{#operations}}
1010
{{#operation}}
1111
{{#summary}}
@@ -16,10 +16,7 @@
1616
// {{{notes}}}
1717
//
1818
{{/notes}}
19-
{{#returnType}}{{{.}}}_t{{/returnType}}{{^returnType}}void{{/returnType}} *{{{classname}}}_{{{operationId}}}(apiClient_t *apiClient{{#allParams}}, {{{dataType}}} {{paramName}}{{/allParams}})
20-
21-
22-
19+
{{#returnType}}{{{.}}}_t{{/returnType}}{{^returnType}}void{{/returnType}} *{{{classname}}}_{{{operationId}}}(apiClient_t *apiClient{{#allParams}},{{{dataType}}}{{#isListContainer}}_t*{{/isListContainer}}{{^isListContainer}}{{#isPrimitiveType}}{{#isString}}*{{/isString}}{{/isPrimitiveType}}{{^isPrimitiveType}}_t*{{/isPrimitiveType}}{{/isListContainer}} {{paramName}}{{/allParams}});
2320

2421
{{/operation}}
2522
{{/operations}}

modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include <stdlib.h>
33
#include <string.h>
44
#include "apiClient.h"
5-
#include "apiKey.h"
6-
#include "model/pet.h" //TODO: Manual Path check if its ok
5+
#include "keyValuePair.h"
6+
#include "pet.h" //TODO: Manual Path check if its ok
77

88
size_t writeDataCallback(void *buffer, size_t size, size_t nmemb, void *userp);
99

0 commit comments

Comments
 (0)