Skip to content

fix: replace struct with typed enum for proper validation dispatch#8

Open
PritamP20 wants to merge 1 commit intoaccordproject:mainfrom
PritamP20:fix/declaration-typed-enum
Open

fix: replace struct with typed enum for proper validation dispatch#8
PritamP20 wants to merge 1 commit intoaccordproject:mainfrom
PritamP20:fix/declaration-typed-enum

Conversation

@PritamP20
Copy link
Copy Markdown

@PritamP20 PritamP20 commented Apr 4, 2026

Declaration was a thin base struct with only _class, name, decorators, and location. Every time a typed declaration (ConceptDeclaration, AssetDeclaration, etc.) was added to a model, all its fields properties, superType, isAbstract got stripped away. Three methods in the codebase were working around this with hardcoded hacks.

Declaration is now a proper enum with 13 variants, dispatching on $class for deserialization and delegating to the inner struct for serialization.

Changes

  • Replace Declaration struct with a typed enum (Concept, Asset, Participant, Transaction, Event, Enum, Map, and 6 scalar variants)
  • Fix validate_no_circular_inheritance was hardcoded to only detect cycles between "Person" and "Employee", now works for any class names
  • Fix as_concept_declaration and as_map_declaration were always returning None
  • Remove hardcoded find_properties_for_declaration hack from ModelFile
  • Simplify ModelFile::validate from ~30 lines of workarounds to a single line
  • Add Clone to 15 structs required by the enum variants
  • Enable 3 previously #[ignore]d tests that now pass correctly

Flags

  • Breaking change to the Declaration type callers must now use Declaration::Concept(d) instead of the base struct literal
  • All existing tests updated accordingly

Tested

25 tests pass, 0 failing

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary (README usage example predates this PR and uses incorrect API — tracked separately)
  • Merging to main from fork:fix/declaration-typed-enum

Signed-off-by: Pritam <pritamp20@Pritams-MacBook-Air.local>
Signed-off-by: Pritam P <pripritam7@gmail.com>
@PritamP20
Copy link
Copy Markdown
Author

@mttrbrts can you please review this once

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.

1 participant