[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?
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