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 ajv logging warnings when discriminators are combined with $ref's #651

Merged
merged 1 commit into from
Sep 12, 2021

Conversation

alonsohki
Copy link
Contributor

@alonsohki alonsohki commented Aug 30, 2021

This seems to be a bug when combining discriminators with references. In https://github.com/cdimascio/express-openapi-validator/blob/master/src/middlewares/parsers/schema.preprocessor.ts#L318 a properties field is added to the schema, even if empty. Then, ajv will detect that you have a object containing a $ref key along with an empty properties key, and trigger this piece of code that generates the said warning:

  if (it.schema.$ref && $refKeywords) {
    if (it.opts.extendRefs == 'fail') {
      throw new Error('$ref: validation keywords used in schema at path "' + it.errSchemaPath + '" (see option extendRefs)');
    } else if (it.opts.extendRefs !== true) {
      $refKeywords = false;
      it.logger.warn('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"');
    }
  }

@alonsohki alonsohki mentioned this pull request Aug 30, 2021
@alonsohki
Copy link
Contributor Author

Ping @cdimascio

Copy link
Owner

@cdimascio cdimascio left a comment

Choose a reason for hiding this comment

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

@alonsohki thank you!

@cdimascio cdimascio merged commit 522c3ec into cdimascio:master Sep 12, 2021
@cdimascio
Copy link
Owner

@all-contributors add @alonsohki for code

@allcontributors
Copy link
Contributor

@cdimascio

I've put up a pull request to add @alonsohki! 🎉

@alonsohki alonsohki deleted the fix-discriminators-with-refs branch September 12, 2021 00:54
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