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
  • #6727
Closed
Open
Issue created Jun 20, 2020 by Administrator@rootContributor5 of 5 checklist items completed5/5 checklist items

[BUG][Dart] Generated Enum is a string without validation

Created by: agilob

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?
Description

Requested generated Enum is a string without validation.

openapi-generator version

4.3.1

OpenAPI declaration file content or url

If you post the code inline, please wrap it with


components:
  schemas:
    Sorting:
      type: object
      description: sorting order
      properties:
        sortingOrder:
          type: string
          enum: [asc, desc]

Generates:

part of openapi.api;

class Sorting {
  
  String sortingOrder = null;
  //enum sortingOrderEnum {  asc,  desc,  };{
  Sorting();

  @override
  String toString() {
    return 'Sorting[sortingOrder=$sortingOrder, ]';
  }

  Sorting.fromJson(Map<String, dynamic> json) {
    if (json == null) return;
    sortingOrder = json['sortingOrder'];
  }

  Map<String, dynamic> toJson() {
    Map <String, dynamic> json = {};
    if (sortingOrder != null)
      json['sortingOrder'] = sortingOrder;
    return json;
  }

  static List<Sorting> listFromJson(List<dynamic> json) {
    return json == null ? List<Sorting>() : json.map((value) => Sorting.fromJson(value)).toList();
  }

  static Map<String, Sorting> mapFromJson(Map<String, dynamic> json) {
    var map = Map<String, Sorting>();
    if (json != null && json.isNotEmpty) {
      json.forEach((String key, dynamic value) => map[key] = Sorting.fromJson(value));
    }
    return map;
  }

  // maps a json object with a list of Sorting-objects as value to a dart map
  static Map<String, List<Sorting>> mapListFromJson(Map<String, dynamic> json) {
    var map = Map<String, List<Sorting>>();
     if (json != null && json.isNotEmpty) {
       json.forEach((String key, dynamic value) {
         map[key] = Sorting.listFromJson(value);
       });
     }
     return map;
  }
}
Command line used for generation

openapi-generator generate -i openapi-spec.yaml -g dart --skip-validate-spec -o lib/generated --additional-properties=pubName=agilob,useEnumExtension=true

Assignee
Assign to
Time tracking