Skip to content

Support UTF-8 characters (e.g. Hebrew) #43

@orenagiv

Description

@orenagiv

Hey,
While using the LangChain.dart package, which uses the openapi_spec package, I've noticed that if the OpenAI response includes characters in Hebrew or other languages with special characters - it results with "gibberish".

This is most probably due to client.dart > lines 883 and 896, where json.decode is done over r.body:
https://github.com/search?q=repo%3Atazatechnology%2Fopenapi_spec+json.decode%28r.body%29&type=code

It seems that due to this Dart issue:
dart-lang/http#789

The json.decode should be done with utf8.decode over the r.bodyBytes, in order to properly handle the UTF-8 chars:

if (s.ref != null || returnType.startsWith('Union')) {
  decoder = "return $returnType.fromJson(json.decode(utf8.decode(r.bodyBytes)));";
} else {
  decoder = """
    final list = json.decode(utf8.decode(r.bodyBytes)) as List;
    return list.map((e) => ${s.items.ref}.fromJson(e)).toList();

I've manually manipulated the generated client.dart file - and it resolved the problem.
However, unfortunately, due to lack of time I'm unable to test this properly and submit a Pull Request...
I hope the maintainers will have to take a look soon.

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