Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][C] C-client: referenced enum missing in model #5610

Open
5 of 6 tasks
Angeall opened this issue Mar 17, 2020 · 1 comment
Open
5 of 6 tasks

[BUG][C] C-client: referenced enum missing in model #5610

Angeall opened this issue Mar 17, 2020 · 1 comment

Comments

@Angeall
Copy link
Contributor

Angeall commented Mar 17, 2020

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

enum-bug.yaml

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
  1. Use the provided "enum-bug.yaml" specification, or any API with a referenced enum inside an object schema
  2. Generate C-Libcurl client against the yaml
  3. Try to compile it using CMake
  4. 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}}
@Angeall
Copy link
Contributor Author

Angeall commented Mar 17, 2020

As requested, tagging technical experts now:
@zhemant @ityuhui

@Angeall Angeall changed the title [BUG] C-client: referenced enum missing in model [BUG][C] C-client: referenced enum missing in model Mar 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant