Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: global ajv cache #105

Merged
merged 2 commits into from
Jan 15, 2022
Merged

fix: global ajv cache #105

merged 2 commits into from
Jan 15, 2022

Conversation

Eomm
Copy link
Member

@Eomm Eomm commented Jan 15, 2022

I faced this issue when I was using this plugin in tests:

fastify.register(fastifyEnv, {
      confKey: 'secrets',
      data: opts.configData,
      schema: fastify.getSchema('schema:dotenv')
    })

This plugin has a global ajv instance that is caching the schemas.
This cache trigger this error:

Subtest: the application should start
    not ok 1 - schema with key or id "schema:dotenv" already exists
      ---
      stack: |
        Ajv._checkUnique (node_modules/env-schema/node_modules/ajv/lib/core.ts:721:13)

This change turns off the cache because the schema provided to the env-schema is single and it does not require the cache used by ajv.

https://ajv.js.org/options.html#addusedschema

test/no-global.test.js Outdated Show resolved Hide resolved
Copy link
Member

@darkgl0w darkgl0w left a comment

Choose a reason for hiding this comment

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

LGTM

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

Co-authored-by: darkgl0w <31093081+darkgl0w@users.noreply.github.com>
@Eomm Eomm merged commit 2624561 into master Jan 15, 2022
@climba03003 climba03003 deleted the noglobal branch May 23, 2022 06:41
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.

3 participants