Skip to content

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

@dominikIncibit

Description

@dominikIncibit

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; }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions