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(functions): schema should respect "auto" dialect #1771

Merged
merged 2 commits into from
Aug 16, 2021

Conversation

P0lip
Copy link
Contributor

@P0lip P0lip commented Aug 10, 2021

Currently when you pass "auto" we don't run detectDialect function, so nothing useful happens.

Checklist

  • Tests added / updated
  • Docs added / updated

Does this PR introduce a breaking change?

  • Yes
  • No

@P0lip P0lip added the t/bug Something isn't working label Aug 10, 2021
@P0lip P0lip self-assigned this Aug 10, 2021
@P0lip P0lip marked this pull request as ready for review August 16, 2021 22:40
@@ -25,11 +25,13 @@ export default createRulesetFunction<unknown, Options>(
},
dialect: {
enum: ['auto', 'draft4', 'draft6', 'draft7', 'draft2019-09', 'draft2020-12'],
default: 'auto',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unrelated, but I thought it'd be actually cool to express what the default is.
Going to be useful later on in Studio when building forms.

@P0lip P0lip requested a review from a team August 16, 2021 22:41
@P0lip P0lip enabled auto-merge (squash) August 16, 2021 22:51
@@ -56,7 +58,9 @@ export default createRulesetFunction<unknown, Options>(

try {
let validator;
const dialect = opts?.dialect ?? detectDialect(schemaObj) ?? 'draft7';
const dialect =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the only actual change

@P0lip P0lip merged commit ed1621c into develop Aug 16, 2021
},
prepareResults: {},
prepareResults: true,

Choose a reason for hiding this comment

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

I'm assuming this is the same as passing an empty object?

@@ -56,7 +58,9 @@ export default createRulesetFunction<unknown, Options>(

try {
let validator;
const dialect = opts?.dialect ?? detectDialect(schemaObj) ?? 'draft7';
const dialect =
(opts.dialect === void 0 || opts.dialect === 'auto' ? detectDialect(schemaObj) : opts?.dialect) ?? 'draft7';

Choose a reason for hiding this comment

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

If opts is not defined, it will throw on L56

image

Suggested change
(opts.dialect === void 0 || opts.dialect === 'auto' ? detectDialect(schemaObj) : opts?.dialect) ?? 'draft7';
(opts.dialect === void 0 || opts.dialect === 'auto' ? detectDialect(schemaObj) : opts.dialect) ?? 'draft7';

@P0lip P0lip deleted the fix/functions/schema-dialect-detection branch August 16, 2021 23:44
stoplight-bot pushed a commit that referenced this pull request Aug 17, 2021
# [@stoplight/spectral-functions-v1.1.2](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-functions-v1.1.1...@stoplight/spectral-functions-v1.1.2) (2021-08-17)

### Bug Fixes

* **functions:** schema should respect "auto" dialect ([#1771](#1771)) ([ed1621c](ed1621c))
@stoplight-bot
Copy link
Collaborator

🎉 This PR is included in version @stoplight/spectral-functions-v1.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released t/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants