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

Dart-lang template bugs fixed with "baseName" #567

Merged
merged 2 commits into from
Jul 23, 2018

Conversation

kuronekomichael
Copy link
Contributor

@kuronekomichael kuronekomichael commented Jul 14, 2018

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 method DateTime.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!

Copy link
Contributor

@ackintosh ackintosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! It looks good to me.

@ackintosh ackintosh added this to the 3.1.2 milestone Jul 21, 2018
@wing328
Copy link
Member

wing328 commented Jul 21, 2018

I'll try to test locally tomorrow and approve if no question from me.

@wing328
Copy link
Member

wing328 commented Jul 23, 2018

Tested locally and the result is good.

@wing328 wing328 merged commit 2e1add8 into OpenAPITools:master Jul 23, 2018
@wing328
Copy link
Member

wing328 commented Jul 23, 2018

@kuronekomichael thanks for the PR, which has been merged into master.

@ackintosh thanks for reviewing the change.

@kuronekomichael kuronekomichael deleted the fix/dart-template-bugs branch July 23, 2018 16:16
@wing328 wing328 changed the title BugFix: Dart-lang template bugs BugFix: Dart-lang template bugs fixed with "baseName" Jul 25, 2018
@wing328 wing328 changed the title BugFix: Dart-lang template bugs fixed with "baseName" Dart-lang template bugs fixed with "baseName" Jul 25, 2018
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
* BugFix: [Dart] Cannot get/set data from json when underscore("_") is included in spec.yaml's property name

Because the property name is always lowerCamelCase

* BugFix: When type is "Date", it is not correctly output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants