Skip to content

Support objects in expressions - #1777

Merged
TomasEng merged 36 commits into
mainfrom
support-objects-in-expressions
Jun 17, 2026
Merged

Support objects in expressions#1777
TomasEng merged 36 commits into
mainfrom
support-objects-in-expressions

Conversation

@TomasEng

@TomasEng TomasEng commented May 28, 2026

Copy link
Copy Markdown
Contributor

Important

This pull request is stacked upon #1769, which should be merged first.

Description

This pull request adds support for objects in expressions, along with an object function for creating an object. Here is an overview of the changes:

  • New object function in ExpressionEvaluator. Because of the complexity of the function, I created a separate class named ObjectFunctionEvaluator for evaluating the function.
  • Support for dictionaries in ExpressionValue. Most of the code did already exist, hiding in comments.

Here is the corresponding change in App frontend: Altinn/altinn-studio#18982

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing not possible since there is no use case for this until we add functions that accept objects as parameters; the automated unit tests should be sufficient
  • Relevant automated test added (if you find this hard, leave it and we'll help out)
  • All tests run green

Documentation

Summary by CodeRabbit

  • New Features
    • Added @object expression function to create objects from alternating key/value arguments.
    • Extended the expression value system to support JSON object values end-to-end (creation, access, and string rendering).
    • Improved JSON (de)serialization to handle object values consistently, including during equality formatting.
  • Tests
    • Added and expanded shared expression fixtures and test coverage for object construction and object/list lookup scenarios.
    • Updated evaluator tests to cover additional JSON object/array combinations and adjusted “nonsense” equality inputs.

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4df921c7-e753-424a-ab62-46f20668296f

📥 Commits

Reviewing files that changed from the base of the PR and between aa24c44 and 84e2800.

📒 Files selected for processing (1)
  • test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt

📝 Walkthrough

Walkthrough

Adds the @object expression function to the layout expression evaluator. ExpressionValue is extended to hold JsonObject as a first-class variant with a new constructor, implicit conversion, accessor, and serialization paths. A new ObjectFunctionEvaluator implements the key/value pair construction logic. ExpressionEvaluator dispatches the new ExpressionFunction.@object enum member to this evaluator.

Changes

@object expression function

Layer / File(s) Summary
ExpressionFunction enum and ExpressionValue JsonObject variant
src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs, src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs
Declares the @object enum member and extends ExpressionValue with a JsonObject backing field, constructor, implicit conversion operator, Object accessor property, updated FromObject/ToObject factories, ToString/ToStringForText serialization, and ExpressionTypeUnionConverter read/write support for object tokens.
ObjectFunctionEvaluator and dispatch wiring
src/Altinn.App.Core/Internal/Expressions/ObjectFunctionEvaluator.cs, src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs
ObjectFunctionEvaluator.Evaluate validates even argument count, extracts string keys, serializes values to JsonNode, enforces key uniqueness, and returns a JsonObject. ExpressionEvaluator adds a dispatch case for ExpressionFunction.@object that delegates to a new Object(args) helper.
Tests, fixtures, and public API snapshot
test/.../CommonTests/TestFunctions.cs, test/.../shared-tests/functions/object/object.json, test/.../shared-tests/functions/dataModel/lookup-object.json, test/.../shared-tests/functions/dataModel/lookup-list.json, test/.../shared-tests/functions/component/lookup-list.json, test/.../shared-tests/functions/list/list.json, test/.../ExpressionEvaluatorTests/ExpressionValueTests.cs, test/.../ExpressionEvaluatorTests/EqualsTests.cs, test/.../PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt
Adds Object_Theory xUnit method, object.json shared test cases (success and error cases), new and updated data model/component fixtures for object lookup and list nesting, updates ExpressionValueTests and EqualsTests for the new Object property, and updates the public API snapshot.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Altinn/app-lib-dotnet#1769: Adds the list function to ExpressionEvaluator, ExpressionValue, and ExpressionFunction using the same pattern this PR follows for @object.

Suggested reviewers

  • martinothamar
  • ivarne
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and concisely summarizes the main change: introducing support for objects in expressions, which is the primary objective of this changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch support-objects-in-expressions

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@TomasEng TomasEng added feature Label Pull requests with new features. Used when generation releasenotes backport-ignore This PR is a new feature and should not be cherry-picked onto release branches labels May 28, 2026
@TomasEng
TomasEng force-pushed the support-objects-in-expressions branch from 5a4dacc to 5c9c571 Compare May 28, 2026 13:12
@TomasEng TomasEng added the squad/data Issues that belongs to the named squad. label May 29, 2026
@TomasEng TomasEng moved this to 👷 In progress in Team Altinn Studio May 29, 2026
@TomasEng
TomasEng force-pushed the support-objects-in-expressions branch from 2fb14e2 to ee69ba5 Compare May 29, 2026 07:00
Comment thread src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs
@TomasEng
TomasEng force-pushed the support-objects-in-expressions branch from 4d6544b to 4908de3 Compare May 29, 2026 07:21
@TomasEng
TomasEng force-pushed the support-objects-in-expressions branch from 4908de3 to 2a553d2 Compare May 29, 2026 07:33
@TomasEng
TomasEng force-pushed the support-objects-in-expressions branch from 2a553d2 to ab5d0b1 Compare May 29, 2026 07:40
@TomasEng

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@TomasEng
TomasEng marked this pull request as ready for review May 29, 2026 08:02
@TomasEng TomasEng moved this from 👷 In progress to 🔎 In review in Team Altinn Studio May 29, 2026
TomasEng added 7 commits June 1, 2026 07:43
…to support-objects-in-expressions

# Conflicts:
#	src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs
#	test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt
@TomasEng
TomasEng requested a review from olavsorl June 10, 2026 07:19

@ivarne ivarne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ikke noe stort å bemerke her heller 👍

Comment thread src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs Outdated
Comment thread src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs Outdated
Comment thread src/Altinn.App.Core/Internal/Expressions/ObjectFunctionEvaluator.cs Outdated
Comment thread src/Altinn.App.Core/Internal/Expressions/ObjectFunctionEvaluator.cs Outdated
@TomasEng
TomasEng requested a review from ivarne June 12, 2026 12:52

@olavsorl olavsorl 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 ✅

Base automatically changed from support-lists-in-expressions to main June 16, 2026 11:49
@sonarqubecloud

Copy link
Copy Markdown

@TomasEng
TomasEng merged commit 1bd6654 into main Jun 17, 2026
12 checks passed
@github-project-automation github-project-automation Bot moved this from 🔎 In review to ✅ Done in Team Altinn Studio Jun 17, 2026
@TomasEng
TomasEng deleted the support-objects-in-expressions branch June 17, 2026 09:03
@coderabbitai coderabbitai Bot mentioned this pull request Jun 25, 2026
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-ignore This PR is a new feature and should not be cherry-picked onto release branches feature Label Pull requests with new features. Used when generation releasenotes squad/data Issues that belongs to the named squad.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants