Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #5610
Closed
Open
Issue created Mar 17, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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

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}}
Assignee
Assign to
Time tracking