Skip to content

refactor: Separate ClassDefinition into specialization classes. - #3270

Merged
SandPod merged 15 commits into
serverpod:mainfrom
SandPod:separate-model-definitions
Feb 28, 2025
Merged

SandPod merged 15 commits into
serverpod:mainfrom
SandPod:separate-model-definitions

Conversation

@SandPod

@SandPod SandPod commented Feb 26, 2025 •

Copy link
Copy Markdown
Contributor

This PR lays the groundwork for introducing interfaces by defining explicit types for parsed model structures.

Key changes:

  • Establishes a clear inheritance structure for parsed definitions:
  • Previously, ModelClassDefinition and ExceptionClassDefinition were both represented as ClassDefinition, distinguished only by a boolean flag.
  • Now, these types are fully separated in both parsing and code generation, improving type safety and maintainability.

The inheritance structure allows us to target parse rules for specific definitions while sharing logic for all definitions that have fields.

New inheritance structure

The new inheritance structure looks like this:

ClassDefinition  
├── ModelClassDefinition  
└── ExceptionClassDefinition  
EnumDefinition  

It will now be simple to add an InterfaceClassDefintion while preserving all the validation rules that already apply to ClassDefinition fields.

Open question

There is an argument for renaming ClassDefinition to ModelDefinition and then having the specializations communicate what type of model definition we have so we would have the following structure:

The new inheritance structure looks like this:

ModelDefinition  
├── ClassModelDefinition  
└── ExceptionModelDefinition
└── InterfaceModelDefinition  
EnumDefinition  

Guidance for review

Best reviewed commit by commit.

A new test was added at the end for a specific case that I encountered that was not previously covered.

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

None - These changes here are intended to be a strictly internal refactor.

@SandPod
SandPod force-pushed the separate-model-definitions branch from 1594e68 to 7a2c70f Compare February 26, 2025 11:38
@SandPod
SandPod force-pushed the separate-model-definitions branch from 7a2c70f to 1328f13 Compare February 26, 2025 13:16
@SandPod
SandPod force-pushed the separate-model-definitions branch from 1328f13 to 004c7ac Compare February 26, 2025 13:39
@SandPod
SandPod marked this pull request as ready for review February 26, 2025 13:53

@christerswahn christerswahn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good stuff and easy to grasp overview in the PR description! Just had a question for discussion!

@SandPod
SandPod force-pushed the separate-model-definitions branch from fea5d35 to 8360fe1 Compare February 28, 2025 05:39
@SandPod
SandPod force-pushed the separate-model-definitions branch from 8360fe1 to dc12564 Compare February 28, 2025 05:46

@christerswahn christerswahn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! 🚀

@SandPod
SandPod merged commit 1cdf969 into serverpod:main Feb 28, 2025
@SandPod
SandPod deleted the separate-model-definitions branch February 28, 2025 08:15
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants