OpenAPITools / OpenAPITools/openapi-generator

[BUG] [DART-DIO] enumUnknownDefaultCase config ignored with useEnumExtension configuration

Open
#21,411 0 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

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

I use the dart-dio generator with config options:

useEnumExtension: 'true',
enumUnknownDefaultCase: 'true'

When the config option useEnumExtension is activated, the enumUnknownDefaultCase option is ignored and no enum case unknownDefaultOpenApi is generated.

openapi-generator version

I'm using version 7.13.0 (no regression).

OpenAPI declaration file content or url

Example with an enum:

openapi: 3.0.0

info:
  title: test
  version: 0.0.1

paths:
  /test:
    get:
      description: test
      responses:
        "200":
          description: test
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MyEnum"


components:
  schemas:
    MyEnum:
      type: integer
      x-enum-values:
        - identifier: case1
          numericValue: 1
        - identifier: case2
          numericValue: 2
      enum:
        - 1
        - 2

with both config options useEnumExtension and enumUnknownDefaultCase on we get:

java -jar openapi-generator-cli-7.14.0-20250602.083235-44.jar generate -i api.yaml -g dart-dio -o generate -p useEnumExtension=true,enumUnknownDefaultCase=true
class MyEnum extends EnumClass {

  @BuiltValueEnumConst(wireNumber: 1)
  static const MyEnum case1 = _$case1;
  @BuiltValueEnumConst(wireNumber: 2, fallback: true)
  static const MyEnum case2 = _$case2;

  static Serializer<MyEnum> get serializer => _$myEnumSerializer;

  const MyEnum._(String name): super(name);

  static BuiltSet<MyEnum> get values => _$values;
  static MyEnum valueOf(String name) => _$valueOf(name);
}

When only enumUnknownDefaultCase is active, the unknownDefaultOpenApi case is generated:

java -jar openapi-generator-cli-7.14.0-20250602.083235-44.jar generate -i api.yaml -g dart-dio -o generate -p enumUnknownDefaultCase=true
class MyEnum extends EnumClass {

  @BuiltValueEnumConst(wireNumber: 1)
  static const MyEnum number1 = _$number1;
  @BuiltValueEnumConst(wireNumber: 2)
  static const MyEnum number2 = _$number2;
  @BuiltValueEnumConst(wireNumber: 11184809, fallback: true)
  static const MyEnum unknownDefaultOpenApi = _$unknownDefaultOpenApi;

  static Serializer<MyEnum> get serializer => _$myEnumSerializer;

  const MyEnum._(String name): super(name);

  static BuiltSet<MyEnum> get values => _$values;
  static MyEnum valueOf(String name) => _$valueOf(name);
}

Expected generated enum contains both the named cases and the unknownDefault case:

class MyEnum extends EnumClass {

  @BuiltValueEnumConst(wireNumber: 1)
  static const MyEnum case1 = _$case1;
  @BuiltValueEnumConst(wireNumber: 2, fallback: true)
  static const MyEnum case2 = _$case2;
  @BuiltValueEnumConst(wireNumber: 11184809, fallback: true)
  static const MyEnum unknownDefaultOpenApi = _$unknownDefaultOpenApi;
  
  static Serializer<MyEnum> get serializer => _$myEnumSerializer;

  const MyEnum._(String name): super(name);

  static BuiltSet<MyEnum> get values => _$values;
  static MyEnum valueOf(String name) => _$valueOf(name);
}
Generation Details
  • Language: Dart
  • Generator: dart-dio
  • Version: 7.13.0
  • Generator options:
    • useEnumExtension: true,
    • enumUnknownDefaultCase: true
Steps to reproduce

Define an enum with x-enum-values.
Use generator language dart-dio and activate options useEnumExtension, enumUnknownDefaultCase

IS:
Enums are generated without unknown default case.

SHOULD:
Enums are generated with Unknown default case and named cases.

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 api.yaml enum example and the two dart-dio generation commands shown in the issue, comparing output with each configuration combination. Done means generation with both useEnumExtension=true and enumUnknownDefaultCase=true produces the named cases plus unknownDefaultOpenApi as the fallback case.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.