Skip to content

Added calculation schema#4048

Open
olavsorl wants to merge 9 commits intomainfrom
feature/calculation-schema
Open

Added calculation schema#4048
olavsorl wants to merge 9 commits intomainfrom
feature/calculation-schema

Conversation

@olavsorl
Copy link

@olavsorl olavsorl commented Mar 6, 2026

Description

Calculation schema used in calculation.json files. PR in app-lib-dotnet: Altinn/app-lib-dotnet#1683

Related Issue(s)

  • closes #{issue number}

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* and backport* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

Summary by CodeRabbit

  • New Features
    • Adds a Calculation configuration schema for Altinn 3 apps.
    • Introduces a required top-level "calculations" section with pattern-based keys mapping to per-entry calculation objects.
    • Each calculation entry requires an "expression" validated as a string, number, or boolean.
    • Enforces strict structure to prevent unexpected properties in calculation definitions.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

Important

Review skipped

This PR was authored by the user configured for CodeRabbit reviews. CodeRabbit does not review PRs authored by this user. It's recommended to use a dedicated user account to post CodeRabbit review feedback.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eef27b77-2f44-4ab6-bc62-6ee6ee8d2a16

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

Walkthrough

Adds a new JSON Schema file at schemas/json/calculation/calculation.schema.v1.json. Root object disallows additional properties and requires calculations. calculations is a patternProperties object mapping keys to arrays of item objects. Each item object defines an expression property (validated via anyOf against external expression definitions) and declares condition as required, but condition is not defined in the item's properties in this diff.

Changes

Cohort / File(s) Summary
Calculation Schema Definition
schemas/json/calculation/calculation.schema.v1.json
Added new JSON Schema with metadata ($id, $schema, title, description). Root: additionalProperties: false, required: ["calculations"]. calculations: patternProperties ^.+$ → arrays of items. Each item: object with an expression property (uses anyOf to reference `../layout/expression.schema.v1.json#/definitions/{string

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Added calculation schema' directly and clearly summarizes the main change: a new JSON schema file for calculation configuration.
Description check ✅ Passed The description includes a brief explanation of the change and a reference to a related PR, with most QA verification checklist items appropriately completed for a schema addition.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

📝 Coding Plan
  • Generate coding plan for human review comments

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
schemas/json/calculation/calculation.schema.v1.json (1)

16-17: Consider using ^.+$ to prevent empty key names.

The pattern ^.*$ matches empty strings, which would allow calculation keys with empty names. Using ^.+$ ensures at least one character is required for key names.

💡 Suggested improvement
       "patternProperties": {
-        "^.*$": {
+        "^.+$": {

Apply the same change to line 36.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@schemas/json/calculation/calculation.schema.v1.json` around lines 16 - 17,
Update the JSON schema's patternProperties entries to disallow empty property
names by replacing the regex key "^.*$" with "^.+$" wherever it appears (e.g.,
the patternProperties mapping in calculation.schema.v1.json); ensure both
occurrences (the one around "patternProperties" and the other similar entry
later in the file) are changed so keys require at least one character.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@schemas/json/calculation/calculation.schema.v1.json`:
- Around line 34-40: The JSON Schema under "definitions" has an invalid keyword
"ref" and is missing an explicit object type; update the block that contains
"patternProperties" so the property reference uses "$ref":
"#/definitions/calculation" instead of "ref", and add type: "object" at the same
level as "patternProperties" (the object that defines the pattern keyed entries)
so the schema correctly declares that the patterned entries are objects.
- Around line 20-29: The schema references "#/definitions/calculation" inside
the oneOf for the calculations property but no top-level JSON Schema
"definitions" exists; add a top-level "definitions" sibling to "properties" that
declares a "calculation" schema (the shape referenced by the oneOf) so the
reference resolves; ensure the new definitions.calculation describes the
expected fields for a calculation object (types, required fields, nested
structures) and update any titles/descriptions to match existing "calculation"
usage so "#/definitions/calculation" is valid.

---

Nitpick comments:
In `@schemas/json/calculation/calculation.schema.v1.json`:
- Around line 16-17: Update the JSON schema's patternProperties entries to
disallow empty property names by replacing the regex key "^.*$" with "^.+$"
wherever it appears (e.g., the patternProperties mapping in
calculation.schema.v1.json); ensure both occurrences (the one around
"patternProperties" and the other similar entry later in the file) are changed
so keys require at least one character.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 718f523e-5692-41d8-952f-d1644525fdd2

📥 Commits

Reviewing files that changed from the base of the PR and between 5e931c9 and 6df1ba3.

📒 Files selected for processing (1)
  • schemas/json/calculation/calculation.schema.v1.json

@olavsorl olavsorl added backport-ignore This PR is a new feature and should not be cherry-picked onto release branches kind/product-feature Pull requests containing new features labels Mar 9, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
schemas/json/calculation/calculation.schema.v1.json (1)

23-31: Consider renaming "condition" to better reflect its purpose.

The property is named condition, which typically implies a boolean predicate, but the description states "The expression can return any value." If this property represents the computed value (not a conditional check for when to apply the calculation), a name like "expression" or "value" might be more semantically accurate.

If the naming aligns with the backend API contract (per the related app-lib-dotnet PR), this can be ignored.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@schemas/json/calculation/calculation.schema.v1.json` around lines 23 - 31,
The JSON schema property named "condition" is misleading because it accepts any
expression value; rename the property to a clearer name (e.g., "expression" or
"value") in calculation.schema.v1 (replace the "condition" key and update its
"title" to match) and update the description accordingly; then search and update
all schema references and any consuming code or tests that reference "condition"
(including related schema refs or backend contracts such as the app-lib-dotnet
integration) to use the new property name to keep the contract consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@schemas/json/calculation/calculation.schema.v1.json`:
- Around line 23-31: The JSON schema property named "condition" is misleading
because it accepts any expression value; rename the property to a clearer name
(e.g., "expression" or "value") in calculation.schema.v1 (replace the
"condition" key and update its "title" to match) and update the description
accordingly; then search and update all schema references and any consuming code
or tests that reference "condition" (including related schema refs or backend
contracts such as the app-lib-dotnet integration) to use the new property name
to keep the contract consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b6407d99-b877-48ac-bd47-7a3e4c3cec04

📥 Commits

Reviewing files that changed from the base of the PR and between a1f042d and 1e89ba3.

📒 Files selected for processing (1)
  • schemas/json/calculation/calculation.schema.v1.json

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 kind/product-feature Pull requests containing new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant