Repository navigation
Description
Problem
With #1996 (at 6630476), an inline allOf entry writing keywords the IR has no field for keeps each under its own key (openapi:<keyword>, out_of_scope) and reports each with its own info, where main (at 9562ea4) kept the entry whole under one openapi:allOf/N and reported it once, naming every keyword it holds. The keys stay per keyword either way (#1989 settled that a consumer takes one keyword's reason apart from its neighbours'); the open question is only the number of reports. An entry writing k such keywords draws k infos where one naming all k says as much, and an allOf of n such entries draws k × n.
$ cat gen.py
import sys
n = int(sys.argv[1])
entries = ", ".join("{" + ", ".join(f"k{i}{c}: 1" for c in "abcde") + "}" for i in range(n))
print('openapi: 3.1.0\ninfo: {title: t, version: "1"}\npaths: {}\ncomponents:\n schemas:\n S: {type: object, allOf: [' + entries + ']}')
$ python3 gen.py 200 > spec.yaml
$ morphic compile --diag-limit 0 spec.yaml >ir.json 2>err.txt; echo "exit $?"On main (first two infos of err.txt, then the counts):
info openapi/degraded-construct spec.yaml#/components/schemas/S/allOf/0: inline allOf branch is merged in place, and nothing reads the rest of it; the branch (k0a, k0b, k0c, k0d, k0e) is kept verbatim under Unmodeled
info openapi/degraded-construct spec.yaml#/components/schemas/S/allOf/1: inline allOf branch is merged in place, and nothing reads the rest of it; the branch (k1a, k1b, k1c, k1d, k1e) is kept verbatim under Unmodeled
$ jq -c '[.diagnostics[] | .code] | group_by(.) | map({(.[0]): length}) | add' ir.json
{"openapi/degraded-construct":200}
$ jq -c '.types | to_entries[] | select(.key | test("schemas/S$")) | {unmodeledEntries: (.value.unmodeled | length), reasons: (.value.unmodeled | map(.reason) | unique)}' ir.json
{"unmodeledEntries":200,"reasons":["degraded_lowering"]}With #1996:
info openapi/unknown-schema-keyword spec.yaml#/components/schemas/S/allOf/0/k0a: keyword "k0a" has no field in the schema model this compiler lowers and no IR position of its own; kept verbatim under Unmodeled
info openapi/unknown-schema-keyword spec.yaml#/components/schemas/S/allOf/0/k0b: keyword "k0b" has no field in the schema model this compiler lowers and no IR position of its own; kept verbatim under Unmodeled
$ jq -c '[.diagnostics[] | .code] | group_by(.) | map({(.[0]): length}) | add' ir.json
{"openapi/unknown-schema-keyword":1000}
$ jq -c '.types | to_entries[] | select(.key | test("schemas/S$")) | {unmodeledEntries: (.value.unmodeled | length), reasons: (.value.unmodeled | map(.reason) | unique)}' ir.json
{"unmodeledEntries":1000,"reasons":["out_of_scope"]}What the two cost, one compile each of gen.py N (/usr/bin/time -l, instructions retired; jq '.diagnostics' and jq '.types' for the bytes of those two members of the IR):
| N | file | main instructions | #1996 instructions | main IR | #1996 IR |
|---|---|---|---|---|---|
| 200 | 9,960 B | 267.6M | 369.7M (1.38x) | 143,731 B | 570,461 B |
| 400 | 20,360 B | 411.7M | 616.5M (1.50x) | 287,131 B | 1,142,461 B |
| 800 | 41,160 B | 733.1M | 1,124.2M (1.53x) | 573,931 B | 2,286,461 B |
At N = 200 the diagnostics are 57,742 B on main and 279,352 B with #1996, and the types 35,732 B and 126,652 B. The growth in types is the entries (1,000 per-keyword entries with their provenance instead of 200 per-entry ones) and is the IR's price for keeping the keywords apart; the growth in diagnostics is five reports for each entry's one.
Cause
keepUnknownOf (compilers/openapi/internal/schema/entrykept.go) hands an entry's unknown keywords to annotation.UnknownKeywordsIn, which keeps and reports each at its own pointer (#1996 at 6630476). The entry's other unread keywords, the ones no home holds, are reported in one finding at the entry (recordEntryUnhomed), so one entry already draws both shapes of report. On main, diagUnmergedBranch (compilers/openapi/internal/schema/allof.go) drew one for the entry (9562ea4).
Direction
A draft. Two readings, with the key and the reason per keyword the same in both:
- One report per keyword, as refactor(compilers/openapi)!: lower a schema from one statement #1996. Each finding sits at the keyword's own pointer, so a triage rule written against a keyword's pointer places it exactly, and a finding names one reason. It costs
kreports for one fact of an entry, and the volume scales with the keywords written. - One report per entry and reason, at the entry's pointer, naming every keyword kept under that reason (
unknown keywords k0a, k0b, k0c, k0d, k0e kept verbatim under Unmodeled), asmainnamed them. It draws the report volume back to the entry count and leaves the keys as they are. It costs a report whose pointer is the entry's rather than the keyword's, so a triage rule that wants one keyword's report has the entry's to select from, and a keyword written on an entry with others of a different reason (a validation-only one beside an unknown one) draws one report per reason.
What decides it is the cost against what a reader of the report needs: for an allOf of 6,400 entries writing five unknown keywords each the first draws 32,000 infos.
Out of scope
- The Unmodeled entries per keyword (openapi: a keyword on an inline allOf branch kept whole loses its own key, reason and report #1989 settled them) and the IR size they bring.
- The words of the reports and the two readers an entry's report passes through (openapi: an allOf entry kept whole is reported apart from the same keywords beside the allOf, in its count and its words #2057).
Priority: P4, rule 3 (off the golden spec; the report's volume). jq '[.diagnostics[] | select(.code == "openapi/unknown-schema-keyword")] | length' ir.json over the golden spec compiled by main (9562ea4) and #1996 (6630476) → 0 and 0 (cloudflare/api-schemas@8b1a4518).
Activity
OmarAlJarrah commentedon Nov 30, 2026
Decided in #2354 at 7213104: one report per keyword kept, as the flat spelling reports it. A keyword on an entry is read at the entry's own pointer and reported as the same keyword beside the
allOfis (docs/compilers/openapi.md#allof-inline-residue), and an entry kept whole draws one report naming every keyword it holds. Sogen.py 200still draws 1,000openapi/unknown-schema-keywordinfos. The full schema cases still record spelling findings under this issue's reason (split-degraded-reports: unread keywords split between the position and an entry draw two reports), so it stays open until those are fixed or recorded under the decision.test(internal/harness): hold the full case records to one reading
test(harness): drop the entry discriminator records, class their pairs