fix: assign schemas to host ajv instance#126
Conversation
|
@diogosilva95 The CI is failing, can you add a unit test as well please? |
|
@Fdawgs added the test and fixed lint :) |
would you provide an example please? when you add a schema to the ajv instance with an existing id it throws an error |
That is the exact problem I mention, import fastify from "fastify";
const app = fastify();
app.register(async (instance) => {
instance.addSchema({
$id: 'foo',
type: 'object',
properties: {
foo: { type: 'string' }
}
})
})
app.register(async (instance) => {
instance.addSchema({
$id: 'foo',
type: 'object',
properties: {
foo: { type: 'string' },
bar: { type: 'string' }
}
})
})
await app.ready() |
|
Isn't |
Eomm
left a comment
There was a problem hiding this comment.
LGTM
The ajv instance is encapsulated too.
I would just add another test to cover the cliba feedback 👍🏼
The problem is similar to |
There was a problem hiding this comment.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no suggestions.
Comments skipped due to low confidence (2)
index.js:46
- [nitpick] The variable name 'schemas' is clear, but it could be more specific. Consider renaming it to 'registeredSchemas'.
const schemas = Object.values(fastify.getSchemas())
index.js:49
- The condition checks if the schema is already added to AJV, but it does not handle the case where 'schema.$id' is undefined. Consider adding a check for 'schema.$id'.
if (!ajv.getSchema(schema.$id)) {
Fixes the issue #113 by adding the schemas to the internal avj instance used by the plugin
Checklist
npm run testandnpm run benchmarkand the Code of conduct