Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !567

Dart-lang template bugs fixed with "baseName"

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/kuronekomichael/fix/dart-template-bugs into master Jul 14, 2018
  • Overview 0
  • Commits 2
  • Pipelines 0
  • Changes 1

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 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!

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/kuronekomichael/fix/dart-template-bugs