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
  • #11250
Closed
Open
Issue created Jan 07, 2022 by Administrator@rootContributor

[DART-DIO-NEXT] error using query parameter with BuiltList of EnumClass

Created by: ktnishide

@kuhnroyal @agilob

Hi everyone!

Is there any workaround for handling an array of enum on query parameters like below? image

I am getting the following error:

[log] type 'String' is not a subtype of type 'SearchType' in type cast
[log] #0      _CastListBase.[] (dart:_internal/cast.dart:99:46)
#1      ListMixin.elementAt (dart:collection/list.dart:78:33)
#2      ListIterator.moveNext (dart:_internal/iterable.dart:342:26)
#3      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:188:27)
#4      new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#5      new List.of (dart:core-patch/array_patch.dart:51:28)
#6      encodeCollectionQueryParameter

Generated code causing the error: api_util.dart

ListParam<T> encodeCollectionQueryParameter<T>(
  Serializers serializers,
  dynamic value,
  FullType type, {
  ListFormat format = ListFormat.multi,
}) {
  final serialized = serializers.serialize(
    value as Object,
    specifiedType: type,
  );
  if (value is BuiltList<T> || value is BuiltSet<T>) {
    return ListParam(List.of((serialized as Iterable<Object?>).cast()), format);
  }
  throw ArgumentError('Invalid value passed to encodeCollectionQueryParameter');
}

OpenApi Spec:

  /feed:
    get:
      tags:
        - FeedApi
      parameters:
        - name: state
          in: query
          schema:
            type: string
            format: string
        - name: top
          in: query
          schema:
            type: integer
            format: int32
        - name: skip
          in: query
          schema:
            type: integer
            format: int32
        - name: contentType
          in: query
          schema:
            type: array
            items:
              $ref: '#/components/schemas/SearchType'
        - name: categories
          in: query
          schema:
            type: array
            items:
              $ref: '#/components/schemas/AppArticleCategory'
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/FeedItemViewModel'
      x-operation-name: get
...
components:
  schemas:
    AppArticleCategory:
      enum:
        - StudentLife
        - CareerAndMoney
        - HealthAndRelationship
        - MoneyAndFinance
      type: string
    SearchType:
      enum:
        - All
        - Article
        - PartTimeJob
        - Career
        - Course
        - Offer
        - Competition
        - ForumThread
        - Survey
      type: string

Originally posted by @ktnishide in https://github.com/OpenAPITools/openapi-generator/issues/8536#issuecomment-1007127742

Assignee
Assign to
Time tracking