Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dio can not set serializer #152

Closed
nathansamson opened this issue Sep 15, 2024 · 1 comment · Fixed by #158, #159 or #162
Closed

Dio can not set serializer #152

nathansamson opened this issue Sep 15, 2024 · 1 comment · Fixed by #158, #159 or #162
Labels
bug Something isn't working

Comments

@nathansamson
Copy link

Description of the bug

The json Serializer is not working

Steps to reproduce

Use the following code

@Openapi(
  additionalProperties:
      DioProperties(
        pubName: '...',
        pubAuthor: '...',
        serializationLibrary: DioSerializationLibrary.jsonSerializable
      ),
  inputSpec: InputSpec(path: 'my-api.json'),
  generatorName: Generator.dio,
  outputDirectory: 'my-api/',
)
class ApiGenerator {}

Run
fvm dart run build_runner build (fvm might not be needed depending on install of dart, I use it with fvm and flutter)

Expected behavior

The API is built WITH Build_value as JSON serializer (the default) instead of the chosen JSON Serializer.

Logs

~~~
[INFO] openapi_generator on lib/core/api_generator.dart:Loaded cached and current spec files.
[INFO] openapi_generator on lib/core/api_generator.dart:Dirty Spec found. Running generation.
[INFO] openapi_generator on lib/core/api_generator.dart:Running following command to generate openapi client - [ generate -o=heelo-api/ -i=lib/core/api.json -g=dart-dio --additional-properties=allowUnicodeIdentifiers=false,ensureUniqueParams=true,useEnumExtension=true,enumUnknownDefaultCase=false,prependFormOrBodyParameters=false,pubAuthor=Heelo BV,pubName=heelo_api,legacyDiscriminatorBehavior=true,sortModelPropertiesByRequiredFlag=true,sortParamsByRequiredFlag=true,wrapper=none ]
[INFO] openapi_generator on lib/core/api_generator.dart:Openapi generator completed successfully.
~~~

Note it does NOT include the json serializer code


When  I change the openapi generator code (and point to it by path) with the following code it does work....

~~~
--- a/openapi-generator-annotations/lib/src/openapi_generator_annotations_base.dart
+++ b/openapi-generator-annotations/lib/src/openapi_generator_annotations_base.dart
@@ -664,8 +664,10 @@ class EnumTransformer {
   static DioSerializationLibrary? dioSerializationLibrary(String? name) {
     switch (name) {
       case 'json_serializable':
+      case 'jsonSerializable':
         return DioSerializationLibrary.jsonSerializable;
       case 'built_value':
+      case 'builtValue':
         return DioSerializationLibrary.builtValue;
     }
     return null;
~~~

Screenshots

No response

Platform

Linux

Library version

5.0.2

Flutter version

3.24.1

Flutter channel

stable

Additional context

[✓] Flutter (Channel stable, 3.24.1, on Fedora Linux 40 (Workstation Edition) 6.10.8-200.fc40.x86_64, locale
    en_GB.UTF-8)
    • Flutter version 3.24.1 on channel stable at /home/nathan/fvm/versions/3.24.1
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5874a72aa4 (4 weeks ago), 2024-08-20 16:46:00 -0500
    • Engine revision c9b9d5780d
    • Dart version 3.5.1
    • DevTools version 2.37.2
@nathansamson nathansamson added the bug Something isn't working label Sep 15, 2024
@philitell
Copy link

philitell commented Oct 12, 2024

Yes i can confirm that - please fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants