Repository navigation
feat(spectral): warn on rule names written as error.code (#163) - #164
Merged
Merged
Conversation
`specfuse-error-rule-name-in-code` (warn) flags a description or summary that assigns or compares a snake_case rule name to `code` (`error.code = template_in_use`, `"code": "x_y"`) when `components.schemas.Error.properties.code` is an integer. Since §54 the rule name belongs in `reason`; a schema migration leaves that prose behind. - functions/openapiErrorReasonProse.js: the integer gate, and a match that needs an underscore in the value so `code: integer` / `code = 409` and `status_code` stay silent. - fixtures error-reason-prose.yaml (4 firings, 3 silences) and error-reason-prose-string-code.yaml (the gate), asserted in example-regen.yml. - API Handbook §11 names the rule; compatibility.md §51 item 2 and §54 record it and point the migration at it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #163.
What
New Spectral rule
specfuse-error-rule-name-in-code(warn). It flags adescriptionorsummaryanywhere in the document that assigns or compares a snake_case rule name tocode:error.code = template_in_useerrors[0].code == 'page_size_over_limit'`code`: `slot_already_booked`"code": "delete_not_allowed"Since #160 (compatibility.md §54),
codeis the HTTP status and the rule name goes inreason. Migrating the schema leaves prose like this behind, and nothing else checks it. Response examples are already covered:spectral:oasexample validation rejects a stringcode.Keeping it quiet on correct prose
components.schemas.Error.properties.codeistype: integer. A project still on the old string-codeshape gets §54's migration note instead of warnings.code: integerorcode = 409. The cost: a single-word rule name isn't caught.\bbeforecodekeepsstatus_codeandreason_codeout.The rule is implemented as a custom function (
functions/openapiErrorReasonProse.js), because the gate readscomponentswhile the matches come from anywhere in the document.Verification (local, Spectral 6.16.2)
fixtures/error-reason-prose.yaml:409response description and anx-*block;/clean(error.reason = …),/status(code = 409,code: integer) and/otherCodes(status_code,reason_code, postal code).fixtures/error-reason-prose-string-code.yaml: the same prose under a stringcode, with 0 findings (the gate holds).hello-orders: 0 findings from the new rule, and the total is unchanged at 74.error.code = order_lockedinto one referenced operation file. It reported exactly once, mapped to that file, so the multi-file$refsetup works.templates/,examples/andsamples/finds no prose the rule would flag.givenis$, so it always selects.example-regen.ymlstep asserts all of the above. I ran its assertions locally and they pass.Docs
🤖 Generated with Claude Code