question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
raffomaniacommented, May 11, 2021

Okay, thanks for clarifying! Is there a chance we might be able to add a warning when these are used, to save future users from looking up these issues?

2reactions
kuhnroyalcommented, May 11, 2021

Good idea, I will see if I get around to this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

oneOf, anyOf, allOf, not - Swagger
oneOf – validates the value against exactly one of the subschemas; allOf ... Besides these, there is a not keyword which you can...
Read more >
Declarative Pipeline - Use of when condition, how to do ...
There are two issues here in the declarative conditionals. First, looking at: allOf { expression{env.BRANCH_NAME != 'master'} expression{env ...
Read more >
Pipeline Syntax - Jenkins
If an anyOf condition is used, note that the condition skips remaining tests as soon as the first "true" condition is found. More...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found