OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.36k stars 6.46k forks source link

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

Open KimFromMarietta opened 2 years ago

KimFromMarietta commented 2 years ago
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 = ''

0xNF commented 2 years ago

3.0.0-nullsafety.1

This is pretty old isn't it? The current master branch is on 6.1.0.

kuhnroyal commented 1 year ago

3.x is way too old. Please try with a current version.