From 0e1178e04391768cbe77bf09a4220a1e35d6b76d Mon Sep 17 00:00:00 2001
From: Ayman Bagabas <ayman.bagabas@gmail.com>
Date: Mon, 3 May 2021 21:56:32 -0400
Subject: [PATCH 1/2] [swift5] Add useClasses cliOption

---
 .../codegen/languages/Swift5ClientCodegen.java      | 13 +++++++++++++
 .../codegen/options/Swift5OptionsProvider.java      |  1 +
 2 files changed, 14 insertions(+)

diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java
index c810c01a891..3ec06b6c38c 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java
@@ -63,6 +63,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
     public static final String LENIENT_TYPE_CAST = "lenientTypeCast";
     public static final String USE_SPM_FILE_STRUCTURE = "useSPMFileStructure";
     public static final String SWIFT_PACKAGE_PATH = "swiftPackagePath";
+    public static final String USE_CLASSES = "useClasses";
     public static final String USE_BACKTICK_ESCAPES = "useBacktickEscapes";
     public static final String GENERATE_MODEL_ADDITIONAL_PROPERTIES = "generateModelAdditionalProperties";
     public static final String HASHABLE_MODELS = "hashableModels";
@@ -82,6 +83,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
     protected boolean swiftUseApiNamespace = false;
     protected boolean useSPMFileStructure = false;
     protected String swiftPackagePath = "Classes" + File.separator + "OpenAPIs";
+    protected boolean useClasses = false;
     protected boolean useBacktickEscapes = false;
     protected boolean generateModelAdditionalProperties = true;
     protected boolean hashableModels = true;
@@ -282,6 +284,8 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
                 + " and set the source path to Sources" + File.separator + "{{projectName}} (default: false)."));
         cliOptions.add(new CliOption(SWIFT_PACKAGE_PATH, "Set a custom source path instead of "
                 + projectName + File.separator + "Classes" + File.separator + "OpenAPIs" + "."));
+        cliOptions.add(new CliOption(USE_CLASSES, "Use final classes for models instead of structs (default: false)")
+                .defaultValue(Boolean.FALSE.toString()));
 
         cliOptions.add(new CliOption(HASHABLE_MODELS,
             "Make hashable models (default: true)")
@@ -484,6 +488,11 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
             typeMapping.put("binary", "Data");
         }
 
+        if (additionalProperties.containsKey(USE_CLASSES)) {
+            setUseClasses(convertPropertyToBooleanAndWriteBack(USE_CLASSES));
+        }
+        additionalProperties.put(USE_CLASSES, useClasses);
+
         setLenientTypeCast(convertPropertyToBooleanAndWriteBack(LENIENT_TYPE_CAST));
 
         // make api and model doc path available in mustache template
@@ -904,6 +913,10 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
         this.swiftPackagePath = swiftPackagePath;
     }
 
+    public void setUseClasses(boolean useClasses) {
+        this.useClasses = useClasses;
+    }
+
     public void setUseBacktickEscapes(boolean useBacktickEscapes) {
         this.useBacktickEscapes = useBacktickEscapes;
     }
diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/Swift5OptionsProvider.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/Swift5OptionsProvider.java
index 6e5f48ca377..fa562df6d7f 100644
--- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/Swift5OptionsProvider.java
+++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/Swift5OptionsProvider.java
@@ -96,6 +96,7 @@ public class Swift5OptionsProvider implements OptionsProvider {
                 .put(Swift5ClientCodegen.GENERATE_MODEL_ADDITIONAL_PROPERTIES, GENERATE_MODEL_ADDITIONAL_PROPERTIES_VALUE)
                 .put(Swift5ClientCodegen.HASHABLE_MODELS, HASHABLE_MODELS_VALUE)
                 .put(Swift5ClientCodegen.MAP_FILE_BINARY_TO_DATA, "false")
+                .put(Swift5ClientCodegen.USE_CLASSES, "false")
                 .build();
     }
 
-- 
GitLab


From 0005d526d307d4e29a0b9d06554e975211f36503 Mon Sep 17 00:00:00 2001
From: Ayman Bagabas <ayman.bagabas@gmail.com>
Date: Thu, 27 May 2021 12:22:06 -0400
Subject: [PATCH 2/2] Update swift docs

---
 docs/generators/swift5.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/docs/generators/swift5.md b/docs/generators/swift5.md
index bace7f1f049..51dc7529358 100644
--- a/docs/generators/swift5.md
+++ b/docs/generators/swift5.md
@@ -39,6 +39,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
 |swiftPackagePath|Set a custom source path instead of OpenAPIClient/Classes/OpenAPIs.| |null|
 |swiftUseApiNamespace|Flag to make all the API classes inner-class of {{projectName}}API| |null|
 |useBacktickEscapes|Escape reserved words using backticks (default: false)| |false|
+|useClasses|Use final classes for models instead of structs (default: false)| |false|
 |useSPMFileStructure|Use SPM file structure and set the source path to Sources/{{projectName}} (default: false).| |null|
 
 ## IMPORT MAPPING
-- 
GitLab