forked from loafle/openapi-generator-original
[swift5] Map file and binary to Data (#9419)
* [swift5] Map file and binary to Data Fixes: https://github.com/OpenAPITools/openapi-generator/issues/9308 * Update docs
This commit is contained in:
parent
e09409fbce
commit
ae0350280f
@ -17,6 +17,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
|
||||
|lenientTypeCast|Accept and cast values for simple types (string->bool, string->int, int->string)| |false|
|
||||
|library|Library template (sub-template) to use|<dl><dt>**urlsession**</dt><dd>[DEFAULT] HTTP client: URLSession</dd><dt>**alamofire**</dt><dd>HTTP client: Alamofire</dd></dl>|urlsession|
|
||||
|mapFileBinaryToData|Map File and Binary to Data (default: false)| |false|
|
||||
|nonPublicApi|Generates code with reduced access modifiers; allows embedding elsewhere without exposing non-public API calls to consumers.(default: false)| |null|
|
||||
|objcCompatible|Add additional properties and methods for Objective-C compatibility (default: false)| |null|
|
||||
|podAuthors|Authors used for Podspec| |null|
|
||||
|
@ -165,7 +165,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|Maps|✗|ToolingExtension
|
||||
|CollectionFormat|✓|OAS2
|
||||
|CollectionFormatMulti|✓|OAS2
|
||||
|Enum|✓|OAS2,OAS3
|
||||
|Enum|✗|OAS2,OAS3
|
||||
|ArrayOfEnum|✓|ToolingExtension
|
||||
|ArrayOfModel|✓|ToolingExtension
|
||||
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
|
||||
|
@ -66,6 +66,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
public static final String USE_BACKTICK_ESCAPES = "useBacktickEscapes";
|
||||
public static final String GENERATE_MODEL_ADDITIONAL_PROPERTIES = "generateModelAdditionalProperties";
|
||||
public static final String HASHABLE_MODELS = "hashableModels";
|
||||
public static final String MAP_FILE_BINARY_TO_DATA = "mapFileBinaryToData";
|
||||
protected static final String LIBRARY_ALAMOFIRE = "alamofire";
|
||||
protected static final String LIBRARY_URLSESSION = "urlsession";
|
||||
protected static final String RESPONSE_LIBRARY_PROMISE_KIT = "PromiseKit";
|
||||
@ -84,6 +85,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
protected boolean useBacktickEscapes = false;
|
||||
protected boolean generateModelAdditionalProperties = true;
|
||||
protected boolean hashableModels = true;
|
||||
protected boolean mapFileBinaryToData = false;
|
||||
protected String[] responseAs = new String[0];
|
||||
protected String sourceFolder = swiftPackagePath;
|
||||
protected HashSet objcReservedWords;
|
||||
@ -120,7 +122,6 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"Bool",
|
||||
"Void",
|
||||
"String",
|
||||
"URL",
|
||||
"Data",
|
||||
"Date",
|
||||
"Character",
|
||||
@ -286,6 +287,10 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"Make hashable models (default: true)")
|
||||
.defaultValue(Boolean.TRUE.toString()));
|
||||
|
||||
cliOptions.add(new CliOption(MAP_FILE_BINARY_TO_DATA,
|
||||
"Map File and Binary to Data (default: false)")
|
||||
.defaultValue(Boolean.FALSE.toString()));
|
||||
|
||||
supportedLibraries.put(LIBRARY_URLSESSION, "[DEFAULT] HTTP client: URLSession");
|
||||
supportedLibraries.put(LIBRARY_ALAMOFIRE, "HTTP client: Alamofire");
|
||||
|
||||
@ -470,6 +475,15 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
additionalProperties.put(HASHABLE_MODELS, hashableModels);
|
||||
|
||||
if (additionalProperties.containsKey(MAP_FILE_BINARY_TO_DATA)) {
|
||||
setMapFileBinaryToData(convertPropertyToBooleanAndWriteBack(MAP_FILE_BINARY_TO_DATA));
|
||||
}
|
||||
additionalProperties.put(MAP_FILE_BINARY_TO_DATA, mapFileBinaryToData);
|
||||
if (mapFileBinaryToData) {
|
||||
typeMapping.put("file", "Data");
|
||||
typeMapping.put("binary", "Data");
|
||||
}
|
||||
|
||||
setLenientTypeCast(convertPropertyToBooleanAndWriteBack(LENIENT_TYPE_CAST));
|
||||
|
||||
// make api and model doc path available in mustache template
|
||||
@ -547,6 +561,14 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
}
|
||||
|
||||
public boolean isMapFileBinaryToData() {
|
||||
return mapFileBinaryToData;
|
||||
}
|
||||
|
||||
public void setMapFileBinaryToData(boolean mapFileBinaryToData) {
|
||||
this.mapFileBinaryToData = mapFileBinaryToData;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isReservedWord(String word) {
|
||||
return word != null && reservedWords.contains(word); //don't lowercase as super does
|
||||
|
@ -95,6 +95,7 @@ public class Swift5OptionsProvider implements OptionsProvider {
|
||||
.put(Swift5ClientCodegen.SWIFT_PACKAGE_PATH, SWIFT_PACKAGE_PATH_VALUE)
|
||||
.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")
|
||||
.build();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user