Skip to content

feat(publish): use custom ajv instance#2317

Open
fpotier wants to merge 2 commits intomasterfrom
feat/custom-ajv
Open

feat(publish): use custom ajv instance#2317
fpotier wants to merge 2 commits intomasterfrom
feat/custom-ajv

Conversation

@fpotier
Copy link
Copy Markdown
Member

@fpotier fpotier commented Apr 9, 2026

Description

Use a custom ajv instance for publisheddata metadata editing

Motivation

  • Initialize metadata with default values if specified in the schema
  • Remove schema entries that can't be processed by the frontend (avoids error if the schema defines custom dynamicDefaults functions as only they are only registered by the backend)
  • Allow use of jsonschema 2019 features

Changes:

  • Explictly pass an ajv instance to the jsonforms
  • Adds a service to instantiate the ajv instance and cleanup schema

Tests included

  • Included for each change/fix?
  • Passing? (Merge will not be approved unless this is checked)

Documentation

  • swagger documentation updated [required]
  • official documentation updated [nice-to-have]

official documentation info

If you have updated the official documentation, please provide PR # and URL of the pages where the updates are included

Backend version

  • Does it require a specific version of the backend
  • which version of the backend is required:

Summary by Sourcery

Introduce a shared AJV 2019 service and wire it into metadata publish/edit forms to support schema defaults and modern JSON Schema features while filtering unsupported keywords.

New Features:

  • Provide a shared AjvService that creates configured AJV 2019 instances with formats and keywords and exposes schema cleanup utilities.
  • Pass custom AJV instances into JSONForms in publish and published-data edit flows to drive metadata form validation and default handling.

Enhancements:

  • Sanitize metadata schemas before use by stripping unsupported dynamicDefaults entries via the shared AJV service.
  • Register AjvService in the shared module for reuse across components.

Build:

  • Add ajv, ajv-formats, and ajv-keywords runtime dependencies for custom JSON Schema validation.

Tests:

  • Update publish and published-data edit component tests to import the shared module so they can construct components using the new AJV-based service.

@fpotier fpotier marked this pull request as ready for review April 9, 2026 11:23
@fpotier fpotier requested a review from a team as a code owner April 9, 2026 11:23
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • AjvService currently creates a new Ajv2019 instance in each consumer; if per-form isolation is not required, consider exposing a shared singleton instance from the service to avoid repeated setup cost and configuration duplication.
  • AjvService.cleanupSchema and deleteDynamicDefaults operate on any; consider introducing a JSON Schema type (or at least a narrower interface) for the schema parameter to catch structural issues at compile time.
  • In PublishComponent you removed the explicit metadata = cloneDeep(publishedDataConfig.defaultValues) assignment; if the form should still start with backend-provided defaults, consider reintroducing this initialization alongside AJV useDefaults handling to preserve existing behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- AjvService currently creates a new Ajv2019 instance in each consumer; if per-form isolation is not required, consider exposing a shared singleton instance from the service to avoid repeated setup cost and configuration duplication.
- AjvService.cleanupSchema and deleteDynamicDefaults operate on `any`; consider introducing a JSON Schema type (or at least a narrower interface) for the `schema` parameter to catch structural issues at compile time.
- In PublishComponent you removed the explicit `metadata = cloneDeep(publishedDataConfig.defaultValues)` assignment; if the form should still start with backend-provided defaults, consider reintroducing this initialization alongside AJV `useDefaults` handling to preserve existing behavior.

## Individual Comments

### Comment 1
<location path="src/app/datasets/publish/publish.component.ts" line_range="136" />
<code_context>
+            publishedDataConfig.metadataSchema,
+          );
           this.uiSchema = publishedDataConfig.uiSchema;
-          this.metadata = cloneDeep(publishedDataConfig.defaultValues) ?? {};
         }
       },
</code_context>
<issue_to_address>
**question (bug_risk):** Removing `metadata` initialization may change how defaults are applied.

`metadata` used to be initialized from `publishedDataConfig.defaultValues`, but now it relies solely on Ajv defaults (`useDefaults: "empty"`). If `defaultValues` was meant to override or extend schema defaults, this will change the initial form state. Please confirm this behavior change is intended and that `defaultValues` is no longer required here.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Member

@minottic minottic left a comment

Choose a reason for hiding this comment

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

LGTM, but plz consider addressing the sourcery comments

Copy link
Copy Markdown
Member

@minottic minottic left a comment

Choose a reason for hiding this comment

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

thanks!

@fpotier fpotier requested a review from Junjiequan April 10, 2026 13:57
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.

2 participants