Skip to content

Conversation

@jerel
Copy link
Contributor

@jerel jerel commented Nov 6, 2025

Summary

In a project we have a need to generate sealed classes in Dart but fall back to abstract classes in some cases. This PR adds the ability to configure enum generation by creating an EnumConfig struct and optionally specifying a map of types which should use the specified behavior.

I don't know if this fits into your vision for this project but I figured I'd open this PR and see what you thought as it would be nice to keep parity with this main project.

Test Plan

The default is to generate all code exactly as it has been in the past. The new sealed behavior has to be opted in to.

@jerel jerel requested a review from ma2bd as a code owner November 6, 2025 00:02
@ma2bd
Copy link
Contributor

ma2bd commented Nov 22, 2025

Thanks @jerel. Can you rebase for the CI?

@jerel jerel force-pushed the dart-sealed-classes branch from f2bf7d5 to b595a33 Compare December 5, 2025 23:18
@jerel jerel force-pushed the dart-sealed-classes branch from e76e2df to 638a451 Compare December 5, 2025 23:50
@jerel
Copy link
Contributor Author

jerel commented Dec 8, 2025

@ma2bd I've rebased and CI checks are passing.

pub c_style: bool,
// Generate sealed class if `true` or abstract class if `false`
pub sealed: bool,
// If `sealed_enums` is true then the listed names will be abstract,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean "If sealed is true" etc?

self
}

/// Generate abstract or sealed classes for data enums based on `with_sealed_enums`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo: extra space "enums based"

self.output_enum_container(name, variants)?;
} else if (self.generator.config.enums.sealed
&& !self.generator.config.enums.output_type.contains_key(name))
|| self.generator.config.enums.output_type.get(name) == Some(&"sealed")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we're not using output_type as much when the value is not "enum" or "sealed", right?

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 this pull request may close these issues.

2 participants