OpenAPITools / OpenAPITools/openapi-generator

[BUG] Unsure if openapi-generator is producing null-safe api code

Open
#12,609 2 comments 0 reactions 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

Description

I'm trying to produce null-safe api code from swagger json docs so we can upgrade Dart to 2.17. I understood from the docs that the newest version should produce null safe api code and models, but it doesn't look null safe to me.

openapi-generator version

openapi_generator_annotations: ^3.3.0
openapi_generator_cli: 3.0.0-nullsafety.1

Not a regression

OpenAPI declaration file content or url

mv ../lib/generated/asn/lib/* ../lib/generated/asn
rm -r ../lib/generated/asn/.openapi-generator
rm -r ../lib/generated/asn/.openapi-generator-ignore
rm -r ../lib/generated/asn/.travis.yml
rm -r ../lib/generated/asn/pubspec.yaml
rm -r ../lib/generated/asn/git_push.sh
rm -r ../lib/generated/asn/README.md
rm -r ../lib/generated/asn/.gitignore
rm -r ../lib/generated/asn/lib

Input is a basic swagger doc

Portion of output:

part of openapi.api;

class AsnOrder {
/// Returns a new [AsnOrder] instance.
AsnOrder({
this.asnId,
this.asnOrderId,
this.asnOrderLine = const [],
this.createDateTime,
this.createdId,
this.dcNumber,
this.lastUpdatedTime,
this.masterShippingNumber,
this.modifiedId,
this.modifiedSource,
this.poVendor,
this.thdPo,
this.workOrderNumber,
});

String asnId;

String asnOrderId;

List asnOrderLine;

DateTime createDateTime;

String createdId;

String dcNumber;

DateTime lastUpdatedTime;

Generation Details

Script code to invoke api generation:

Asn Core

openapi-generator generate -i ./swagger-docs/asn.json -t ./templates/ -o ../lib/generated/asn -g dart --skip-validate-spec -c ./config/asn-config.json
--global-property modelTests=false,modelDocs=false,apiTests=false,apiDocs=false

Steps to reproduce
Related issues/PRs
Suggest a fix

Shouldn't my code produce a null check on each variable?

Not String asnId; as the script is producing now but String? asnId or String asnId = ''

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 the Dart generation command, ./templates/, ./config/asn-config.json, and swagger-docs/asn.json, then inspect the generated AsnOrder model shown in the report. Reproduce the output with the stated openapi-generator versions and determine whether the generated fields meet Dart 2.17 null-safety expectations; done means the output is consistently null-safe or the expected configuration is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.