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

When using the dio generator the resulting JSON serialization code is wrong #87

Open
dominikIncibit opened this issue Apr 11, 2023 · 0 comments

Comments

@dominikIncibit
Copy link

When using the following input:
/session/login: post: tags: - session summary: Endpoint for user-login and getting the session key requestBody: content: application/json: schema: type: object properties: user: type: string pass: type: string format: md5 seq: type: string format: number

using the dio generator it results in the following JSON generation code:
@override Iterable<Object?> serialize(Serializers serializers, SessionMobileLoginPostRequest object, {FullType specifiedType = FullType.unspecified}) { final result = <Object?>[]; if (object.user != null) { result ..add(r'user') ..add(serializers.serialize(object.user, specifiedType: const FullType(String))); } if (object.pass != null) { result ..add(r'pass') ..add(serializers.serialize(object.pass, specifiedType: const FullType(String))); } if (object.seq != null) { result ..add(r'seq') ..add(serializers.serialize(object.seq, specifiedType: const FullType(double))); } return result; }
Unfortunately this code is wrong and results in the object being transformed to an array type (which is wrong and the api doesnt accept this).

However using the dart generator the resulting code perfectly fine:
Map<String, dynamic> toJson() { final _json = <String, dynamic>{}; if (user != null) { _json[r'user'] = user; } if (pass != null) { _json[r'pass'] = pass; } if (seq != null) { _json[r'seq'] = seq; } return _json; }

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

No branches or pull requests

1 participant