stoplightio / spectral

A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI (v3.1, v3.0, and v2.0), Arazzo v1.0, as well as AsyncAPI v2.x.
https://stoplight.io/spectral
Apache License 2.0
2.51k stars 240 forks source link

Support more than 2 logicals in XOR core function #2396

Closed DFog14 closed 6 months ago

DFog14 commented 1 year ago

Describe the bug In Spectral5.9.2, the core XOR function could accept more than 2 items in its properties' list. In Spectral6+, the core XOR function only appears to support two logical.

To Reproduce Create a ruleset that leverages the core XOR function:

each-component-property-must-contain-only-one: given: $.components...properties.* recommended: true severity: warn then: function: xor functionOptions: properties:

This rule running on 5.9.2 will work with no issue This rule running on 6+ will result in the following error: Error #1: "xor" and its "properties" option support 2-item tuples, i.e. ["id", "name"]

Expected behavior The XOR function will behave in the way that it always has, allowing more than just 2 logicals.

Additional context I understand that from an electrical perspective, an XOR gate only takes two inputs, but XOR functionality can support an unlimited number of inputs in practical use. If this was an intended behavior change, then so be it, it just seems like an odd decision to make as it breaks compatibility and the docs page still lists the function as supporting a list of logicals.

Judging by commit histories, it looks like the xor function was completely redesigned in 6.0.0alpha1, this redesign seems to have limited it to two logicals

P0lip commented 1 year ago

The function was never intended to take more than 2 logical. You can see the code we have in 5.9.2 here and see that we have a check for properties.length !== 2. In other words, what currently happens in v5.x is the function does nothing if you specify more than 2 logicals.

We could possibly make it take more than 2 logicals tho. I'll keep that ticket around.

stoplight-bot commented 5 months ago

:tada: This issue has been resolved in version 1.19.0 :tada:

The release is available on @stoplight/spectral-rulesets-1.19.0

Your semantic-release bot :package::rocket: