Repository navigation
openapi: a key that is no scalar draws findings about the empty name it is read as #1108
Description
Problem
A mapping key that is no scalar is reported once as an error: oas.CheckFormat holds every key to the Format section's rule that a key is a string, and says the parser reads such a key as the empty string (docs/parser-library.md#non-scalar-key). Every rule that judges a key's text then judges that empty string as if the document wrote it, so one defect draws up to three findings at one place.
openapi: 3.1.0
info: {title: T, version: "1"}
paths:
? [p]
: {get: {responses: {"200": {description: ok}}}}
/a:
get:
responses:
? {code: 1}
: {description: weird}
"200": {description: ok}
components:
schemas:
? [s]
: {type: object}morphic compile reports, besides one validation-type-mismatch error per key:
warning openapi/validation/validation-invalid-syntax cascade.yaml:15:7 (#/components/schemas/): Components Object field "schemas" has the key "", which must be a name of letters, digits, '.', '-' and '_' in OpenAPI 3.1 (Components Object)
warning openapi/invalid-path-key cascade.yaml#/paths/: path key "" is not a valid path template: does not begin with "/"; the key is used as written
warning openapi/invalid-status-key cascade.yaml#/paths/~1a/get/responses/: response key "" is no status code, no 1XX-5XX range, and not default; the response is kept with no status condition
The document writes no key "". A key written as "" should still draw each of these.
Cause
nodeview.Pair carries a key's text alone, so a reader past nodeview.KeyOf cannot tell "" written from "" read off a key that is no scalar: the component-name check in oas.walker.entries, and the path-key and status-key checks in operation, which read the parser's model keys.
Direction
A proposal. The Format error is the verdict on such a key; a rule judging a key's spelling leaves it to that error, as docs/compilers/openapi.md#validation already leaves a null whose requirement another rule reports. Two shapes:
nodeview.Paircarries whether its key was a scalar (or the key node itself), and each key-spelling rule skips one that was not. The view's memo holds up tomaxCachedPairspairs, so the field's cost is that bound times its size.- The rules ask the raw mapping at the pointer they report at, which the operation readers, holding model keys, cannot do without a lookup of their own.
Decide whether invalid-path-key and invalid-status-key also defer: unlike the name check, each says what happened to the entry, not only what is wrong with its key.
Out of scope
Extension mappings with non-string keys (#617), and keys merged in through <<, which the Format check places at the merge source.
Priority: P4, rule 2 (corrupt-spec guard): only a document that already fails the Format rule draws the extra findings. morphic compile cascade.yaml → the three warnings above beside three errors (morphic @0f7aec0a, #1106's head).
Activity
docs(compilers/openapi): state what CheckFormat leaves to #1108