Skip to content
This repository was archived by the owner on Oct 23, 2026. It is now read-only.
This repository was archived by the owner on Oct 23, 2026. It is now read-only.

Elevate aliases out of the core ruleset into their own namespace, and get rules off JSONPath #20

Open

Description

@kinlane

Aliases should live outside the core ruleset, in their own namespace, so any ruleset can point at them — and so a rule can be written without touching JSONPath.

Raised and agreed in office hours on 2026-08-14 (#19). This was the clearest point of agreement on that call, and it has no issue of its own.

The problem

Aliases today are defined inside a ruleset. That means the useful ones — the ones that say "this is where operations live in an OpenAPI document" — are trapped in whichever ruleset happened to define them. Every other ruleset either redefines them or falls back to raw JSONPath.

The second-order effect is the one that costs adoption:

JSONPath hating is one of the go-to criticisms of people who are not into using Spectral.

That criticism is fair, and it is not really about JSONPath being bad. It is about JSONPath being the only thing on offer, so every rule author has to learn a query language to express something the format already knows — "the operations", "the responses", "the security schemes".

The proposal

  • Elevate aliases out of the core ruleset into their own space, addressable and referenceable independently.
  • Attach the OpenAPI aliases to the OpenAPI format rather than to a ruleset, so anything linting OpenAPI gets them without importing a ruleset it does not otherwise want.
  • Let an alias point at a reference architecture, so the underlying query language becomes an implementation detail. If someone wants to get rid of JSONPath entirely, the alias layer is where that becomes possible.
  • Switch all examples and documentation over to the alias-based routes, so the documented way to write a rule is the alias way and JSONPath is what you drop to when you need to.

Why this is a specification question

An alias that only works in one engine is a convenience. An alias namespace defined by the specification is portability — it is the difference between "rules written for engine A" and "rules". It also interacts directly with #13: if rules are ever to be portable to other policy engines, the fewer of them that carry hand-written JSONPath, the better that translation gets.

Open questions

  • Does the alias namespace version with the format, with the specification, or on its own?
  • Can a ruleset override an alias it inherits from a format, and if so, is that a footgun?
  • Is the alias layer normative, or a registry the specification points at?

Roadmap items this covers, from the working document in #19: "moving Aliases for openapi to openapi format to enable JSONPath-free rules for more rulesets" and "Switch all examples and documentation to use these Alias-based routes".

Activity

  1. added
    enhancement
    roadmap
    on Aug 17, 2026
  2. kinlane commented on Aug 17, 2026

    @kinlane
    ContributorAuthor

    Some background reading for this, from a read of the alias implementation as it stands — @stoplight/spectral-core 1.23.1 as vendored at v6.16.2. Exploratory, not a counter-proposal. Posting it because a few of these change the shape of what is being proposed here.

    Aliases already do not cross extends, and that is deliberate. If ruleset B defines PathItem and ruleset A extends B, rules written in A get Alias "PathItem" does not exist. A rule resolves against the ruleset it was written in, not the one it runs in — rules inherited via extends keep their original owner, and the merger explicitly preserves it. The test is named should refuse to resolve externally defined aliases.

    This is the strongest argument for the issue and also its biggest complication:

    • It is why the JSONPath criticism survives a feature built to answer it. An alias is private to the file that declares it, so everyone extending the OpenAPI ruleset and adding house rules redeclares PathItem themselves or goes back to raw JSONPath.
    • But the refusal buys something real — two extended rulesets can define the same alias name with different values and never collide. There is a fixture asserting exactly that. Any sharing mechanism has to say what replaces that protection.

    Worth stating plainly: this behaviour is documented nowhere in docs/. It is documented by a test name.

    What actually ships is thinner than it looks. Six aliases, all in the oas ruleset — PathItem, OperationObject, SecurityRequirementObject (simple), ResponseObject, LinkObject, ArrayProperties (scoped). AsyncAPI defines none. Arazzo defines none. Against a standing promise in docs/guides/4c-aliases.md that the core rulesets would ship "a common set of aliases for OpenAPI and AsyncAPI so that users don't have to do the work at all."

    Three behaviours worth knowing before designing on top of this:

    1. A scoped alias matching no format resolves to nothing, silently. No error, no warning — the rule just never runs, and that is indistinguishable from passing. Same failure mode the conformance notes flag for open format identifiers, arriving through a different door.
    2. Overlapping targets are last-wins, with no union. Targets are scanned in reverse and the first format match returns its entire given array, and only its. The source comment says this is intentional, to match the "last value wins" convention used by overrides.
    3. One scoped alias changes evaluation for the whole ruleset. hasComplexAliases is a single per-ruleset boolean. If it is false, every given expands once at load time. If any alias anywhere uses the scoped form, no given expands at load time — all of them resolve at lint time, on every run. The bundled OpenAPI ruleset has three scoped aliases, so that is the mode everyone linting OpenAPI is already in.

    Also relevant to attaching aliases to a format: Ruleset.formats is populated from exactly three places — the ruleset's own formats, those of extended rulesets, and rules' own formats. Alias-target formats are not among them. So a format appearing only inside an alias target would never be registered for detection, and that target could never match. Moot in the bundled ruleset, which declares all four formats at the top — but it is a live edge for any design that moves aliases toward formats. Code-read, no test either way.

    Open, and genuinely open:

    • Does an alias namespace version with the format, with the specification, or on its own?
    • Can a ruleset override an alias it inherits from a format — and is that a footgun?
    • Is the alias layer normative, or a registry the specification points at?
    • Is the extends refusal worth preserving in some form?

    A longer write-up with file-level citations for all of the above is now published: The alias layer, as it actually is. It cites a file for every claim, and flags three statements as code-reads with no test either way rather than stating them as fact.

    There is also a shorter post making the argument at a higher altitude: The best idea in the format is trapped inside one ruleset.

  3. kinlane commented on Aug 28, 2026

    @kinlane
    ContributorAuthor

    From the office hours of 28 August 2026 (#40) — two additions to this issue, one of which comes from another specification group that is already working on it.

    1. Aliases absorb format-version differences, and that is an argument this issue has not made.

    When you're doing path parameters, the aliases are registered based on the format version — so it's OAS2, OAS3, OAS3.1. And so the aliases themselves can obfuscate some of those version dependencies.

    So elevating aliases into the core is not only ergonomics — it is the mechanism by which one rule can span format versions without a conditional in every given. That makes this issue a dependency of #41 (ruleset modularity), where "a different ruleset per version of every standard" is the exact pain being reported by two production users.

    The blocker, restated for the record: aliases today live only in the spectral:oas ruleset as a feature of that ruleset — "and if you extend from that ruleset, you can't use them, because only that ruleset can use them."

    2. The Overlay group is working on "semantic aliases", and the example is the one that hurts most here.

    One of the things that we've talked about in the Overlay spec is having basically something like semantic aliases. And the perfect example is schema. There are certain rules that you want to apply to a schema — an object schema, a JSON Schema. But those can be in a dozen different places in an OpenAPI document, and to try to write a given that finds all those places is a nightmare.

    With the complication that makes it a genuine design problem rather than a lookup table: "without catching an example and freaking out on an example, or something else that is similarly named. Context is really important."

    Overlay 1.2 has shipped, 1.3 is starting, and Lorna Mitchell is keen to move on aliases — meetings every other Tuesday morning, channel in the OpenAPI Slack. The alias vocabulary should be reconciled with theirs before this issue invents a second incompatible one for the same idea. Tracked in #42.

    3. A migration path that is also a demo, proposed on the call:

    An Overlay example of how to replace nasty JSON-Path-based rules with alias-based rules in your OpenAPI would be incredibly meta, and also very fantastic.

    Worth taking seriously beyond the joke: #28 is stuck on the absence of an automated migration path off Spectral's JSON Path dialect, and a mechanical rewrite expressed as an Overlay is a candidate for exactly that — first for the alias move, potentially later for the RFC 9535 move.

    Related: #41 · #42 · #28 · #21.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementroadmap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions