question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[DART] Add null-safety for dart 2.12+

See original GitHub issue

Is your feature request related to a problem? Please describe.

Starting with DART 2.12 dart packages support sound null-safety making it easy to detect common pitfalls during static analysis.

The current implementation of DART2 does not follow null-safety principles.

Describe the solution you’d like

The generated code should follow sound null-safety as per https://dart.dev/null-safety.

If an openapi field is not marked as required, it should be nullable by default: eg:

    Customer:
      type: object
      required:
        - name
        - tenant_id
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
        created_at:
          type: string
          format: date-time
          readOnly: true
        updated_at:
          type: string
          format: date-time
          readOnly: true
        created_by:
          type: string
          format: uuid
          readOnly: true
        tenant_id:
          type: string
          format: uuid
        name:
          type: string
          minLength: 3
          maxLength: 50

should generate a class Customer with fields like String? id, String tenantId, String name, Datetime? createdAt

Describe alternatives you’ve considered

Use the legacy mode until null-safety is supported.

Additional context

Required by https://github.com/gibahjoe/openapi-generator-dart/issues/26

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:34
  • Comments:30 (22 by maintainers)

github_iconTop GitHub Comments

13reactions
agilobcommented, Aug 27, 2021

If no one else contributes this fix, I’ll do it sometime in September

10reactions
agilobcommented, Sep 29, 2021

yup, will open PR very soon

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating to null safety - Dart
This page describes how and when to migrate your code to null safety. Here are the basic steps for migrating each package that...
Read more >
How to enable Null-Safety in Flutter? - dart - Stack Overflow
Enabling null safety · Set the lower Dart SDK constraint to 2.12 in your pubspec.yaml file. · Check if all the packages of...
Read more >
Dart 2.12 release — Null Safety - Evan Fang - Medium
Null safety is a very powerful feature that can prevent your app from NullPointException . You can clearly declare whether a variable can...
Read more >
How To Use Null Safety in Dart 2.12 - Better Programming
With null safety enabled in Flutter/Dart, you cannot have any variable that is equal to null unless you specify it. That is very...
Read more >
Dart 2.12 has been released, with null-safety and C ...
In Dart 2.12, there's now full support for null-safety, with a syntax similar to Swift and Kotlin. There's even smart-casting, where if Dart...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found