Skip to content

Commit 1594b90

Browse files
committed
add option to fallback to non-pointe number, boolean
1 parent d8afb22 commit 1594b90

11 files changed

Lines changed: 57 additions & 23 deletions

File tree

bin/configs/c-useJsonUnformatted.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ inputSpec: modules/openapi-generator/src/test/resources/2_0/c/petstore.yaml
44
templateDir: modules/openapi-generator/src/main/resources/C-libcurl
55
additionalProperties:
66
useJsonUnformatted: true
7+
declareNumberBooleanWithoutPointer: true
78
modelNameMappings:
89
another_model: MappedModel
910
another_property: mappedProperty

docs/generators/c.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
1919
| Option | Description | Values | Default |
2020
| ------ | ----------- | ------ | ------- |
2121
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
22+
|declareNumberBooleanWithoutPointer|Declare number, boolean types without pointer using model-body, model-header templates from OpenAPI Generator v7.20.0.| |false|
2223
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
2324
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
2425
|enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|<dl><dt>**false**</dt><dd>No changes to the enum's are made, this is the default option.</dd><dt>**true**</dt><dd>With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.</dd></dl>|false|

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
4141
public static final String USE_JSON_UNFORMATTED = "useJsonUnformatted";
4242
public static final String USE_JSON_UNFORMATTED_DESC = "Use cJSON_PrintUnformatted instead of cJSON_Print when creating the JSON string.";
4343

