-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[BUG] [C] Presence of an array of uniqueItems results in incomplete and inconsistent model files #14234
Open
5 of 6 tasks
Labels
Comments
mlebihan
added a commit
to mlebihan/openapi-generator
that referenced
this issue
May 2, 2024
…fined "Object.h" (OpenAPITools#2769) Should handle Object.h, AnyType.h correctly. Set.h also tested. - #include Object.h removed and replaced by a typeMapping.put(object, nlohmann::json) like suggested in other issues - object had an invalid syntax: ':' instead of '::' in types with namespace - extra include of #include nlohmann/json.h removed when there's already #include <nlohmann/json.hpp> - nlohmann::json is excluded from model namespace Tested with custom petstore played, with suggested openapi specs coming from issues OpenAPITools#2769, OpenAPITools#10266, OpenAPITools#14234 ```bash rm -rf samples/server/petstore/cpp-pistache-everything/ && ./bin/generate-samples.sh ./bin/configs/cpp-pistache-server-cpp-pistache-everything.yaml && cd samples/server/petstore/cpp-pistache-everything/ && mkdir build && cd build && cmake .. && cmake --build . --parallel ```
mlebihan
added a commit
to mlebihan/openapi-generator
that referenced
this issue
May 2, 2024
…fined "Object.h" (OpenAPITools#2769) Should handle Object.h, AnyType.h correctly. Set.h also tested. - #include Object.h removed and replaced by a typeMapping.put(object, nlohmann::json) like suggested in other issues - object had an invalid syntax: ':' instead of '::' in types with namespace - extra include of #include nlohmann/json.h removed when there's already #include <nlohmann/json.hpp> - nlohmann::json is excluded from model namespace Tested with custom petstore played, with suggested openapi specs coming from issues OpenAPITools#2769, OpenAPITools#10266, OpenAPITools#14234 ```bash rm -rf samples/server/petstore/cpp-pistache-everything/ && ./bin/generate-samples.sh ./bin/configs/cpp-pistache-server-cpp-pistache-everything.yaml && cd samples/server/petstore/cpp-pistache-everything/ && mkdir build && cd build && cmake .. && cmake --build . --parallel ```
5 tasks
wing328
pushed a commit
that referenced
this issue
May 4, 2024
#18553) * [BUG] [C++][Pistache] cpp-pistache-server generating API include undefined "Object.h" (#2769) Should handle Object.h, AnyType.h correctly. Set.h also tested. - #include Object.h removed and replaced by a typeMapping.put(object, nlohmann::json) like suggested in other issues - object had an invalid syntax: ':' instead of '::' in types with namespace - extra include of #include nlohmann/json.h removed when there's already #include <nlohmann/json.hpp> - nlohmann::json is excluded from model namespace Tested with custom petstore played, with suggested openapi specs coming from issues #2769, #10266, #14234 ```bash rm -rf samples/server/petstore/cpp-pistache-everything/ && ./bin/generate-samples.sh ./bin/configs/cpp-pistache-server-cpp-pistache-everything.yaml && cd samples/server/petstore/cpp-pistache-everything/ && mkdir build && cd build && cmake .. && cmake --build . --parallel ``` * - Adding to samples/server/petstore cpp-pistache-everything * - .md and FILES missing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Report Checklist
Description
The
c
language generator does not produce code that will compile and contains inconsistent use of theset_t
andlist_t
types.The generated code tries to
#include "set.h"
in the model header (${OUTDIR}/model/unique_array.h
generated from the example given below), but this file is not a standard header file or part of the generated files. This means the generated source files are incomplete.The model header uses the
set_t
data type to implement an OpenAPIarray
whereuniqueItems
==true
, but the model implementation (${OUTDIR}/model/unique_array.c
generated from the example given below) treats the same data structure component as alist_t
usinglist_...
functions to manipulate and traverse it.openapi-generator version
Checked with v5.2.0, v6.2.1 and the latest 7.0.0 Snapshot (openapi-generator-cli-7.0.0-20221012.083708-4.jar).
OpenAPI declaration file content or url
OpenAPI 3.0.0 YAML example that reproduces the issue:
Generation Details
Used the following command to generate the model code to check:
Steps to reproduce
unique_array_openapi.yaml
.java -jar openapi-generator-cli.jar generate -i unique_array_openapi.yaml -g c -o openapi_c
openapi_c/model/unique_array.h
andopenapi_c/model/unique_array.c
to see the inconsistent use ofset
andlist
and the inclusion of#include "set.h"
.set.h
in theopenapi_c/include
directory.set.c
in theopenapi_c/src
directory.Related issues/PRs
A similar issue appears to have been reported against version 5.0.0 in #6519.
Suggest a fix
The templates for the
C-libcurl
language should not uselist_...
functions (e.g. line 303 inopenapi-genertaor/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache
usinglist_ForEach
) and should use{{datatype}}_...
functions instead, or have an exception for arrays of unique items, to use the correctset_...
functions where appropriate. One exception to the simple one for one change fromlist
toset
is theset_createSet
function (instead oflist_createList
) which will need to additionally take a pointer to a comparison function for the data type being stored in the set, so that new set entries can be compared for uniqueness. This will necessitate the defining of comparison functions for generated complex data types in the model.#include "set.h"
should be#include "../include/set.h"
in the model header. Theset.h
header file should be created in the generatedinclude
directory. Theset.c
file should be created in thesrc
directory and included in the CMake files.The text was updated successfully, but these errors were encountered: