Repository navigation
Conversation
…tion has a nested $ref SchemaValidation looked up the failing field's schema from error.schemaPath. When a referenced definition itself contains a $ref, AJV compiles it separately and reports a schemaPath relative to that definition, so the lookup against the root schema found nothing and the user got the standard text instead of the custom error message. Use error.parentSchema, which AJV sets with verbose: true and which is the schema that failed in every case.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
could someone re-run the failed cypress job? pretty sure it's the TT02 enviroment being slow and not this change all the steps in "Deeply linked hidden with component lookups" passed. it failed in the global afterEach => waitUntilSaved timed out on the last save to TT02 same commit (747ba71) passed the full cypress run earlier today in run 39701849548 also needs labels for check-label. kind/bug I think, backport or backport-ignore is your call |
Description
A custom
errorMessagein the data model was ignored when the field sat in a definition that itself contains a$ref, and the user got «Feil format eller verdi» instead.SchemaValidationlooked up the field's schema fromerror.schemaPath, but AJV compiles such a definition separately and reports a path relative to it, so the lookup against the root schema found nothing. The issue has the steps and screenshots.This PR uses
error.parentSchemainstead. AJV sets it because the validator is created withverbose: true, and it is the schema that failed, whether the definition was inlined or not. That also covers therootElementPathcase, so thegetSchemaPartOldGeneratorbranch is no longer needed here.getSchemaPartandgetSchemaPartOldGeneratorinsrc/utils/schemaUtils.tsare now only used by their own tests. I left them to keep this PR to the fix, and can remove them here or in a separate PR if you prefer.An
errorMessageplaced beside a$ref({ "$ref": "#/$defs/X", "errorMessage": "…" }) is not read before or after this change, since the error comes from the referenced definition. That is a separate case, and I have not changed it.Same steps as in the issue, with app-frontend 4 from the CDN and with this branch, for
Innsender.kontaktInfo.epost:4)v9 has the same lookup in
src/App/frontendin altinn-studio. I understand you sync changes from this repo over there, so I have not made a separate PR, but I am happy to make one if you prefer.Related Issue(s)
errorMessagein the data model is ignored when the definition contains a$ref#4389Verification/QA
kind/*andbackport*label to this PR for proper release notes groupingSchemaValidation.test.tsxhas a new table test that checks that the field'serrorMessageis used as the text key when the field is in:$ref;$ref;$ref, validated against a sub schema (rootElementPath).The last two fail on
main, and the first two pass there too.yarn tscand the fullyarn testpass locally on Node 22 (169 test suites and 3653 tests passed, 1 suite and 61 tests skipped), and ESLint and Prettier pass on the changed files. The changed lines are covered.Manual test in localtest with a copy of one of our apps (Altinn.App 8.12.11), where
Virksomhet.epostandInnsender.kontaktInfo.epostboth have"errorMessage": "Epost.feilmelding", and onlyKontaktInfohas a nested$ref. The local builds were loaded through localtest'sfrontendVersioncookie:main(cd18b44) built locally: the custom message underVirksomhet.epost, «Feil format eller verdi» underInnsender.kontaktInfo.epost.Summary by CodeRabbit
contact.phoneNumberfield, including when validation uses a referenced subschema.