Teach ruleset yaml parser to support yaml anchors/merge keys
See original GitHub issueDescribe the bug The following yaml rule with anchor does not validate correctly
To Reproduce
- Go to online spectral parser
- paste the content of the following rules
rules:
no-x-headers-request: &no-x-headers
description: "All 'HTTP' headers SHOULD NOT include 'X-' headers (https://tools.ietf.org/html/rfc6648)."
severity: warn
given:
- "$..parameters[?(@.in == 'header')].name"
message: |-
HTTP header '{{value}}' SHOULD NOT include 'X-' prefix in {{path}}
recommended: true
type: style
then:
function: pattern
functionOptions:
notMatch: "/^[xX]-/"
no-x-headers-response:
<<: *no-x-headers
given:
- $.[responses][*].headers.*~
message: |-
HTTP header '{{value}}' SHOULD NOT include 'X-' prefix in {{path}}
- See error
/rules/no-x-headers-response should have required property 'then'
Expected behavior No errors
Environment (remove any that are not applicable):
- Version: spectral 5.1.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Advanced YAML syntax cheatsheet
Schemas are rulesets in YAML 1.2 that tell the loader/parser what each part of your YAML file converts to in actual commands. They're ......
Read more >YAML Anchor, Aliases and Merge Keys
Writing about YAML anchor, alias and merge-key in use for reference YAML nodes/data and YAML mixins.
Read more >gitlab-ci.yaml syntax for merging YAML arrays (i.e., script or ...
Support merging rules arrays with !reference ... we can't read the anchors from the YAML parser, but the idea is to use some...
Read more >Introduction to YAML Configurations
Merging maps. Anchors and aliases work for scalar values, but to save maps or sequences, use << to inject the alias.
Read more >Is there YAML syntax for sharing part of a list or map?
The merge key type is probably what you want. It uses a special << mapping key to indicate merges, allowing an alias to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ioggstream I just wanted to let you know 5.6.0 is out with the support for YAML merge keys inside of rulesets.
It depends, since we have these huge OAS2 and OAS3 JSON schemas referenced in our ruleset, so the impact might be a bit higher than it may seem. Moreover, the AsyncAPI ruleset references the AsyncAPI JSON schema which is not small either. Either way, shouldn’t be a big deal to use yaml everywhere.
yeah, sure. Agreed.
You are welcome. If there is any other spot that does not support merge keys, do let me know. We should be supporting them almost everywhere now.