44+
public static final String DECLARE_NUMBER_BOOLEAN_WITHOUT_POINTER = "declareNumberBooleanWithoutPointer";
45+
public static final String DECLARE_NUMBER_BOOLEAN_WITHOUT_POINTER_DESC = "Declare number, boolean types without pointer using model-body, model-header templates from OpenAPI Generator v7.20.0.";
46+
4447
public static final String PROJECT_NAME = "projectName";
4548
protected String moduleName;
4649
protected String projectName;
@@ -270,7 +273,6 @@ public CLibcurlClientCodegen() {
270273
// primitives in C lang
271274
languageSpecificPrimitives.add("int");
272275
languageSpecificPrimitives.add("short");
273-
languageSpecificPrimitives.add("int");
274276
languageSpecificPrimitives.add("long");
275277
languageSpecificPrimitives.add("float");
276278
languageSpecificPrimitives.add("double");
@@ -315,6 +317,9 @@ public CLibcurlClientCodegen() {
315317

316318
cliOptions.add(new CliOption(USE_JSON_UNFORMATTED, USE_JSON_UNFORMATTED_DESC).
317319
defaultValue(Boolean.FALSE.toString()));
320+
321+
cliOptions.add(new CliOption(DECLARE_NUMBER_BOOLEAN_WITHOUT_POINTER, DECLARE_NUMBER_BOOLEAN_WITHOUT_POINTER_DESC).
322+
defaultValue(Boolean.FALSE.toString()));
318323
}
319324

320325
@Override
@@ -336,6 +341,13 @@ public void processOpts() {
336341
additionalProperties.put("cJSONPrint", "cJSON_Print");
337342
}
338343

344+
if (additionalProperties.containsKey(DECLARE_NUMBER_BOOLEAN_WITHOUT_POINTER)) {
345+
if (Boolean.parseBoolean(additionalProperties.get(DECLARE_NUMBER_BOOLEAN_WITHOUT_POINTER).toString())) {
346+
modelTemplateFiles.put("model-header-v7_20_0.mustache", ".h");
347+
modelTemplateFiles.put("model-body-v7_20_0.mustache", ".c");
348+
}
349+
}
350+
339351
// make api and model doc path available in mustache template
340352
additionalProperties.put("apiDocPath", apiDocPath);
341353
additionalProperties.put("modelDocPath", modelDocPath);

samples/client/petstore/c-useJsonUnformatted/.openapi-generator/FILES

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,46 @@ include/list.h
3131
libcurl.licence
3232
model/any_type.h
3333
model/api_response.c
34+
model/api_response.c
35+
model/api_response.h
3436
model/api_response.h
3537
model/bit.c
38+
model/bit.c
3639
model/bit.h
40+
model/bit.h
41+
model/category.c
3742
model/category.c
3843
model/category.h
44+
model/category.h
45+
model/mapped_model.c
3946
model/mapped_model.c
4047
model/mapped_model.h
48+
model/mapped_model.h
4149
model/model_with_set_propertes.c
50+
model/model_with_set_propertes.c
51+
model/model_with_set_propertes.h
4252
model/model_with_set_propertes.h
4353
model/object.c
4454
model/object.h
4555
model/order.c
56+
model/order.c
57+
model/order.h
4658
model/order.h
4759
model/pet.c
60+
model/pet.c
4861
model/pet.h
62+
model/pet.h
63+
model/preference.c
4964
model/preference.c
5065
model/preference.h
66+
model/preference.h
67+
model/tag.c
5168
model/tag.c
5269
model/tag.h
70+
model/tag.h
5371
model/user.c
72+
model/user.c
73+
model/user.h
5474
model/user.h
5575
src/apiClient.c
5676
src/apiKey.c

samples/client/petstore/c-useJsonUnformatted/model/api_response.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ typedef struct api_response_t api_response_t;
1919

2020

2121
typedef struct api_response_t {
22-
int *code; //numeric
22+
int code; //numeric
2323
char *type; // string
2424
char *message; // string
2525

2626
int _library_owned; // Is the library responsible for freeing this object?
2727
} api_response_t;
2828

2929
__attribute__((deprecated)) api_response_t *api_response_create(
30-
int *code,
30+
int code,
3131
char *type,
3232
char *message
3333
);

samples/client/petstore/c-useJsonUnformatted/model/category.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ typedef struct category_t category_t;
1919

2020

2121
typedef struct category_t {
22-
long *id; //numeric
22+
long id; //numeric
2323
char *name; // string
2424

2525
int _library_owned; // Is the library responsible for freeing this object?
2626
} category_t;
2727

2828
__attribute__((deprecated)) category_t *category_create(
29-
long *id,
29+
long id,
3030
char *name
3131
);
3232

samples/client/petstore/c-useJsonUnformatted/model/mapped_model.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ typedef struct MappedModel_t MappedModel_t;
1919

2020

2121
typedef struct MappedModel_t {
22-
int *another_property; //numeric
22+
int another_property; //numeric
2323
char *uuid_property; // string
2424

2525
int _library_owned; // Is the library responsible for freeing this object?
2626
} MappedModel_t;
2727

2828
__attribute__((deprecated)) MappedModel_t *MappedModel_create(
29-
int *another_property,
29+
int another_property,
3030
char *uuid_property
3131
);
3232

samples/client/petstore/c-useJsonUnformatted/model/order.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ openapi_petstore_order_STATUS_e order_status_FromString(char* status);
2727

2828

2929
typedef struct order_t {
30-
long *id; //numeric
31-
long *pet_id; //numeric
32-
int *quantity; //numeric
30+
long id; //numeric
31+
long pet_id; //numeric
32+
int quantity; //numeric
3333
char *ship_date; //date time
3434
openapi_petstore_order_STATUS_e status; //enum
35-
int *complete; //boolean
35+
int complete; //boolean
3636

3737
int _library_owned; // Is the library responsible for freeing this object?
3838
} order_t;
3939

4040
__attribute__((deprecated)) order_t *order_create(
41-
long *id,
42-
long *pet_id,
43-
int *quantity,
41+
long id,
42+
long pet_id,
43+
int quantity,
4444
char *ship_date,
4545
openapi_petstore_order_STATUS_e status,
46-
int *complete
46+
int complete
4747
);
4848

4949
void order_free(order_t *order);

samples/client/petstore/c-useJsonUnformatted/model/pet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ openapi_petstore_pet_STATUS_e pet_status_FromString(char* status);
2929

3030

3131
typedef struct pet_t {
32-
long *id; //numeric
32+
long id; //numeric
3333
struct category_t *category; //model
3434
char *name; // string
3535
list_t *photo_urls; //primitive container
@@ -40,7 +40,7 @@ typedef struct pet_t {
4040
} pet_t;
4141

4242
__attribute__((deprecated)) pet_t *pet_create(
43-
long *id,
43+
long id,
4444
category_t *category,
4545
char *name,
4646
list_t *photo_urls,

samples/client/petstore/c-useJsonUnformatted/model/tag.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ typedef struct tag_t tag_t;
1919

2020

2121
typedef struct tag_t {
22-
long *id; //numeric
22+
long id; //numeric
2323
char *name; // string
2424

2525
int _library_owned; // Is the library responsible for freeing this object?
2626
} tag_t;
2727

2828
__attribute__((deprecated)) tag_t *tag_create(
29-
long *id,
29+
long id,
3030
char *name
3131
);
3232

0 commit comments

Comments
 (0)