Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Spectral Ruleset Authoring

ASecurity

Playbook for writing and wiring a Spectral ruleset that enforces an API style guide in CI — covers rule anatomy, severity levels, custom functions, and the recommended core-rules baseline.

7 stars
0 votes
0 copies
0 views
Added 9/23/2026
ai-agentsjavascriptgojavanodeexpresstestinggitapi

Works with

cursorcliapi

Security Analysis

A100/100

Scanned 9/23/2026

$npx -y skills add mcorbett51090/RavenClaude --skill spectral-ruleset-authoring --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Spectral Ruleset Authoring?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Spectral Ruleset Authoring
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mcorbett51090-spectral-ruleset-authoring/badge)](https://www.skillsdirectory.com/skills/mcorbett51090-spectral-ruleset-authoring)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: spectral-ruleset-authoring
description: "Playbook for writing and wiring a Spectral ruleset that enforces an API style guide in CI — covers rule anatomy, severity levels, custom functions, and the recommended core-rules baseline."
---

# Spectral Ruleset Authoring

## When to Use This Skill

Use when setting up spec-linting governance for a new API program, when migrating from an ad-hoc review checklist to automated enforcement, or when adding a custom rule to catch a project-specific violation.

## 1. Rule Anatomy

```yaml
rules:
  rule-id:
    message: "{{description}} — {{error}}"
    description: "Human-readable explanation of what the rule checks."
    severity: error        # error | warn | info | hint
    given: "$.paths.*.*.responses"     # JSONPath expression selecting nodes to check
    then:
      function: truthy     # built-in or custom function
```

| Severity | CI behaviour |
|---|---|
| `error` | Non-zero exit — blocks merge |
| `warn` | Logged, exit 0 — advisory |
| `info` | Informational only |

Use `error` only for violations that break consumers or contradict a hard house rule. Use `warn` for style preferences.

## 2. Recommended Baseline Ruleset

```yaml
extends: ["spectral:oas"]

rules:
  # Enforce RFC 9457 error media type
  problem-json-on-errors:
    message: "Error responses must use application/problem+json, not application/json."
    severity: error
    given: "$.paths.*.*.responses[?(@property >= '400')].content"
    then:
      function: schema
      functionOptions:
        schema:
          not:
            required: ["application/json"]

  # Require operationId on every operation
  operation-id-required:
    message: "Every operation must have an operationId."
    severity: error
    given: "$.paths.*[get,post,put,patch,delete,options,head]"
    then:
      field: operationId
      function: truthy

  # Reject RPC verbs in paths
  no-rpc-path-names:
    message: "Path segments should be nouns, not verbs (no get/create/update/delete prefixes)."
    severity: warn
    given: "$.paths"
    then:
      function: pattern
      functionOptions:
        notMatch: "/(get|create|update|delete|list|fetch|retrieve)[A-Z_]"

  # Require tags on every operation
  operation-tags-required:
    message: "Every operation must have at least one tag."
    severity: warn
    given: "$.paths.*[get,post,put,patch,delete]"
    then:
      field: tags
      function: truthy

  # Flag OpenAPI 3.0.x (prefer 3.1)
  prefer-openapi-31:
    message: "Prefer OpenAPI 3.1+ (JSON-Schema-aligned). [verify-at-build]"
    severity: warn
    given: "$"
    then:
      field: openapi
      function: pattern
      functionOptions:
        notMatch: "^3\\.0\\."
```

## 3. Custom JavaScript Function

When a built-in (`truthy`, `falsy`, `pattern`, `schema`, `enumeration`, `length`) is insufficient:

```js
// functions/cursor-pagination.js
export default function cursorPagination(targetVal, _opts, context) {
  const { path } = context;
  // targetVal is the schema object for a list-response
  if (!targetVal.properties?.cursor) {
    return [{ message: "List response schema must include a 'cursor' property for keyset pagination.", path }];
  }
  return [];
}
```

Reference it in the ruleset:

```yaml
functions: [cursor-pagination]

rules:
  list-response-has-cursor:
    message: "List response schemas must include a cursor property."
    severity: error
    given: "$.components.schemas[?(/Page$|Collection$/.test(@property))]"
    then:
      function: cursor-pagination
```

## 4. CI Integration

```yaml
# .github/workflows/lint-api-spec.yml
- name: Spectral lint
  run: npx --yes @stoplight/spectral-cli@latest lint openapi.yaml --ruleset .spectral.yaml --fail-severity error
```

Exit codes: `0` = no errors, `1` = parse error, `2` = lint errors at the fail-severity level.

## 5. Rule Development Workflow

1. Pick one violation from the anti-patterns list in `CLAUDE.md §4`.
2. Write the `given` JSONPath against the spec using the Spectral Playground (`stoplight.io/spectral`).
3. Add a test fixture: a minimal `openapi-bad.yaml` that triggers it + `openapi-good.yaml` that passes.
4. Set severity `warn` first; promote to `error` only after the team agrees it's a hard rule.
5. Document the rule's rationale in its `description` field — consumers filing a PR need to understand it.

## Pitfalls

- Setting everything to `error` — if CI blocks every commit, engineers disable the linter
- Using `given: "$"` (root) for rules that only apply to operations — overly broad paths slow the run and produce confusing error locations
- Writing rules that depend on a specific operation structure instead of OpenAPI semantics — test against multiple real specs before shipping
- Forgetting to pin the Spectral version in CI — Spectral minor updates occasionally add breaking rule changes to `spectral:oas`

## See Also

- [`../../agents/api-testing-engineer.md`](../../agents/api-testing-engineer.md) — wiring Spectral in CI, Newman, and contract testing
- [`../../agents/api-design-architect.md`](../../agents/api-design-architect.md) — API style guide governance
- [`../../CLAUDE.md`](../../CLAUDE.md) — house opinion: lint the spec as governance

Attribution

mcorbett51090mcorbett51090
View sourceSee grades on GitHubMore from mcorbett51090 →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Terse caveman voice: answer first, fluff gone, every technical fact kept. Use for /caveman, "caveman mode", "talk like caveman", "be brief", "less tokens". Stays on until "stop caveman" or "normal mode".

1100021 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

698431 votes

Writing Skills

Create and manage Claude Code skills in HASH repository following Anthropic best practices. Use when creating new skills, modifying skill-rules.json, understanding trigger patterns, working with hooks, debugging skill activation, or implementing progressive disclosure. Covers skill structure, YAML frontmatter, trigger types (keywords, intent patterns), UserPromptSubmit hook, and the 500-line rule. Includes validation and debugging with SKILL_DEBUG. Examples include rust-error-stack, cargo-dep...

3931 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3421 votes

catchup

Recovers the conversation and failed tool calls of a previous Codex, Amp, Claude Code, Antigravity, Cline, Copilot CLI, Cursor, DeepSeek Harness, Grok Build, Kimi, OpenCode, Pi Agent, or ZCode session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", asks to recover/summarize a previous session before continuing, or asks to diagnose or report a catchup failure. Do NOT use for the current conversation, git history, or any non-agent log.

741 votes
View all in ai-agents →