Skip to content
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

oneOf doesn't seem to be working properly #265

Closed
Robert-Stackflow opened this issue Oct 2, 2024 · 0 comments · Fixed by #287
Closed

oneOf doesn't seem to be working properly #265

Robert-Stackflow opened this issue Oct 2, 2024 · 0 comments · Fixed by #287

Comments

@Robert-Stackflow
Copy link

Robert-Stackflow commented Oct 2, 2024

Steps to reproduce

When an entity contains oneOf

I have found #5, but this issue seems to have not been resolved subsequently.My expectation is similar to #5 (comment).

Expected results

The fromJson function of InstructionUnion can automatically call the fromJson function of TimelineAddEntries and other classes according to the property type to construct.

Actual results

It only returns InstructionUnion()

Your OpenApi snippet

    InstructionUnion:
      discriminator:
        mapping":
          TimelineAddEntries: '#/components/schemas/TimelineAddEntries'
          TimelineAddToModule: '#/components/schemas/TimelineAddToModule'
          TimelineClearCache: '#/components/schemas/TimelineClearCache'
          TimelinePinEntry: '#/components/schemas/TimelinePinEntry'
          TimelineReplaceEntry: '#/components/schemas/TimelineReplaceEntry'
          TimelineShowAlert: '#/components/schemas/TimelineShowAlert'
          TimelineShowCover: '#/components/schemas/TimelineShowCover'
          TimelineTerminateTimeline: '#/components/schemas/TimelineTerminateTimeline'
        propertyName: type
      oneOf:
        - $ref: '#/components/schemas/TimelineAddEntries'
        - $ref: '#/components/schemas/TimelineAddToModule'
        - $ref: '#/components/schemas/TimelineClearCache'
        - $ref: '#/components/schemas/TimelinePinEntry'
        - $ref: '#/components/schemas/TimelineReplaceEntry'
        - $ref: '#/components/schemas/TimelineShowAlert'
        - $ref: '#/components/schemas/TimelineTerminateTimeline'
        - $ref: '#/components/schemas/TimelineShowCover'

Code sample

Code sample
abstract class InstructionUnion {
  String get type;
}

class TimelineAddEntries implements InstructionUnion {
  @override
  final String type = 'TimelineAddEntries';
  // other
}

class TimelineAddToModule implements InstructionUnion {
  @override
  final String type = 'TimelineAddToModule';
  // other
}

Logs

No response

Dart version and used packages versions

Dart version
3.5.0
Packages version
  freezed_annotation: ^2.4.4
  json_annotation: ^4.9.0
  retrofit: ^4.4.1

  json_serializable: ^6.7.1
  freezed: ^2.5.7
  swagger_parser: ^1.19.1
  retrofit_generator: ^9.1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant