OpenAPITools / OpenAPITools/openapi-generator

[BUG] [C Client] incorrect generate "object_convertToJSON" function

Open
#5,735 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: C Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

I use OpenApi3 generator (Openapi-generator-cli-4.1.0) for C client, and found not for clean functional for me.

So, I have some json template where I plan to use "payload" like addition parameter (json Object type) for my functionality:

...
"data": {
"type": "object",
"properties": {
"message": {
"type": "string",
"minLength": 1,
"maxLength": 1024,
"description": "human-readable event description"
},
"payload": {
"type": "object",
"description": "(optional) Additional data, some object/property should be added, integer/string/array/object",
"properties": {}
}
},
....

after generation we have object.h and object.c files for working with object_t type.

Please to correct my if I am wrong.
For make "object" type need to do something like:

object_t* _tmp = object_create();
cJSON* obj = object_convertToJSON(_tmp);
if(cJSON_AddNumberToObject(obj, "value", 123)){
return true;
}

but currently looks like that function:"object_convertToJSON" not fully correct
or maybe my json template wrong?

cJSON *object_convertToJSON(object_t *object) {
    cJSON *item = cJSON_CreateObject();

    return item;
fail:
    cJSON_Delete(item);
    return NULL;
}

I fix this issue internally, like:

cJSON *object_convertToJSON(object_t *object) {
    **//cJSON *item = cJSON_CreateObject();**
    return (cJSON *)object;
}
...
cJSON * _tmp = cJSON_CreateObject();
bla-bla...
openapi-generator version

Openapi-generator-cli-4.1.0

OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the report with OpenAPI Generator CLI 4.1.0 and the described OpenAPI 3 object schema. Inspect the generated object.c and object.h, focusing on object_convertToJSON; the fix is complete when generated C code correctly serializes the object payload without requiring the reported manual workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, java
Domain
devtools, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.