[BUG][C] C-client: referenced enum missing in model
Created by: Angeall
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
When a simple enum is referenced in an object properties, it's missing in the model body (_create function) and header (model struct).
openapi-generator version
master branch on 2020-03-17T10:41:00Z. Don't really know if it's a regression, I tried using the latest stable version too, but then I was mainly stuck with #5477 (this is why I'm using the master branch)
OpenAPI declaration file content or url
Command line used for generation
./run-in-docker.sh generate -i samples/client/enum-bug.yaml -g c -o /gen/out/enum-c
Steps to reproduce
- Use the provided "enum-bug.yaml" specification, or any API with a referenced enum inside an object schema
- Generate C-Libcurl client against the yaml
- Try to compile it using CMake
- Multiple errors
Here is the debugModels output: debug_models.txt
Here is the model header file with error commented: object_dummy.h
Here is the model body file with error commented: object_dummy.c
To get the compiler errors, just try to compile the generated code, it will be much simpler.
Related issues/PRs
My last pull request #5604 that fixed a problem that was still present after #5477 was merged
Suggest a fix
A fix could be something like the following fix, as stated in the debugModels output, the referenced enum is considered as "^isModel" and "^isPrimitiveType", so we have to add a third case : an enum that is neither a model nor a primitive type.
Although maybe it should be considered as a model, and that this causes the bug, but I'm not enough familiar with those definitions to be sure.
diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/model-header.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/model-header.mustache
index 03a03276f6..5d492a95ac 100644
--- a/modules/openapi-generator/src/main/resources/C-libcurl/model-header.mustache
+++ b/modules/openapi-generator/src/main/resources/C-libcurl/model-header.mustache
@@ -91,6 +91,9 @@ typedef struct {{classname}}_t {
{{#isFreeFormObject}}
{{datatype}}_t *{{name}}; //object
{{/isFreeFormObject}}
+ {{#isEnum}}
+ {{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}; //enum
+ {{/isEnum}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{#isNumeric}}
@@ -161,6 +164,9 @@ typedef struct {{classname}}_t {
{{#isFreeFormObject}}
{{datatype}}_t *{{name}}{{#hasMore}},{{/hasMore}}
{{/isFreeFormObject}}
+ {{#isEnum}}
+ {{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}{{#hasMore}},{{/hasMore}}
+ {{/isEnum}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{#isNumeric}}