Skip to content

Tests for recent C fixes#20200

Merged
wing328 merged 4 commits intoOpenAPITools:masterfrom
eafer:c_api_fixes_1_tests
Nov 28, 2024
Merged

Tests for recent C fixes#20200
wing328 merged 4 commits intoOpenAPITools:masterfrom
eafer:c_api_fixes_1_tests

Conversation

@eafer
Copy link
Contributor

@eafer eafer commented Nov 27, 2024

These are the updated test schemas for the recently merged C generator patches. As requested by @wing328 here:

#14434 (comment)

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
Copy link
Contributor Author

eafer commented Nov 27, 2024

@ityuhui

@eafer
Copy link
Contributor Author

eafer commented Nov 27, 2024

By the way, there are a few warnings in the test build that seem to be a recent regression:

/home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/c/model/order.c: In function ‘order_convertToJSON’:
/home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/c/model/order.c:97:48: warning: implicit declaration of function ‘statusorder_ToString’ [-Wimplicit-function-declaration]
   97 |     if(cJSON_AddStringToObject(item, "status", statusorder_ToString(order->status)) == NULL)
      |                                                ^~~~~~~~~~~~~~~~~~~~
/home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/c/model/order.c:97:48: warning: passing argument 3 of ‘cJSON_AddStringToObject’ makes pointer from integer without a cast [-Wint-conversion]
   97 |     if(cJSON_AddStringToObject(item, "status", statusorder_ToString(order->status)) == NULL)
      |                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                |
      |                                                int
In file included from /home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/c/model/order.h:11,
                 from /home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/c/model/order.c:4:
/home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/c/model/../external/cJSON.h:255:112: note: expected ‘const char * const’ but argument is of type ‘int’
  255 | CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
      |                                                                                             ~~~~~~~~~~~~~~~~~~~^~~~~~
[ 60%] Building C object CMakeFiles/openapi_petstore.dir/model/pet.c.o
/home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/c/model/pet.c: In function ‘pet_convertToJSON’:
/home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/c/model/pet.c:151:[48](https://github.com/OpenAPITools/openapi-generator/actions/runs/12053425233/job/33609057818?pr=20200#step:4:49): warning: implicit declaration of function ‘statuspet_ToString’ [-Wimplicit-function-declaration]
  151 |     if(cJSON_AddStringToObject(item, "status", statuspet_ToString(pet->status)) == NULL)
      |                                                ^~~~~~~~~~~~~~~~~~
/home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/c/model/pet.c:1[51](https://github.com/OpenAPITools/openapi-generator/actions/runs/12053425233/job/33609057818?pr=20200#step:4:52):48: warning: passing argument 3 of ‘cJSON_AddStringToObject’ makes pointer from integer without a cast [-Wint-conversion]
  151 |     if(cJSON_AddStringToObject(item, "status", statuspet_ToString(pet->status)) == NULL)
      |                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                |
      |                                                int
In file included from /home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/c/model/pet.h:11,
                 from /home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/c/model/pet.c:4:
/home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/c/model/../external/cJSON.h:2[55](https://github.com/OpenAPITools/openapi-generator/actions/runs/12053425233/job/33609057818?pr=20200#step:4:56):112: note: expected ‘const char * const’ but argument is of type ‘int’
  255 | CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
      |                                                                                             ~~~~~~~~~~~~~~~~~~~^~~~~~

type: string
xml:
name: Category
Preference:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding a new test schema

have you added the new files too using git add?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What new files? Did I mess something up? I thought I just needed to update the schema with the new cases that were failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you mean for the samples? Yes, I added everything.

Copy link
Member

@wing328 wing328 Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the build error message:

[ 66%] Building C object CMakeFiles/openapi_petstore.dir/model/tag.c.o
[ 73%] Building C object CMakeFiles/openapi_petstore.dir/model/user.c.o
In file included from /home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/c/model/user.c:4:
/home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/c/model/user.h:19:10: fatal error: preference.h: No such file or directory
   19 | #include "preference.h"
      |          ^~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/openapi_petstore.dir/build.make:219: CMakeFiles/openapi_petstore.dir/model/user.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:87: CMakeFiles/openapi_petstore.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

looks like the c petstore is trying to import preference (enum) but no luck.

does the C petstore client support enum models? or it only supports inline enum?

Copy link
Contributor Author

@eafer eafer Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I messed up at some point during rebasing. I'll send the rest of the samples now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added the missing files, sorry for the confusion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done. Sorry, I have no idea how I keep messing this up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem bro. Thanks for adding the test.

@wing328
Copy link
Member

wing328 commented Nov 27, 2024

cc @zhemant (2018/11) @ityuhui (2019/12) @michelealbano (2020/03)

@wing328 wing328 added this to the 7.11.0 milestone Nov 28, 2024
@wing328
Copy link
Member

wing328 commented Nov 28, 2024

lgtm. let's give it a try

@wing328 wing328 merged commit 037cb12 into OpenAPITools:master Nov 28, 2024
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.

2 participants