OpenAPITools / OpenAPITools/openapi-generator

[dart-dio] non-nullable model fields defined as nullable in generated dart

Open
#14,320 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Using the example spec here the following snippet is generated

/// Outer
///
/// Properties:
/// * [results]
@BuiltValue()
abstract class Outer implements Built<Outer, OuterBuilder> {
  @BuiltValueField(wireName: r'results')
  BuiltList<int>? get results;
  Outer._();
  factory Outer([void updates(OuterBuilder b)]) = _$Outer;
  @BuiltValueHook(initializeBuilder: true)
  static void _defaults(OuterBuilder b) => b..results = ListBuilder();
  @BuiltValueSerializer(custom: true)
  static Serializer<Outer> get serializer => _$OuterSerializer();
}

When results is non-nullable I expect the type to be BuiltList<int> instead of BuiltList<int>?.

On this line you can see the template reads {{^isNullable}}{{^required}}?{{/required}}{{/isNullable}}, which seems backwards for the isNullable check.

Spec used to demonstrate issue is here
openapi-generator version: commit 031f0dcee692264681387bf8fbbece98f477801b (master as of now)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_members.mustache and compare its nullable and required conditionals with the reported output. Generate the Dart model from the linked example spec, then verify that the non-nullable results field is emitted as BuiltList rather than BuiltList?.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
api, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.