OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.62k stars 6.29k forks source link

Attempt to create a cumulative fix for missing Object.h, AnyType.h, Set.h for many generators: can you give me some knowledge you have to help me correcting them? #18523

Open mlebihan opened 2 months ago

mlebihan commented 2 months ago

Many generators encounter the same problem against properties having a "type": "object" or 'type": ["string", "number",...], and another form with arrays that lead to missing sources files at generation time:

being declared as #include but no Object.h, Object.cpp, AnyType.h, AnyType.cpp, Set.h, Set.cpp [for C++ example], are generated aside.

I am in need of correcting this problem, and I would like to solve it for the most generators possible. All, if possible.

They are already a lot of issues created for this trouble: one for one specific generator each time. But I think it's useful to gather here all the knowledge we have about it.


I begin focusing on it, and here's what I've attempted in a fork branch, to create a test that fails for the first of these problems:

https://github.com/OpenAPITools/openapi-generator/compare/master...mlebihan:openapi-generator:any_type and I generate from a custom petstore, where I've added to Pet definition a:

        veterinarianVisit:
          type: object
          description: last veterinarian visit advice

Debugging things, it looks that C generator does generates its object.h and object.c files:

image

But cpp-pistache generator doesn't generate its equivalent Object.h and Object.cpp:

image

[main] ERROR org.openapitools.codegen.ObjectAnyTypeSetTest - Object.h expected file hasn't been produced by cpp-pistache-server generator.
[main] ERROR org.openapitools.codegen.ObjectAnyTypeSetTest - Object.cpp expected file hasn't been produced by cpp-pistache-server generator.

java.lang.AssertionError: 2 files ([Object.cpp, Object.h]) are lacking in cpp-pistache-server generation
Expected :true
Actual   :false
<Click to see difference>

    at org.testng.Assert.fail(Assert.java:110)
    at org.testng.Assert.failNotEquals(Assert.java:1413)
    at org.testng.Assert.assertTrue(Assert.java:56)
    at org.openapitools.codegen.ObjectAnyTypeSetTest.assertGeneratedFiles(ObjectAnyTypeSetTest.java:72)
    at org.openapitools.codegen.ObjectAnyTypeSetTest.testSomeWithPetstoreWithAbstract(ObjectAnyTypeSetTest.java:45)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:135)
    at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:673)
    at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:220)
    at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
    at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:945)
    at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:193)
    at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
    at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at org.testng.TestRunner.privateRun(TestRunner.java:808)
    at org.testng.TestRunner.run(TestRunner.java:603)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:429)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:423)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:383)
    at org.testng.SuiteRunner.run(SuiteRunner.java:326)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1249)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.runSuites(TestNG.java:1092)
    at org.testng.TestNG.run(TestNG.java:1060)
    at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:65)
    at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:105)

Depending on the issues I've read about this, they are various advices. Can you tell me:

  1. If once, these sources were generated but an event (around 4.1.0 version of openapi generator? earlier?) made that it doesn't work anymore?

  2. If it's just a configuration issue : the missing sources exist (for each generator) but they just aren't "pushed" at generation time, for any reason ; or if at the opposite, they are entirely missing? "We don't know yet (we haven't written yet), in example, how to perform a C++ serialization in json of an Object?

  3. What do you recommend me, to solve this problem?

Thanks!

wing328 commented 2 months ago

@mlebihan thanks for offering help to fix these issue. Can you please PM me via Slack when you've time in the coming week?

https://join.slack.com/t/openapi-generator/shared_invite/zt-12jxxd7p2-XUeQM~4pzsU9x~eGLQqX2g

mlebihan commented 2 months ago

Object for C++ pistache looks working correctly with:

https://github.com/OpenAPITools/openapi-generator/compare/master...mlebihan:openapi-generator:any_type

(my test isn't accurate and working, but the generation looks to be)