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

Implement support for discriminated unions #287

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

CallMeSH
Copy link

This PR introduces support for OpenAPI discriminator patterns in oneOf schemas. The implementation enables proper code generation for polymorphic types.

Key Changes:

  • Added discriminator handling within UniversalComponentClass for oneOf variant support
  • Enhanced OpenApiParser to correctly process discriminator mappings from OpenAPI specs
  • Updated Freezed DTO template to generate sealed classes with union factories
  • Anonymous class naming now uses the parent class name as context (e.g., ClassNameStatus instead of StatusStatus)
  • Added comprehensive test cases with sample schemas and expected outputs

This PR does not support any other generator and I still have to test a few things with the Freezed one.
I will remove its DRAFT status once I think it is ready.

closes #286
closes #265

…ation

- Added discriminator handling in `UniversalComponentClass` to support oneOf variants.
- Updated `dart_freezed_dto_template.dart` to generate sealed classes and union factories based on discriminator values.
- Introduced new test cases for discriminated oneOf schemas, including a sample JSON schema and expected output files.
- Enhanced OpenApiParser to correctly parse and map discriminator properties from OpenAPI specifications.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant