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: change keywords priority for inferring example and try infer example from root in combined schemas #126

Merged
merged 4 commits into from
Jul 2, 2021

Conversation

magicmatatjahu
Copy link
Contributor

PR fixes bugs described in #124 issue. I copied the description of bugs from mentioned issue:

  • const should take precedence over other keywords. At the moment package infer examples in order: default -> const -> enum -> examples[0] -> generate example using format, but I think that const should take precedence over other keywords and we should change also whole order, so we should end with priority:
    • const - valid schema should have always value defined in const
    • examples[0] - if we don't have defined const then examples[0] should have next priority
    • enum[0]
    • default - it's a default value for valid schema, but const, examples[0] and enum[0] should have highter priorities - examples and enum in first index can have different value than is defined in default
  • if schema has defined examples, default, const with oneOf like in schema above, package should infer examples from root schema, not from first oneOf item -> problem with this line. This problem should be also handled for other combined keywords like allOf.

Changes:

  • change the priority of const, examples, default, enum keywords
  • try to infer example in combined schemas from root, and only then infer examples from sub schemas
  • write tests for changes
  • update Readme.md with changed order

Copy link
Member

@RomanHotsiy RomanHotsiy left a comment

Choose a reason for hiding this comment

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

Great job! 👏

@RomanHotsiy RomanHotsiy merged commit e03e923 into Redocly:master Jul 2, 2021
@RomanHotsiy
Copy link
Member

Published in v1.1.0

@magicmatatjahu magicmatatjahu deleted the fix-124 branch July 2, 2021 08:32
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