diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Qt5CPPGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Qt5CPPGenerator.java index 8cdd89b603f..1b22302f8a3 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Qt5CPPGenerator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Qt5CPPGenerator.java @@ -26,6 +26,7 @@ import java.util.Set; public class Qt5CPPGenerator extends AbstractCppCodegen implements CodegenConfig { public static final String CPP_NAMESPACE = "cppNamespace"; public static final String CPP_NAMESPACE_DESC = "C++ namespace (convention: name::space::for::api)."; + public static final String OPTIONAL_PROJECT_FILE_DESC = "Generate client.pri."; protected final String PREFIX = "SWG"; protected Set foundationClasses = new HashSet(); @@ -35,6 +36,7 @@ public class Qt5CPPGenerator extends AbstractCppCodegen implements CodegenConfig protected Map namespaces = new HashMap(); protected Set systemIncludes = new HashSet(); protected String cppNamespace = "Swagger"; + protected boolean optionalProjectFileFlag = true; public Qt5CPPGenerator() { super(); @@ -82,6 +84,7 @@ public class Qt5CPPGenerator extends AbstractCppCodegen implements CodegenConfig // CLI options addOption(CPP_NAMESPACE, CPP_NAMESPACE_DESC, this.cppNamespace); + addSwitch(CodegenConstants.OPTIONAL_PROJECT_FILE, OPTIONAL_PROJECT_FILE_DESC, this.optionalProjectFileFlag); /* * Additional Properties. These values can be passed to the templates and @@ -114,6 +117,9 @@ public class Qt5CPPGenerator extends AbstractCppCodegen implements CodegenConfig supportingFiles.add(new SupportingFile("HttpRequest.cpp.mustache", sourceFolder, PREFIX + "HttpRequest.cpp")); supportingFiles.add(new SupportingFile("modelFactory.mustache", sourceFolder, PREFIX + "ModelFactory.h")); supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, PREFIX + "Object.h")); + if (optionalProjectFileFlag) { + supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, "client.pri")); + } super.typeMapping = new HashMap(); @@ -160,6 +166,14 @@ public class Qt5CPPGenerator extends AbstractCppCodegen implements CodegenConfig cliOptions.add(option); } + protected void addSwitch(String key, String description, Boolean defaultValue) { + CliOption option = CliOption.newBoolean(key, description); + if (defaultValue != null) + option.defaultValue(defaultValue.toString()); + cliOptions.add(option); + } + + @Override public void processOpts() { super.processOpts(); @@ -183,6 +197,12 @@ public class Qt5CPPGenerator extends AbstractCppCodegen implements CodegenConfig importMapping.put("SWGHttpRequestInputFileElement", "#include \"" + modelNamePrefix + "HttpRequest.h\""); additionalProperties().put("prefix", modelNamePrefix); } + + if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_PROJECT_FILE)) { + setOptionalProjectFileFlag(convertPropertyToBooleanAndWriteBack(CodegenConstants.OPTIONAL_PROJECT_FILE)); + } else { + additionalProperties.put(CodegenConstants.OPTIONAL_PROJECT_FILE, optionalProjectFileFlag); + } } /** @@ -425,4 +445,8 @@ public class Qt5CPPGenerator extends AbstractCppCodegen implements CodegenConfig public String escapeUnsafeCharacters(String input) { return input.replace("*/", "*_/").replace("/*", "/_*"); } + + public void setOptionalProjectFileFlag(boolean flag) { + this.optionalProjectFileFlag = flag; + } } diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/Project.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/Project.mustache new file mode 100644 index 00000000000..ed75433238c --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/Project.mustache @@ -0,0 +1,42 @@ +QT += network + +HEADERS += \ +# Models +{{#models}} +{{#model}} + $${PWD}/{{classname}}.h \ +{{/model}} +{{/models}} +# APIs +{{#apiInfo}} +{{#apis}} +{{#operations}} + $${PWD}/{{classname}}.h \ +{{/operations}} +{{/apis}} +{{/apiInfo}} +# Others + $${PWD}/{{prefix}}Helpers.h \ + $${PWD}/{{prefix}}HttpRequest.h \ + $${PWD}/{{prefix}}ModelFactory.h \ + $${PWD}/{{prefix}}Object.h + +SOURCES += \ +# Models +{{#models}} +{{#model}} + $${PWD}/{{classname}}.cpp \ +{{/model}} +{{/models}} +# APIs +{{#apiInfo}} +{{#apis}} +{{#operations}} + $${PWD}/{{classname}}.cpp \ +{{/operations}} +{{/apis}} +{{/apiInfo}} +# Others + $${PWD}/{{prefix}}Helpers.cpp \ + $${PWD}/{{prefix}}HttpRequest.cpp + diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/Qt5CPPOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/Qt5CPPOptionsProvider.java index 82dec7ec389..2cfca776498 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/Qt5CPPOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/Qt5CPPOptionsProvider.java @@ -12,6 +12,7 @@ public class Qt5CPPOptionsProvider implements OptionsProvider { public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true"; public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false"; public static final String CPP_NAMESPACE_VALUE = "Swagger"; + public static final String OPTIONAL_PROJECT_FILE_VALUE = "true"; @Override @@ -26,6 +27,7 @@ public class Qt5CPPOptionsProvider implements OptionsProvider { .put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE) .put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE) .put(Qt5CPPGenerator.CPP_NAMESPACE, CPP_NAMESPACE_VALUE) + .put(CodegenConstants.OPTIONAL_PROJECT_FILE, OPTIONAL_PROJECT_FILE_VALUE) .build(); } diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/qtfivecpp/Qt5CPPOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/qtfivecpp/Qt5CPPOptionsTest.java index 1bc1147cd00..6f2d53561e9 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/qtfivecpp/Qt5CPPOptionsTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/qtfivecpp/Qt5CPPOptionsTest.java @@ -28,6 +28,8 @@ public class Qt5CPPOptionsTest extends AbstractOptionsTest { new Expectations(clientCodegen) {{ clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(Qt5CPPOptionsProvider.SORT_PARAMS_VALUE)); times = 1; + clientCodegen.setOptionalProjectFileFlag(true); + times = 1; }}; } } diff --git a/samples/client/petstore/qt5cpp/PetStore/PetStore.pro b/samples/client/petstore/qt5cpp/PetStore/PetStore.pro index 64f27a3c924..ef2ef25ca2b 100644 --- a/samples/client/petstore/qt5cpp/PetStore/PetStore.pro +++ b/samples/client/petstore/qt5cpp/PetStore/PetStore.pro @@ -16,33 +16,9 @@ CONFIG += c++11 TEMPLATE = app +include(../client/client.pri) SOURCES += main.cpp \ - ../client/SWGCategory.cpp \ - ../client/SWGHelpers.cpp \ - ../client/SWGHttpRequest.cpp \ - ../client/SWGOrder.cpp \ - ../client/SWGPet.cpp \ - ../client/SWGPetApi.cpp \ - ../client/SWGStoreApi.cpp \ - ../client/SWGTag.cpp \ - ../client/SWGUser.cpp \ - ../client/SWGUserApi.cpp \ - ../client/SWGApiResponse.cpp \ - PetApiTests.cpp + PetApiTests.cpp -HEADERS += \ - ../client/SWGCategory.h \ - ../client/SWGHelpers.h \ - ../client/SWGHttpRequest.h \ - ../client/SWGObject.h \ - ../client/SWGOrder.h \ - ../client/SWGPet.h \ - ../client/SWGPetApi.h \ - ../client/SWGStoreApi.h \ - ../client/SWGTag.h \ - ../client/SWGUser.h \ - ../client/SWGUserApi.h \ - PetApiTests.h \ - ../client/SWGApiResponse.h \ - ../client/SWGModelFactory.h +HEADERS += PetApiTests.h diff --git a/samples/client/petstore/qt5cpp/client/client.pri b/samples/client/petstore/qt5cpp/client/client.pri new file mode 100644 index 00000000000..9b554ddc800 --- /dev/null +++ b/samples/client/petstore/qt5cpp/client/client.pri @@ -0,0 +1,36 @@ +QT += network + +HEADERS += \ +# Models + $${PWD}/SWGApiResponse.h \ + $${PWD}/SWGCategory.h \ + $${PWD}/SWGOrder.h \ + $${PWD}/SWGPet.h \ + $${PWD}/SWGTag.h \ + $${PWD}/SWGUser.h \ +# APIs + $${PWD}/SWGPetApi.h \ + $${PWD}/SWGStoreApi.h \ + $${PWD}/SWGUserApi.h \ +# Others + $${PWD}/SWGHelpers.h \ + $${PWD}/SWGHttpRequest.h \ + $${PWD}/SWGModelFactory.h \ + $${PWD}/SWGObject.h + +SOURCES += \ +# Models + $${PWD}/SWGApiResponse.cpp \ + $${PWD}/SWGCategory.cpp \ + $${PWD}/SWGOrder.cpp \ + $${PWD}/SWGPet.cpp \ + $${PWD}/SWGTag.cpp \ + $${PWD}/SWGUser.cpp \ +# APIs + $${PWD}/SWGPetApi.cpp \ + $${PWD}/SWGStoreApi.cpp \ + $${PWD}/SWGUserApi.cpp \ +# Others + $${PWD}/SWGHelpers.cpp \ + $${PWD}/SWGHttpRequest.cpp +