Skip to content

Conversation

GiteshKhanna
Copy link

@GiteshKhanna GiteshKhanna commented Apr 5, 2025

This PR exports resolver functions so we can reuse them. Let me give you an example:-

I wanted to use arraysUnion on enum keyword. But the only option I had was to either

  1. Copy paste the arraysUnion function & pass it in mergeSchemas function. like

const mergedSchema = schemaMerger.mergeSchemas([schema1,schema2], {
resolvers: {
enum: CustomResolvers.arraysUnion
}
});

(here CustomResolvers is the module I created in my repo where I've copy pasted your arraysUnion function)

  1. Hacky reference import, because I know that required is using arraysUnion as a resolver.

const mergedSchema = schemaMerger.mergeSchemas([schema1, schema2], {
resolvers: {
enum: schemaMerger.keywordsResolvers.required
}
} );

But now, after this change, on exporting resolvers, it makes your resolver functions re-usable. Hence I could do something like below, which is very intuitive and reduces boilerplate code for someone using the lib:-

const mergedSchema = schemaMerger.mergeSchemas([schema1, schema2], {
resolvers: {
enum: schemaMerger.resolvers.arraysUnion
}
} );

Checklist

@mcollina mcollina requested a review from ivan-tymoshenko April 7, 2025 10:15
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Please add a test for this export as well as the types.
The types tests live in:
https://github.com/fastify/merge-json-schemas/blob/main/types/index.test-d.ts

@GiteshKhanna GiteshKhanna requested a review from mcollina April 7, 2025 18:21
@mcollina
Copy link
Member

Docs are also needed

@GiteshKhanna GiteshKhanna requested a review from mcollina April 21, 2025 06:30
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@Fdawgs Fdawgs requested a review from Copilot May 2, 2025 07:19
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR exports the resolver functions to allow users to reuse them easily instead of resorting to copy-pasting or hacky imports.

  • Exports the resolvers from index.js
  • Updates type tests to verify resolver types
  • Adds unit tests and README documentation to demonstrate usage

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

File Description
types/index.test-d.ts Updated import and type tests to ensure exported resolvers work
test/exports.test.js New tests verifying the resolvers export and type function
index.js Modified export to include resolvers
README.md Documentation updated with an example of resolver usage

Signed-off-by: Frazer Smith <[email protected]>
@Fdawgs Fdawgs changed the title allow reusing resolvers. feat: allow reusing resolvers May 2, 2025
@GiteshKhanna
Copy link
Author

Thanks for the reviews @Fdawgs @mcollina! Can this be merged & a version be released for the same?

@Fdawgs
Copy link
Member

Fdawgs commented May 13, 2025

@ivan-tymoshenko wdyt?

@GiteshKhanna
Copy link
Author

Hi @ivan-tymoshenko — just a gentle nudge on this one. The merge is currently blocked and I’ve already got two approvals. Could you please take a look when you get a moment? Appreciate your help!

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.

4 participants