fix(compilers/openapi): detect a version key past the sniff cap - #435
Merged
Conversation
Detect capped its search for `openapi`/`swagger` at the first 64 KiB, so a valid document that writes a large object before its version key was reported as an unrecognized format. Stripe's published spec3.json is one: `components` runs to megabytes and `openapi` lands at byte 2,593,401. Mapping key order carries no meaning, so the same document with its keys the other way round compiled fine — the format answer depended on where a writer put a key. The 64 KiB prefix keeps its place as the fast path, and every document that declares a key there is still answered without a full parse. When the prefix declares neither key, a byte scan of the whole source decides whether to read it whole: only bytes that name `openapi:` or `swagger:` as a top-level key reach the parse, so a source of another format still gets the fast path's silence and never a complaint from this compiler. That scan is what Detect already used to tell its own broken source from another format's, and it is no longer bounded to the prefix either. A document whose prefix does not parse and whose declaration sits past the cap is now reported as an undecodable OpenAPI source rather than declined, which is the answer the surrounding rule always intended; detection now reads the bytes it would have had to read to say otherwise. Fixes #420 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SYeBgDsskwnyitLgPGCPn1
Wahbeh-Mohammad
left a comment
There was a problem hiding this comment.
Checked by running the code, not just reading it. The Stripe case works: real spec3.json goes from exit 1 on main to exit 0 here. One correction to the body: the note that the fix "missed JSON" is wrong, JSON is the case that works.
Four comments inline: the unbounded whole-file parse, other formats' files getting claimed, tests that stay green with the logic broken, and key order still deciding the result when both keys are present.
|
Review done by me + fable |
Wahbeh-Mohammad
approved these changes
Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #420. Not breaking.
Stripe's published
spec3.json— valid OpenAPI 3.0 — was rejected asengine/unrecognized-formatbecause detection sniffed only the first 64 KiB looking for a top-levelopenapikey, and Stripe puts a multi-megabytecomponentsobject first.openapilands at byte 2,593,401.The 64 KiB prefix scan stays as the fast path, extracted unchanged into
sniffPrefix. When the prefix declares neitheropenapinorswagger, a cheap whole-source byte scan decides whether the document is worth reading whole. A source of another format still gets the fast path's silence —detect.go's rule that this compiler must never claim or complain about another format's bytes is preserved.Verified end-to-end, not just at
Detect: a synthetic 279 KB spec withopenapiat byte 279,062 goesexit 1→exit 0through the real CLI.Stack 1 of 8. Base
main— review and merge bottom-up. Every commit here passedmake gatewhen it landed, and the full gate was re-run on the top of the stack. Run it asGOTOOLCHAIN=go1.26.3 make gate; this machine's Go 1.27 fails it for reasons unrelated to any change (#431).🤖 Generated with Claude Code
https://claude.ai/code/session_01SYeBgDsskwnyitLgPGCPn1