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 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 273762e830d..d44d34ca039 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(); }