Skip to content

v1.70.0

Latest

Choose a tag to compare

@erraggy erraggy released this 30 Nov 07:47
Immutable release. Only release title and notes can be modified.
3e90bdd

🔎 Spec Conformance, Round Two: References, HTTP Case Rules and Runtime Expressions

validate now reads a local $ref as the JSON Pointer it is, checks the runtime expressions in Links and Callbacks, compares header and media type names the way HTTP does, and refuses an empty Responses Object. diff reports its changes in a stable order and treats a new required parameter or request body as breaking. convert stops warning about a field OAS 3 still defines, and moves a path item's body and formData parameters into each operation's request body.

Most of this makes a document that passed fail, or the other way round, so read the two lists below before you upgrade.

⚠️ Documents that passed can now fail

  • A $ref that names a location that does not exist (#654). A dangling reference written with percent-encoded separators (#%2Fcomponents%2Fschemas%2FNope) used to be read as an external file and pass. It is an error now, like every other dangling reference.
  • An empty Responses Object (#658). responses: {} (or one holding only x- extensions) is an error in every version, because each says it MUST contain at least one response code. fix lists it among the errors it cannot fix and convert refuses the document.
  • Runtime expressions in Link values and Callback keys (#659). A string that begins $request. or $response., or embeds {$, must follow the grammar, and a $request.path, .query or .header name must be declared by the operation that holds the callback or the link's response (Accept, Content-Type and Authorization are exempt). Constants such as $5.00 still pass.
  • Keys of additionalOperations that name a fixed-field method (#645). GET, get and Get are errors, compared ignoring case, and such an entry no longer takes the standard operation's place in GetOperations.
  • HTTP's case rules in every version (#646). Two header parameters whose names differ only in case (X-Trace and x-trace) are duplicates, a repeated parameter makes generate refuse the document (it used to emit code that did not compile), and a response range is only 1XX to 5XX in capitals. Two response header keys that differ only in case, a header parameter named Accept, Content-Type or Authorization, and a Content-Type response header are warnings, because the specification says they are ignored.
  • diff --breaking is stricter (#646 and the release PR). A response header's schema is compared now. A new required parameter or request body is an error (it was a warning), so a pipeline that gated on exit code can start failing. Making a required parameter optional is info.

✅ Documents that failed now pass

  • Any valid JSON Pointer $ref (#654). Percent-encoded names (#/components/schemas/P%65t), pointers below a component and pointers into paths resolve. OAS 2.0 definitions with bracket names referenced by an encoded $ref validate.
  • A path or webhook name that holds a dot (#649). /v1.0/users and order.created are read as the keys they are, where the operation used to be lost or attributed to /v1.
  • allowEmptyValue on a query parameter converts without a warning that it was "removed in OAS 3.0". It was not: 3.0 and 3.1 define it for query parameters, and the converter already kept it.

📋 Results you can rely on

  • Duplicate operationId messages and parser errors are the same on every run (#648, fixes #639). The first operation is the first in the order paths, webhooks, components.pathItems, sorted within each.
  • diff reports its changes in a stable order, by path, then type, category and message. One pair of documents used to print 17 different outputs in 40 runs.
  • validate --source-map finds keys that start with a digit or hold a dot (every response code, /v1.0/x), and shows the right operation for them (#649).
  • validate reports an empty Responses Object once, at the object with its specification link.
  • The differ compares what each operation effectively takes: the path item's parameters with the operation's own overriding the one of the same name and location, each $ref read through the document's reusable parameters, and a required request body behind a $ref is read too. A change to a path item's parameters is reported once per operation under it.
  • convert moves a path item's body and formData parameters into each operation's request body (the operation's own parameter of the same name wins). They used to be written out as in: formData parameters in a 3.x document. A formData parameter's allowEmptyValue has no equivalent in a request body, so the conversion now says it was dropped, and its reports name the operation and the parameter's place in the source.

🧰 New API

// Look up the position of a dot-joined path, as validate, fix, convert, diff,
// join and generate report them. Each segment is read against the keys the
// document holds, so "/v1.0/pets" is one key.
loc := result.SourceMap.GetPath("paths./v1.0/pets.get.responses.200")
if loc.IsKnown() {
    fmt.Println(loc.Line, loc.Column)
}

// A Responses Object that is present and holds no response. A nil one is absent.
if op.Responses.IsEmpty() {
    // the document wrote responses: {}
}

// A structure error that names the object it concerns.
var se *parser.StructureError
if errors.As(err, &se) && se.Kind == parser.StructureEmptyResponses {
    fmt.Println(se.Path)
}

parser.SourceMap.GetPath, parser.Responses.IsEmpty, parser.StructureError and parser.StructureEmptyResponses are new. Nothing is removed or changed in an existing signature.

📊 What it costs

Allocations per operation, from the committed benchmark files: ValidateParsed goes from 77 to 84 on the smallest document, 671 to 733 on the medium one and 7084 to 7816 on the large one (about +9 to +10%), and Diff from 395 to 418 (+6%). Parse, fix, convert, join and generate are each within 1% of v1.69.0. The validator now checks references as JSON Pointers, parses runtime expressions and applies the HTTP case rules, and the differ builds each operation's effective parameter list.

🔒 User impact

  • No removed or changed API, and no change to the CLI's flags. The command line examples in the help text and the docs now put the flags before the file path, which is the order that works.
  • The ten corpus specifications produce the same validate messages as before this release.
  • ✅ 12,547 tests pass, govulncheck is clean, and every new rule was checked by breaking it and watching a test fail.

What's Changed

  • fix(validator): reject additionalOperations keys that name a fixed-field method by @erraggy in #645
  • fix: compare names and values that map to HTTP as HTTP does by @erraggy in #646
  • fix(parser,validator): duplicate operationIds name the lowest operation on every run by @erraggy in #648
  • fix(parser,validator): read dot-joined paths against the keys the document holds by @erraggy in #649
  • fix(validator,parser): read a local $ref as the JSON Pointer it denotes by @erraggy in #654
  • docs(claude): a local $ref is a JSON Pointer with one reader by @erraggy in #657
  • fix(validator): an empty Responses Object is an error in every version by @erraggy in #658
  • feat(validator): check runtime expressions in Link values and Callback keys by @erraggy in #659
  • chore: prepare v1.70.0 release by @erraggy in #662

Issues Fixed

Full Changelog: v1.69.0...v1.70.0