Skip to content

Commit 1a09c7a

Browse files
authored
Add option to fallback to non-pointer number, boolean types (#23197)
* add option to fallback to non-pointe number, boolean * add new files * fix
1 parent d8afb22 commit 1a09c7a

20 files changed

Lines changed: 1503 additions & 523 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: 16 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,16 @@ 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+
modelTemplateFiles.remove("model-header.mustache");
350+
modelTemplateFiles.remove("model-body.mustache");
351+
}
352+
}
353+
339354
// make api and model doc path available in mustache template
340355
additionalProperties.put("apiDocPath", apiDocPath);
341356
additionalProperties.put("modelDocPath", modelDocPath);

0 commit comments

Comments
 (0)