Skip to content

Rule for Confirming Header Exists in OpenAPI Spec #2291

Answered by EPKLISN
blueksy1012 asked this question in Q&A
Discussion options

You must be logged in to vote

I like to do it this way:

the rule

given:
- $.paths..parameters
severity: hint
then:
function: parameters-header
functionOptions:
name: Content-Location
type: header

the function

module.exports = (targetVal, opts) => {
const { name } = opts;
const { type } = opts;
if (targetVal) {
for (let i = 0; i < targetVal.length; i++) {
if (targetVal[i].in == type && targetVal[i].name == name) {
return;
}
}
return [{ message: 'Missing header parameter.' }];
}
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@blueksy1012
Comment options

Answer selected by blueksy1012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants