[BUG][dart][dart-dio] required fields are nullable in generated files
Created by: valebedu
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
When trying to generate dart-dio api client with open api specification with required fields, they are ignored by default.
I know that a nullableFields option is available for generation but there is only 2 possibles output:
- all fields are nullable
- all fields are non nullable
Why there is no way to have only required fields non nullable?
openapi-generator version
os: macOS os version: 10.15.2 openapi-generator version: 4.2.3 node version: 10.15.2 npm version: 6.13.4
OpenAPI declaration file content or url
Command line used for generation
npm install
npm run client:generate
with the following package.json
{
"name": "dart-dio-gen",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"client:generate": "rm -rf client/ && openapi-generator generate --generator-name dart-dio --input-spec petstore.yaml --output client/"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@openapitools/openapi-generator-cli": "^1.0.10-4.2.3"
}
}
Steps to reproduce
After generation, just have a look at client/model/pet.dart
for example
Obtained generate file:
import 'package:openapi/model/tag.dart';
import 'package:built_collection/built_collection.dart';
import 'package:openapi/model/category.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'pet.g.dart';
abstract class Pet implements Built<Pet, PetBuilder> {
@nullable
@BuiltValueField(wireName: r'id')
int get id;
@nullable
@BuiltValueField(wireName: r'category')
Category get category;
@nullable
@BuiltValueField(wireName: r'name')
String get name;
@nullable
@BuiltValueField(wireName: r'photoUrls')
BuiltList<String> get photoUrls;
@nullable
@BuiltValueField(wireName: r'tags')
BuiltList<Tag> get tags;
/* pet status in the store */
@nullable
@BuiltValueField(wireName: r'status')
String get status;
//enum statusEnum { available, pending, sold, };
// Boilerplate code needed to wire-up generated code
Pet._();
factory Pet([updates(PetBuilder b)]) = _$Pet;
static Serializer<Pet> get serializer => _$petSerializer;
}
Expected generated file:
import 'package:openapi/model/tag.dart';
import 'package:built_collection/built_collection.dart';
import 'package:openapi/model/category.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'pet.g.dart';
abstract class Pet implements Built<Pet, PetBuilder> {
@nullable
@BuiltValueField(wireName: r'id')
int get id;
@nullable
@BuiltValueField(wireName: r'category')
Category get category;
@BuiltValueField(wireName: r'name')
String get name;
@BuiltValueField(wireName: r'photoUrls')
BuiltList<String> get photoUrls;
@nullable
@BuiltValueField(wireName: r'tags')
BuiltList<Tag> get tags;
/* pet status in the store */
@nullable
@BuiltValueField(wireName: r'status')
String get status;
//enum statusEnum { available, pending, sold, };
// Boilerplate code needed to wire-up generated code
Pet._();
factory Pet([updates(PetBuilder b)]) = _$Pet;
static Serializer<Pet> get serializer => _$petSerializer;
}