We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
When generating code containing enums we get functions to convert to/from a string. However the function name and the prototype are different.
In item_resource.c
char* valueitem_resource_ToString(simple_api_item_resource_VALUE_e value) { char* valueArray[] = { "NULL", "value1", "value2" }; return valueArray[value]; }
In item_resource.h
char* item_resource_value_ToString(simple_api_item_resource_VALUE_e value);
I would expect them to have the same names. We have instead just been patching the output.
Tested with 6.6.0 originally but reproduced on 7.2.0 and master (8b5b5a7).
openapi: 3.0.1 info: title: Simple API version: 1.0.0 servers: - url: / paths: /{id}: get: summary: Get item description: |- Gets the item. parameters: - name: id in: path description: |- Gets the specific item in the form of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx required: true schema: type: string - name: content in: query schema: type: string enum: - all - subset responses: '200': $ref: '#/components/responses/GetItem' components: schemas: ItemResource: type: object properties: value: type: string enum: - value1 - value2 GetItemResult: type: object properties: key: $ref: '#/components/schemas/ItemResource' description: |- Representation of an item responses: GetItem: description: |- Representation of an item returned content: application/json: schema: $ref: '#/components/schemas/GetItemResult'
java -jar ../openapi-generator-cli-7.2.0.jar generate -g c --additional-properties=prependFormOrBodyParameters=true -o out -i ../simple.yaml
out/model/item_resource.(c/h)
I have looked through all the issues marked with [C] and can't see any duplicates. I also can't find any open PRs attempting to fix this.
I think this is the fix but I don't know if it's complete or if it will break anything else. I'll try and make a PR one I work out how to do that.
diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache index 1cb6759f7ad..98bbfd37998 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache @@ -77,12 +77,12 @@ end: {{^isContainer}} {{^isModel}} {{#isEnum}} -char* {{name}}{{classname}}_ToString({{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}) { +char* {{classname}}_{{name}}_ToString({{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}) { char* {{name}}Array[] = { "NULL"{{#allowableValues}}{{#values}}, "{{.}}"{{/values}}{{/allowableValues}} }; return {{name}}Array[{{name}}]; } -{{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}{{classname}}_FromString(char* {{name}}){ +{{projectName}}_{{classVarName}}_{{enumName}}_e {{classname}}_{{name}}_FromString(char* {{name}}){ int stringToReturn = 0; char *{{name}}Array[] = { "NULL"{{#allowableValues}}{{#values}}, "{{.}}"{{/values}}{{/allowableValues}} }; size_t sizeofArray = sizeof({{name}}Array) / sizeof({{name}}Array[0]); @@ -101,12 +101,12 @@ char* {{name}}{{classname}}_ToString({{projectName}}_{{classVarName}}_{{enumName {{#items}} {{^isModel}} {{#isEnum}} -char* {{name}}{{classname}}_ToString({{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}) { +char* {{classname}}_{{name}}_ToString({{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}) { char *{{name}}Array[] = { "NULL"{{#allowableValues}}{{#values}}, "{{.}}"{{/values}}{{/allowableValues}} }; return {{name}}Array[{{name}} - 1]; } -{{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}{{classname}}_FromString(char* {{name}}) { +{{projectName}}_{{classVarName}}_{{enumName}}_e {{classname}}_{{name}}_FromString(char* {{name}}) { } -{{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}{{classname}}_FromString(char* {{name}}) { +{{projectName}}_{{classVarName}}_{{enumName}}_e {{classname}}_{{name}}_FromString(char* {{name}}) { int stringToReturn = 0; char *{{name}}Array[] = { "NULL"{{#allowableValues}}{{#values}}, "{{.}}"{{/values}}{{/allowableValues}} }; size_t sizeofArray = sizeof({{name}}Array) / sizeof({{name}}Array[0]); @@ -629,7 +629,7 @@ fail: { goto end; //Enum } - {{name}}Variable = {{name}}{{classname}}_FromString({{{name}}}->valuestring); + {{name}}Variable = {{classname}}_{{name}}_FromString({{{name}}}->valuestring); {{/isString}} {{/isEnum}} {{^isEnum}}
The text was updated successfully, but these errors were encountered:
[C][Client] Fix enum function names not matching headers in the model…
3fa8e33
… template - fixes OpenAPITools#17510
34c3f8c
… template (#17512) - fixes #17510 Co-authored-by: Dan Booker <[email protected]>
Successfully merging a pull request may close this issue.
Bug Report Checklist
Description
When generating code containing enums we get functions to convert to/from a string. However the function name and the prototype are different.
In item_resource.c
In item_resource.h
I would expect them to have the same names. We have instead just been patching the output.
openapi-generator version
Tested with 6.6.0 originally but reproduced on 7.2.0 and master (8b5b5a7).
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
out/model/item_resource.(c/h)
Related issues/PRs
I have looked through all the issues marked with [C] and can't see any duplicates. I also can't find any open PRs attempting to fix this.
Suggest a fix
I think this is the fix but I don't know if it's complete or if it will break anything else. I'll try and make a PR one I work out how to do that.
The text was updated successfully, but these errors were encountered: