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

Fix a few issues with the C generator (part 1 version 2) #14434

Merged
merged 7 commits into from
Nov 27, 2024

Conversation

eafer
Copy link
Contributor

@eafer eafer commented Jan 11, 2023

This is a second version of the pull request from #14388. The differences with the first version are:

  • this version uses the existing implementation of object_t, as requested by @ityuhui
  • the Config.cmake.in file was cleaned up (I think it showed up in the first place because I forgot to rebuild before running the script)
  • returnTypeIsEnum was abandoned and replaced with returnProperty, following the instructions by @wing328
  • the fourth patch from Fix a few issues with the C generator #14379 is also included now, because it got fixed

These patches fix a few compilation errors for this api's generated code, but they are not enough by themselves to get it to build. More patches will be submitted later.

eafer added 5 commits January 10, 2023 20:55
Some generated C apis fail to build because the source files get
'#include "any_type.h"' lines, but no such header gets generated. As a
simple fix, add a new template for an empty file with that name. This is
enough to fix the problem for us, because all the generic type stuff is
handled by object_t.
I'm guessing that enums have not been used much with the C generator
before, because they always seem to produce code that doesn't build, or
that tries to free them after use. This patch fixes all the problems
we've encountered so far, except for those that need checking the return
type. I'll come back to that later.
Currently, the C templates never check if a function returns an enum
inside mustache, so when that happens the generated code has broken
return types and doesn't build. I originally tried to fix this by
extending CodegenOperation to implement a 'returnTypeIsEnum' check, but
William Cheng suggested[1] that I use the existing 'returnProperty'
instead:

  OpenAPITools#14379 (comment)

So do that.
As required for a pull request, run the generate-samples.sh script and
commit the changes.
@eafer
Copy link
Contributor Author

eafer commented Jan 11, 2023

@zhemant @michelealbano

@wing328
Copy link
Member

wing328 commented May 11, 2023

@ityuhui what do you think is the best way to proceed with this PR?

What about breaking it down into 4 smaller PRs to review and merge?

@ityuhui
Copy link
Contributor

ityuhui commented May 12, 2023

@wing328

Since it's been a long time since my last review, I will go through this PR recently to check if it can be merged or should break down into smaller PR.

@ityuhui
Copy link
Contributor

ityuhui commented May 15, 2023

I'm just wondering why this a0fa76d should change.

@wing328 Are these 2 commits 523e5de and 5a4a398 about returnProperty reviewed by you ?

I'm find with the rest of this PR.

@eafer
Copy link
Contributor Author

eafer commented May 15, 2023

Hi! Thank you for looking into this again.

I'm just wondering why this a0fa76d should change.

Because that's how *_parseFromJSON() and *_convertToJSON() are actually called by the rest of the generated code. For instance in the api-body.mustache template you have the following line:

        elementToReturn = {{{returnBaseType}}}_parseFromJSON({{classname}}localVarJSON);

For our instance_state model, this generates:

        elementToReturn = instance_state_parseFromJSON(ArmAPIlocalVarJSON);

But the *_parseFromJSON() function gets declared as:

arm_api_instance_state__e instance_state_instance_state_parseFromJSON(cJSON *instance_stateJSON);

So the build will not go well, with warnings such as this one:

warning: implicit declaration of function ‘instance_state_parseFromJSON’; did you mean instance_return_parseFromJSON’? [-Wimplicit-function-declaration]
 4045 |         elementToReturn = instance_state_parseFromJSON(ArmAPIlocalVarJSON);
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                           instance_return_parseFromJSON

@ityuhui
Copy link
Contributor

ityuhui commented May 17, 2023

Thank you @eafer for the clarifacation.

I'm OK with this PR.

@wing328 If you agree the commits 523e5de and 5a4a398 about returnProperty, I think this PR can merge now.

@eafer
Copy link
Contributor Author

eafer commented May 23, 2023

Hey, is there anything more I can do here? Do you want me to walk you through those two patches?

@ityuhui
Copy link
Contributor

ityuhui commented May 24, 2023

I'm OK with this PR.

Just wait for @wing328 to review and merge.

@eafer
Copy link
Contributor Author

eafer commented May 31, 2023

Hey @wing328, is there anything more I can do to help here?

@ityuhui
Copy link
Contributor

ityuhui commented Jun 15, 2023

Hi @wing328

I think this PR can merge now.

@wing328
Copy link
Member

wing328 commented Nov 25, 2024

@eafer can you please resolve the merge conflicts when you've time?

sorry for the delay in getting it merged.

you may want to update modules/openapi-generator/src/test/resources/2_0/c/petstore.yaml with a few test schemas to cover this change.

@wing328 wing328 added this to the 7.11.0 milestone Nov 25, 2024
@eafer
Copy link
Contributor Author

eafer commented Nov 26, 2024

@wing328 I did the backmerge you requested. I'll try to look into the test schemas later, but it's been a while and I'm struggling to get things to build again.

@wing328
Copy link
Member

wing328 commented Nov 27, 2024

updated samples via e3dfe90
and all tests passed

@wing328 wing328 merged commit 47665aa into OpenAPITools:master Nov 27, 2024
18 checks passed
@wing328
Copy link
Member

wing328 commented Nov 27, 2024

just merged it. thanks again for the PR.

if i can find the time later, i'll update the c petstore spec to add some tests too.

eafer added a commit to eafer/openapi-generator that referenced this pull request Nov 27, 2024
The recent commit 47665aa ("Fix a few issues with the C generator
(part 1 version 2) (OpenAPITools#14434)") didn't include any test schemas. Add them
now, as requested:

  OpenAPITools#14434 (comment)
@eafer eafer mentioned this pull request Nov 27, 2024
@eafer
Copy link
Contributor Author

eafer commented Nov 27, 2024

@wing328 Thanks! I just tried some changes for the test schemas and sent a new pull request with them: #20200. I hope it helps.

@wing328
Copy link
Member

wing328 commented Nov 27, 2024

@eafer thank you. will review and get it merged shortly

wing328 pushed a commit that referenced this pull request Nov 28, 2024
* [C] Add test schemas for the recent changes

The recent commit 47665aa ("Fix a few issues with the C generator
(part 1 version 2) (#14434)") didn't include any test schemas. Add them
now, as requested:

  #14434 (comment)

* Update samples

* Fix sample update with missing files

* More fixes for sample updates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants