String Binary File is just expecting BytesIO and not filename and mime-type
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start with the generated types.py and the File.from_dict code shown in the issue, then trace how binary string schemas are represented during response or request parsing. Reproduce the supplied FileRequest upload case and verify that the resulting File preserves payload, filename, and MIME type rather than only the binary data.
Written by the indexing model from the issue text.
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
- Dominant language
- Python
- Stars
- 2k
- Forks
- 293
- Avg merge
- 34m
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from openapi-generators/openapi-python-client
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
openapi-generators/openapi-python-client#1451 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
-
Difficulty 3/5 1-2 days Newbie friendliness 64/100
openapi-generators/openapi-python-client#1435 · 1 comment ·
All issues in openapi-generators/openapi-python-client
Similar issues
-
essnmx good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
[Feature] 奇物选择添加优先级 Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
syfoud/Simulated_Scepter#174 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Giskard-AI/giskard-oss#2840 · 1 comment ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Openarea: repo bug perceived difficulty: 2
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
yeti-platform/yeti#1380 ·