From e35a1270a3f59d1f7ba768cfe3dfbf49e411b4dc Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sat, 26 Feb 2022 07:56:41 +0100 Subject: [PATCH] Simplify forward declaration detection (#11490) This makes sure all model classes are added to the forward declarations which makes it possible to create templates without any model includes which helps to resolve circular inclusion issues. --- .../codegen/languages/AbstractCppCodegen.java | 11 ++++------- samples/client/petstore/cpp-qt/client/PFXPet.h | 2 ++ .../client/include/CppRestPetstoreClient/model/Pet.h | 2 ++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java index fc4e37066f8..a82430bb4a4 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java @@ -418,13 +418,10 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg if( !childPropertyType.equals(childModel.classname) || childPropertyType.equals(parentModel.classname) || !childModel.hasVars ){ continue; } - for(CodegenProperty p : childModel.vars) { - if(((p.isModel && p.dataType.equals(parentModel.classname)) || (p.isContainer && p.mostInnerItems.baseType.equals(parentModel.classname)))) { - String forwardDecl = "class " + childModel.classname + ";"; - if(!forwardDeclarations.contains(forwardDecl)) { - forwardDeclarations.add(forwardDecl); - } - } + + String forwardDecl = "class " + childPropertyType + ";"; + if(!forwardDeclarations.contains(forwardDecl)) { + forwardDeclarations.add(forwardDecl); } } } diff --git a/samples/client/petstore/cpp-qt/client/PFXPet.h b/samples/client/petstore/cpp-qt/client/PFXPet.h index b84bfc6d93e..3a5617940e1 100644 --- a/samples/client/petstore/cpp-qt/client/PFXPet.h +++ b/samples/client/petstore/cpp-qt/client/PFXPet.h @@ -29,6 +29,8 @@ #include "PFXObject.h" namespace test_namespace { +class PFXCategory; +class PFXTag; class PFXPet : public PFXObject { public: diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Pet.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Pet.h index 05cd7c31c27..8a329064374 100644 --- a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Pet.h +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Pet.h @@ -31,6 +31,8 @@ namespace openapitools { namespace client { namespace model { +class Category; +class Tag; /// /// A pet for sale in the pet store