Open
Description
I have Java OpenAPI server which provides an upload endpoint (POST) that expect as schema a FileRequest ( schema = @Schema(implementation = FileRequest.class)
)
The FileRequest looks like:
@Value.Immutable
@JsonDeserialize(builder = com.mydata.request.FileRequest.Builder.class)
public abstract class FileRequest implements FileFields {
@Schema(type = "string", format = "binary", description = "File")
@JsonProperty
public abstract String file();
public static class Builder extends ImmutableFileRequest.Builder {
}
}
Looking at the generated code, the models looks good. This is the relevant part on types.py:
@attr.s(auto_attribs=True)
class File:
""" Contains information for file uploads """
payload: BinaryIO
file_name: Optional[str] = None
mime_type: Optional[str] = None
def to_tuple(self) -> FileJsonType:
""" Return a tuple representation that httpx will accept for multipart/form-data """
return self.file_name, self.payload, self.mime_type
T = TypeVar("T")
However, looking at the upload endpoint request, it doesn't expect the Optional values above:
@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()
_file = d.pop("file", UNSET)
file: Union[Unset, File]
if isinstance(_file, Unset):
file = UNSET
else:
file = File(
payload = BytesIO(_file)
)
Notice that the File expects only the binary data, losing the filename and mimetype.
Expected behavior
I would expect that the generated code would look something like below, which I patched and am using currently:
else:
file = File(
payload = BytesIO(_file['payload']),
file_name=_file['filename']
)
Desktop (please complete the following information):
- OS: Linux, but irrelevant
- openapi-python-client version: 0.11.1
- Python 3.8.10
- openapi: 3.0.1