Skip to content

feat: Interface Model Support - #3248

Closed
BenAuerDev wants to merge 3 commits into
serverpod:mainfrom
BenAuerDev:feat/interface-support
Closed

BenAuerDev wants to merge 3 commits into
serverpod:mainfrom
BenAuerDev:feat/interface-support

Conversation

@BenAuerDev

@BenAuerDev BenAuerDev commented Feb 20, 2025 •

Copy link
Copy Markdown
Contributor

This PR tries to enable the use of the interface and implements keyword in model files.

This is done in 3 steps/commits

  1. Enable interface and implements keywords
  2. Enable generating interfaces and classes implementing them
  3. Exclude interfaces from serialization in protocol

I described every change ordered by file in the commit descriptions.

This PR tries to close #2842.

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

No breaking changes

keywords.dart
- add `interfaceType => 'interface'`
- add `isImplementing => 'implements'

definitions.dart
- add `isInterface` (bool) field
- add `isImplementing` (List<InheritanceDefinition)` field
- add `implementedInterfaces` getter
- add `implementedFields` getter
- add `fieldsIncludingImplemented` getter
- update `inheritedFields` getter

entity_dependency_resolver:
- extract logic from `_resolveInheritance` into `_resolveExtends`
- add private method `_resolveImplements`
- add both `_resolveExtends` and `_resolveImplements` to be called in `_resolveInheritance`

model_parser:
- parse `isImplementing` and `isInterface`

model_analyzer:
- add `interfaceType` to analyzer

restrictions.dart:
- add restrictions for `interfaceType`

`class_yaml_definition` and `exception_yaml_definition`:
- add ValidateNode for `isImplementing`

interface_yaml_definition.dart:
- add `InterfaceYamlDefinition` for analyzer

`extra_properties_test`, `inheritance_test` and `model_types_test`:
- update tests returning a set of white listed node names as interface is now a white listed
model_library_generator:
- update if statements to only generate what we need for an interface
- add logic to handle implementing interfaces
- update logic handling fields
- add logic to add the `override` annotation to fields inherited from an interface

class_defintion_builder.dart:
- add `isInterface` and `isImplementing` with setters to ClassDefinitionBuilder for tests

compilation_unit_helpers.dart:
- add `tryFindImplementedClass` for tests

interface_class_test.dart:
- add tests for generating interface classes
…checking that

similar to the sealed classes, we don't serialize `interfaces` in `library_generator` I renamed

unsealedModels => serializableModels

and added a rule also excluding every model that `.isInterface`
@BenAuerDev BenAuerDev changed the title Feat/interface support feat: Interface Model Support Feb 20, 2025
@SandPod

SandPod commented Mar 10, 2025

Copy link
Copy Markdown
Contributor

Closing as #3292 replaces it.

@SandPod SandPod closed this Mar 10, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 10, 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.

"Interface" model support.

2 participants