@codacy/tools-spectral-1
v0.2.0
Published
Spectral adapter — Library-mode OpenAPI/AsyncAPI linter
Readme
@codacy/tools-spectral-1
Table of Contents
Overview
OpenAPI and AsyncAPI linter using Spectral. Uses the Library execution strategy — calls the @stoplight/spectral-core API directly rather than spawning a subprocess.
| Property | Value |
|----------|-------|
| Tool ID | spectral |
| Codacy UUID | fb60ff64-3d91-11ec-9bbc-0242ac130002 |
| Strategy | Library |
| Languages | JSON, YAML |
| Dependency | @stoplight/spectral-core (v1.x) |
| File patterns | **/*.yaml, **/*.yml, **/*.json |
Updating patterns
# Re-fetch pattern metadata from the Codacy API
pnpm prefetch
# Commit the result
git add src/patterns.jsonPattern IDs follow the format spectral_operation-operationId, spectral_info-contact, etc.
Updating the Spectral version
- Update
@stoplight/spectral-coreand related packages inpackage.json - Run
pnpm install - Run
pnpm prefetchto check for new/removed rules - Run
pnpm testto verify compatibility - If the major version changes, create a new adapter package (
spectral-2/)
Development
pnpm build # Build with tsup
pnpm test # Run testsNotes for maintainers
- Spectral diagnostics use 0-based line and column numbers. The adapter adds 1 to both to produce 1-based Codacy Issues.
- The adapter processes files one at a time, creating a new Spectral instance per file. This avoids state leakage between files.
- Not all YAML/JSON files are API specs. Non-spec files may produce parse errors from Spectral — the adapter captures these as warnings and continues.
- The default ruleset is
spectral:oas(OpenAPI). AsyncAPI support can be added by detecting theasyncapikey in the document. checkAvailabilitydynamically imports@stoplight/spectral-coreand creates an instance.installis a no-op — the npm dependency handles installation.
