[DART] Add null-safety for dart 2.12+
See original GitHub issueIs 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:
- Created 3 years ago
- Reactions:34
- Comments:30 (22 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If no one else contributes this fix, I’ll do it sometime in September
yup, will open PR very soon