Skip to content

[BUG][dart-dio-next] Emit warning when allOf or anyOf are present #9443

@raffomania

Description

@raffomania

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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? See Description.
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
openapi-generator version

The bug appears with the OpenAPI generator versions 5.1.0, 5.1.1, 5.1.1-snapshot, 5.2.0-snapshot, 6.0.0-snapshot.

OpenAPI declaration file content or url
      "User": {
        "type": "object",
        "required": [
          "global_role"
        ],
          "global_role": {
            "$ref": "#/components/schemas/GlobalRole"
          },
        }
      },
      "GlobalRole": {
        "type": "string",
        "enum": [
          "SuperAdmin",
          "Auditor",
          "Employee"
        ]
      }
Description

Given the above schemata, the following dart code will be generated for updating a user in lib/src/models/user_update.dart:

  @override
  UserUpdate deserialize(Serializers serializers, Iterable<Object?> serialized,
      {FullType specifiedType = FullType.unspecified}) {
    final result = UserUpdateBuilder();

    final iterator = serialized.iterator;
    while (iterator.moveNext()) {
      final key = iterator.current as String;
      iterator.moveNext();
      final Object? value = iterator.current;
      switch (key) {
        case r'global_role':
          result.globalRole.replace(serializers.deserialize(value,
              specifiedType: const FullType(GlobalRole)) as GlobalRole);
          break;
      }
    }
    return result.build();
  }

And a lib/src/models/role.dart:

class GlobalRole extends EnumClass {
  @BuiltValueEnumConst(wireName: r'super_admin')
  static const GlobalRole superAdmin = _$superAdmin;
  @BuiltValueEnumConst(wireName: r'auditor')
  static const GlobalRole auditor = _$auditor;
  @BuiltValueEnumConst(wireName: r'employee')
  static const GlobalRole employee = _$employee;

  static Serializer<GlobalRole> get serializer => _$globalRoleSerializer;

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

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

This fails to build with the following Error:

lib/src/model/user_update.dart:96:29: Error: The method 'replace' isn't defined for the class 'GlobalRole?'.
 - 'GlobalRole' is from 'package:api/src/model/global_role.dart' ('api/lib/src/model/global_role.dart').
Try correcting the name to the name of an existing method, or defining a method named 'replace'.
          result.globalRole.replace(serializers.deserialize(value,
                            ^^^^^^^
Generation Details
generate -g dart-dio-next -o ./api -i openapi.yml -p pubName=api --enable-post-process-file

I'm using the dart-dio-next generator. Dart version is 2.12.3.

Steps to reproduce
  1. Generate a client containing the schemata included above.
  2. Include the generated api in a dart project.
  3. compile the dart project.
Related issues/PRs

I have searched thoroughly for dart issues containing the keywords "enum" or "replace" but found nothing.

Suggest a fix

I've tried to locate the line responsible for the creating the generated code in question, but could not find it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions