OpenAPITools / OpenAPITools/openapi-generator

[BUG][c-libcurl] Unexpected code generated for array of objects

Open
#16,452 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

The code generated for a response that contains an array of objects is not correct.
With this petstore example,
I would expect having a list of pet object but instead I get a string with json data (see generated code).

I am new with openapi-generator but this behavior doesn't match for me what is described in the documentation and it differs of what is generated by other language generators (I tried python and java).

openapi-generator version

The issue affects the latest tagged version (v7.0.0) and master.

OpenAPI declaration file content or url

petsore example could be used to reproduce the issue:

Generation Details

openapi-generator generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g c -o /tmp/test/

Suggest a fix

To get the expected behavior, in modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache, replace:

        char *localVarJSONToChar = cJSON_Print({{{paramName}}}VarJSON);
        list_addElement(elementToReturn , localVarJSONToChar);

by:

        {{{returnBaseType}}}_t *obj = {{{returnBaseType}}}_parseFromJSON({{{paramName}}}VarJSON);
        list_addElement(elementToReturn , obj);

This fixes the issues but I think it could have some side effects.

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 with modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache at the array-of-objects response handling, using modules/openapi-generator/src/test/resources/3_0/petstore.yaml and the provided generation command to reproduce it. Compare the generated samples/client/petstore/c/api/PetAPI.c output with the expected list of parsed pet objects, then verify the change does not introduce the noted side effects.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
api, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.