gibahjoe / openapi-generator-dart

Openapi Generator for Dart/Flutter
BSD 3-Clause "New" or "Revised" License
123 stars 34 forks source link

List of enumerated types errors with... isn't a type so it can't be used as a type argument. #56

Closed bobwith2bees closed 3 years ago

bobwith2bees commented 3 years ago

Just kicking the tires on the flutter package, trying to build an early version of the rarible protocol. (So the protocol.yaml is also a suspect.)

I see two flavors of errors, focusing on one for now.
error: The name 'xxxxEnum' isn't a type so it can't be used as a type argument.

I think this is an example- https://ethereum-api.rarible.org/v0.1/doc#tag/nft-order-activity-controller

It appears when there is a List of Enumerated Types, something goes wrong serializing/deserializing.

    ActivityFilterByUser:
      type: "object"
      required:
      - "@type"
      - "types"
      - "users"
      properties:
        '@type':
          type: "string"
          enum:
          - "by_user"
        users:
          type: "array"
          items:
            $ref: "#/components/schemas/Address"
        types:
          type: "array"
          items:
            type: "string"
            enum:
            - "TRANSFER_FROM"
            - "TRANSFER_TO"
            - "MINT"
            - "BURN"
            - "MAKE_BID"
            - "GET_BID"
            - "LIST"
            - "BUY"
            - "SELL"
# multiple errors but they are all likely the same root cause. Including for completeness
error: The name 'ActivityFilterTypesEnum' isn't a type so it can't be used as a type argument. (non_type_as_type_argument at [rarible] lib/src/model/activity_filter.dart:29)
error: The values in a const list literal must be constants. (non_constant_list_element at [rarible] lib/src/model/activity_filter.dart:69)
error: Undefined name 'ActivityFilterTypesEnum'. (undefined_identifier at [rarible] lib/src/model/activity_filter.dart:69)
error: The argument type 'dynamic' can't be assigned to the parameter type 'Type?'. (argument_type_not_assignable at [rarible] lib/src/model/activity_filter.dart:69)
error: Arguments of a constant creation must be constant expressions. (const_with_non_constant_argument at [rarible] lib/src/model/activity_filter.dart:69)

Reproduction Steps:

# Just a glorified example project that reproduces the error
git clone https://gitlab.com/graflr/rarible_nft.git
cd rarible_nft
git checkout issue56
flutter pub get  
flutter pub run build_runner build --delete-conflicting-outputs --verbose

# Everything seems to work, but as soon as you include the library in the example/lib/main.dart you can see all the errors in the IDE

I have tried various permutations of Generator.dioNext, and useEnumExtension: true. There is always the possibility of operator error on my part, but I did attempt to do my homework before asking for help. Thanks.

gibahjoe commented 3 years ago

Hi, What version of the library are you using?

bobwith2bees commented 3 years ago

This should match the debug, the repo may be set to just Generator.dart.

  openapi_generator_annotations: 3.2.0
  openapi_generator: 3.2.0+2

---
@Openapi(
    additionalProperties: AdditionalProperties(
      pubName: 'rarible',
      pubAuthor: 'rarible.org',
    ),
    inputSpecFile: 'example/rarible_ethereum_api_v0.1.yaml',
    generatorName: Generator.dioNext,
    outputDirectory: 'api/rarible')
bobwith2bees commented 3 years ago

image

gibahjoe commented 3 years ago

Hi, having looked into this, the issue is with the generator not generating List of enums correctly.

I have raised an issue with the Openapi generator library authors here.

I have also downloaded and modified the spec to work using a work around I found
openapi.yaml.zip

Also, you should update your annotation to below to prevent the Lock model from clashing with the one in Dio

@Openapi(
    additionalProperties: AdditionalProperties(
      pubName: 'rarible',
      pubAuthor: 'rarible.org',
    ),
typeMappings:{'Lock':'RaribleLock'}, //add this line
    inputSpecFile: 'example/rarible_ethereum_api_v0.1.yaml',
    generatorName: Generator.dioNext,
    outputDirectory: 'api/rarible')

Hope this helps

gibahjoe commented 3 years ago

let me know if you need further assistance

bobwith2bees commented 3 years ago

Wow - thanks for the super-thorough follow up. You even addressed the second issue I was seeing, but didn't ask!

bobwith2bees commented 3 years ago

I added a label to my repo for completeness and updated the reproduction steps in case someone wants to reproduce it in the future.

You have me working with the workaround. Do you need me to close the issue, or do you want to keep it open until the upstream fix is available? Just let me know if you need anything on my side. Thanks again!

gibahjoe commented 3 years ago

No problem.