Skip to content

Swift5: Binary / File type generated incorrectly as URL in responses #9308

@ghost

Description

After some investigation, the test issue when changing the type binary from URL to Data, is related to the code in ModelUtils line 659.

} else if (ModelUtils.isFileSchema(schema)) {
return "file";
} else if (ModelUtils.isBinarySchema(schema)) {
return SchemaTypeUtil.BINARY_FORMAT;

public static boolean isBinarySchema(Schema schema) {
if (schema instanceof BinarySchema) {
return true;
}
if (SchemaTypeUtil.STRING_TYPE.equals(schema.getType())
&& SchemaTypeUtil.BINARY_FORMAT.equals(schema.getFormat())) { // format: binary
return true;
}
return false;
}
public static boolean isFileSchema(Schema schema) {
if (schema instanceof FileSchema) {
return true;
}
// file type in oas2 mapped to binary in oas3
return isBinarySchema(schema);
}

The binary type will be considered as file type.

To add some interesting bits to the discussion
The Kotlin Client generator, considers binary as BiteArray (or Data in Swift) and file as java.io.File (or URL in Swift)

typeMapping.put("file", "java.io.File");
typeMapping.put("array", "kotlin.Array");
typeMapping.put("list", "kotlin.collections.List");
typeMapping.put("set", "kotlin.collections.Set");
typeMapping.put("map", "kotlin.collections.Map");
typeMapping.put("object", "kotlin.Any");
typeMapping.put("binary", "kotlin.ByteArray");

The Java Client generator, considers binary as byte[], and file as java.io.File.

Since this is a big change on how files/binary is treated in the Swift Generator that is also a breaking change, and doing things differently from the other generators worries me a bit, so I just would like to be sure that this is the right move, but let's continue this discussion on the new PR..

Originally posted by @4brunu in #9206 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions