Created by: kuronekomichael
PR checklist
-
Read the contribution guidelines. -
Ran the shell script under ./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
. -
Filed the PR against the correct branch: master
,3.1.x
,4.0.x
. Default:master
. -
Copied the technical committee to review the pull request if your PR is targeting a particular programming language.
Description of the PR
[Only Dart-lang
]
-
If the definition includes format: date
, it will not be treated as a date type and will call an incorrect methodDateTime.fromJson()
which does not exist -
If the property name is underscore_case, the name will always be changed to lowerCamelcase and will be accessed with an incorrect property name
Example
swagger: '2.0'
info:
version: 1.0.0
title: Simplest OpenAPI Sample
paths:
/me/status:
get:
operationId: getMyStatus
consumes:
- application/json
produces:
- application/json
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/Status'
'405':
description: Invalid input
definitions:
Status:
type: object
properties:
created_at:
type: string
format: date-time
birthDate:
type: string
format: date
avatar_url:
type: string
When generated from the above yaml file, the difference in output is as follows.
diff -r -u master/lib/model/status.dart fixed/lib/model/status.dart
@@ -16,15 +16,15 @@
Status.fromJson(Map<String, dynamic> json) {
if (json == null) return;
- createdAt = json['createdAt'] == null ? null : DateTime.parse(json['createdAt']);
- birthDate = new DateTime.fromJson(json['birthDate']);
- avatarUrl = json['avatarUrl'];
+ createdAt = json['created_at'] == null ? null : new DateTime.fromMillisecondsSinceEpoch(json['created_at'].toInt() * 1000);
+ birthDate = json['birthDate'] == null ? null : DateTime.parse(json['birthDate']);
+ avatarUrl = json['avatar_url'];
}
Map<String, dynamic> toJson() {
return {
'createdAt': createdAt == null ? '' : createdAt.toUtc().toIso8601String(),
- 'birthDate': birthDate,
+ 'birthDate': birthDate == null ? '' : birthDate.toUtc().toIso8601String(),
'avatarUrl': avatarUrl
};
}
json['createdAt']
is invalid property name.
json['created_at']
is correct
new DateTime.fromJson(json['birthDate']);
throws an error. DateTime
don't have fromJson
method.
DateTime.parse(json['birthDate']);
is correct.
@ircecho Please help me!