Skip to content

Added calculation schema#4048

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

Added calculation schema#4048
olavsorl wants to merge 4 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
    • Added a Calculation configuration schema for Altinn 3 apps. Users can define a required "calculations" section with pattern-based keys, list calculation entries that reference conditions or other calculations, and reuse definitions via string refs. The schema enforces contained definitions and integrates with existing expression definitions for conditional logic.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

📝 Walkthrough

Walkthrough

Adds a new JSON Schema file that defines the Altinn 3 Calculation configuration format: a root object requiring "calculations", pattern-based calculation entries, items that are calculation objects or string refs, and definitions for "calculation" with "condition" and "ref".

Changes

Cohort / File(s) Summary
Calculation Schema Definition
schemas/json/calculation/calculation.schema.v1.json
New JSON Schema introducing the Altinn 3 Calculation configuration. Declares root metadata ($id, $schema, title, description), requires calculations, uses patternProperties for calculation keys mapping to arrays of items (either #/definitions/calculation or string refs), and defines calculation with condition (external expression ref) and ref (string).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive PR description includes basic information but lacks detail on changes and leaves most checklist items unchecked despite having selections. Provide a more detailed description of the calculation schema changes for service owners. Clarify which verification/QA items are actually applicable and why others were skipped.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Added calculation schema' directly and clearly describes the main change—a new calculation schema file was added to the repository.
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.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/calculation-schema

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.

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
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