Skip to content

[dart2] [client] Adds correct deserialization of octet-streams into Uint8List#17810

Open
0xNF wants to merge 1 commit intoOpenAPITools:masterfrom
0xNF:Dart2_fix_uint8list
Open

[dart2] [client] Adds correct deserialization of octet-streams into Uint8List#17810
0xNF wants to merge 1 commit intoOpenAPITools:masterfrom
0xNF:Dart2_fix_uint8list

Conversation

@0xNF
Copy link
Copy Markdown
Contributor

@0xNF 0xNF commented Feb 7, 2024

fix #12161

This PR is part of the effort to split PR #17548

This PR is a bit meatier than the others -- I copied much of the logic for adding uint8list support to the AbstractDartCodegen from the Dart-dio generator.

The big changes to look out for are:

  • octet streams now correctly deserde into Uint8List, instead of the previous MultipartFile (which was fine for uploads, but invalid for downloads)
  • decodeBodyBytes() and deserialize() now returns dynamic instead of String, which lets us switch on the content-type to return either a string, or a Uint8List.

@jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08)

… Uint8Lists (OpenAPITools#12161)

* Imported typed_data
* File and Binary response return types are now marked as Uint8List instead of MultipartFile, which was never semantically correct
* _decodeBodyBytes has been reworked to return either 'String' or 'Uint8List' based on the ContentType.
* _deserialize now returns 'dynamic' to work with the new _decodeBodyBytes
@0xNF 0xNF changed the title [dart2] [client] Adds correctly deserialization of octet-streams into Uint8List [dart2] [client] Adds correct deserialization of octet-streams into Uint8List Feb 7, 2024
Copy link
Copy Markdown
Contributor

@kuhnroyal kuhnroyal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a test project for this. Can anyone verify up/downloads?

}

private void configureSerializationLibrary(String srcFolder) {
additionalProperties.put("useJsonSerializable", "true");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used? I thought there is only native serialization.

@joelbrostrom
Copy link
Copy Markdown

Progress status?
We need this fix 🙏

@zoocityboy
Copy link
Copy Markdown

Progress status? We need this fix 🙏

if you want to fix this issue, than you can use your own template

config.yaml

templateDir: /template
typeMappings:
  "string+binary": "Uint8List"

template/serilaization/deserialize.mustache

...
  ReturnType deserialize<ReturnType, BaseType>(dynamic value, String targetType, {bool growable= true}) {
      switch (targetType) {
        case 'Uint8List':
          return value as ReturnType;
        case 'String':
          return '$value' as ReturnType;
        ....

then run

openapi-generator-cli generate \
-g dart-dio \
-i oas.yaml \
-o /package \
-c config.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [Dart] Response type of application/octet-stream with format: binary are unusable

4 participants