You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Spectral: warn on rule names written as error.code when Error.code is the HTTP status #163
Add a Spectral rule that warns when prose names a rule in code, e.g. error.code = template_in_use. Since #160 (compatibility.md §54), Error.code is the HTTP status and the rule name goes in reason.
Follow-up from #159 ("Optional"). The rule was first proposed in compatibility.md §51 item 2 as a generator rule and never forwarded. It fits better in the kit's ruleset, because it checks prose, not generated code.
Why
The failure is silent. A description saying error.code = slot_already_booked passes validate and generate, but the wire can't carry it: code is an integer. Clients written from the docs branch on a field that never holds the value. One consumer had 17 operation descriptions like this (§51 item 2).
Projects migrating off the old shape (§54 migration note) will leave such prose behind. A schema change doesn't touch description text.
Examples are already covered.spectral:oas example validation rejects a string code in a response example. Prose is the gap.
Proposed rule
specfuse-error-rule-name-in-code, severity warn, in schemas/spectral/specfuse-openapi.yaml.
Gate: fire only when the resolved components.schemas.Error.properties.code has type: integer, so a project still on string code isn't flagged.
Targets:description and summary on operations, responses, and x-* blocks that carry prose (info.description included).
Match: a snake_case identifier assigned to or compared with code. For example:
Message: "Error.code is the HTTP status; name the rule in reason (error.reason = foo_bar). API Handbook §11."
It likely needs a small custom function (functions/openapiErrorReasonProse.js): the gate reads a different path from the targets, which a plain pattern rule can't express.
Done when
Rule plus function, with fixtures in both directions:
fires on error.code = template_in_use when code is an integer;
silent for error.reason = template_in_use, for code = 409, and when code is a string.
hello-orders and the init scaffold lint clean (no new findings).
API Handbook §11 names the rule.
compatibility.md §51 item 2 / §54: the lint is no longer "not forwarded".
Activity
feat(spectral): warn on rule names written as error.code (#163) (#164)