-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
fix(dart-dio): use enum type for discriminator when property is enum #24153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| openapi: 3.0.3 | ||
| info: | ||
| title: Dart Dio Enum Discriminator | ||
| version: 1.0.0 | ||
| paths: | ||
| /merchant: | ||
| get: | ||
| responses: | ||
| '200': | ||
| description: ok | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/MerchantDetailsDto' | ||
| components: | ||
| schemas: | ||
| MerchantDetailsDto: | ||
| type: object | ||
| properties: | ||
| uuid: | ||
| type: string | ||
| format: uuid | ||
| merchantType: | ||
| $ref: '#/components/schemas/MerchantTypeEnum' | ||
| required: | ||
| - uuid | ||
| - merchantType | ||
| discriminator: | ||
| propertyName: merchantType | ||
| mapping: | ||
| TYPE_A: '#/components/schemas/MerchantDetailsTypeADto' | ||
| TYPE_B: '#/components/schemas/MerchantDetailsTypeBDto' | ||
| MerchantDetailsTypeADto: | ||
| allOf: | ||
| - $ref: '#/components/schemas/MerchantDetailsDto' | ||
| - type: object | ||
| properties: | ||
| aField: | ||
| type: string | ||
| MerchantDetailsTypeBDto: | ||
| allOf: | ||
| - $ref: '#/components/schemas/MerchantDetailsDto' | ||
| - type: object | ||
| properties: | ||
| bField: | ||
| type: string | ||
| MerchantTypeEnum: | ||
| type: string | ||
| enum: | ||
| - TYPE_A | ||
| - TYPE_B |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,25 +46,25 @@ abstract class Fruit implements Built<Fruit, FruitBuilder> { | |
| } | ||
|
|
||
| extension FruitDiscriminatorExt on Fruit { | ||
| String? get discriminatorValue { | ||
| FruitType get discriminatorValue { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||
| if (this is Apple) { | ||
| return r'APPLE'; | ||
| return FruitType.valueOf(r'APPLE'); | ||
| } | ||
| if (this is Banana) { | ||
| return r'BANANA'; | ||
| return FruitType.valueOf(r'BANANA'); | ||
| } | ||
| return null; | ||
| throw UnsupportedError('Invalid discriminator value for Fruit'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Prompt for AI agents |
||
| } | ||
| } | ||
| extension FruitBuilderDiscriminatorExt on FruitBuilder { | ||
| String? get discriminatorValue { | ||
| FruitType get discriminatorValue { | ||
| if (this is AppleBuilder) { | ||
| return r'APPLE'; | ||
| return FruitType.valueOf(r'APPLE'); | ||
| } | ||
| if (this is BananaBuilder) { | ||
| return r'BANANA'; | ||
| return FruitType.valueOf(r'BANANA'); | ||
| } | ||
| return null; | ||
| throw UnsupportedError('Invalid discriminator value for FruitBuilder'); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Passing the wire discriminator value (
mappingName) to built_valueEnumClass.valueOf()is incorrect becausevalueOfexpects the generated Dart constant name, not the wire name. When the wire value differs from the Dart identifier (e.g.,in-progressvsinProgress), this will throw at runtime.Prompt for AI agents