Skip to content

Commit

Permalink
Simplify forward declaration detection
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dschmidt committed Feb 24, 2022
1 parent 237706d commit 91beb7b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,10 @@ private void addForwardDeclarations(CodegenModel parentModel, Map<String, Object
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);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/cpp-qt/client/PFXPet.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "PFXObject.h"

namespace test_namespace {
class PFXCategory;
class PFXTag;

class PFXPet : public PFXObject {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace openapitools {
namespace client {
namespace model {

class Category;
class Tag;

/// <summary>
/// A pet for sale in the pet store
Expand Down

0 comments on commit 91beb7b

Please sign in to comment.