Support Request: how can a rule ignore parameters with a specific name?
michelecurioni opened this issue · 3 comments
Hi,
I was hoping you could suggest how I could modify the 'ibm-parameter-description' rule to ignore parameters whose name is whitelisted.
For instance, if I have the following openapi spec, I'd like the validator to not report any warning for rule ibm-parameter-description if whitelist = ["no_desc"]
openapi: "3.0.0"
info:
title: "OT2 Content Metadata Service API"
description: "test"
version: "1.0.0"
paths:
/test:
post:
parameters:
- name: no_desc
in: query
schema:
type: string
- name: with_desc
description: some description
in: query
schema:
type: string
Is it possible?
Thanks,
Michele
You should be able to define a custom ruleset that inherits from the ibm cloud ruleset and defines an override for the rule in question.
Here is a link to the Spectral docs re: overrides:
https://meta.stoplight.io/docs/spectral/293426e270fac-overrides#overrides
Also, here is an example of a custom ruleset that I happened to have on hand from a recent demo I presented:
.spectral.js
contents:
const ibmCloudValidationRules = require('@ibm-cloud/openapi-ruleset');
const { propertyCasingConvention } = require('@ibm-cloud/openapi-ruleset/src/functions');
const { schemas } = require('@ibm-cloud/openapi-ruleset-utilities/src/collections');
module.exports = {
extends: ibmCloudValidationRules,
rules: {
'ibm-property-casing-convention': {
description: 'Property names must follow camel case',
message: '{{error}}',
resolved: true,
given: schemas,
severity: 'warn',
then: {
function: propertyCasingConvention,
functionOptions: {
type: 'camel'
}
}
}
},
overrides: [
{
files: [
"ansiform-service.yaml#/components/schemas/CiscoRouter"
],
rules: {
'ibm-property-casing-convention': 'off'
}
}
]
};
This example contains an override of the ibm-property-case-convention rule to turn it off specifically for the "CiscoRouter" schema in the ansiform-service.yaml API definition file.
Thanks for the pointer.
Do you know if the "files" override supports a syntax for matching the value of elements? I'm not sure json-pointer allows you to match on the content of an element.
In my example above, I need to say "skip the rule for all parameters that have a name='no_desc'"
I skimmed through the JSON Pointer RFC that is linked from the Spectral "overrides" documentation (https://datatracker.ietf.org/doc/html/rfc6901), and I did not see a way to specify elements with a certain property value (i.e. name=no_desc). Alternatively, you could define an override for each parameter object (e.g. #/components/parameters/NoDescParam
) that you want to be ignored by the rule.