A linter rule checks a specified pattern in a structured artifact. For an API, it can inspect an OpenAPI document and flag design or authoring problems before they become harder to change. Rules turn recurring guidelines—such as property naming or search pagination—into checks, leaving people to judge whether the design meets consumers’ needs. section 18.0 section 18.2.1
Catch a query-parameter typo
Suppose GET /products has a query parameter named buyPRice. A Spectral rule can select query parameter names with `given: $..parameters[?(@.in === "query")].name`, then apply the `casing` function with the `camel` option. It flags buyPRice and points toward buyPrice. The rule needs both a precise target and a check; otherwise it may report the wrong elements or miss the typo. section 18.3.2 section 18.5
Make each rule useful rather than merely strict:
- Give it a reason grounded in an API design guideline and link that guidance with `documentationUrl`. Do not enforce a preference whose value has not been established. section 18.4.1
- Check one right-sized concern at a time. Search pagination, for example, may need separate rules for the presence and schemas of its parameters; mandatory pagination and optional filters need not share a severity. section 18.4.2 section 18.4.4
- Prefer a shared OpenAPI component when it can replace detailed structural checks. A rule can require a 500 response to reference a reusable response instead of rechecking its media type, description, and schema. section 18.4.3 section 18.6.4
- Return feedback that identifies the problem, its location, importance, and a way to fix it. Set severity and message accordingly. section 18.7
In Spectral, a rule uses `given` JSONPaths to find elements and one or more `then` functions to check them. Start by testing the JSONPath against a valid, realistic document; a temporary `undefined` check reveals what it selected. Functions can check values or, with `field: "@key"`, object keys. Reference checks can verify use of shared components. section 18.5.1 section 18.6.1 section 18.6.4
Keep shared rules in versioned rulesets. An API-local `.spectral.yaml` can import them, change severities, disable unsuitable checks, and add API-specific rules. A linter cannot settle every design question: deciding whether an operation should run for a long time, for example, requires context beyond its API description. section 18.8 section 18.9.1 section 18.2.3
Try a rule
Write a rule that checks semantic versioning at `info.version` in an OpenAPI document. Test it against `version: athena-1.0.0.bugfix`, and make the resulting message useful to someone fixing the value. section 18.12 section 18.5.1




