Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #5411
Closed
Open
Issue created Feb 23, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml

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;

}
Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking