feat(codemode): add OpenAPI tool adapter#35192
Merged
Merged
Conversation
Wiktor102
pushed a commit
to Wiktor102/opencode
that referenced
this pull request
Jul 5, 2026
drewr
pushed a commit
to drewr/opencode
that referenced
this pull request
Jul 7, 2026
shaheislam
pushed a commit
to shaheislam/opencode-vim
that referenced
this pull request
Jul 7, 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.
Adds
OpenAPI.fromSpec(exported as@opencode-ai/codemode/openapi): a basic OpenAPI 3.x document -> codemode tool subtree adapter, one tool per operation. The host places the subtree under a key in itstoolstree; that key is the model-visible namespace.Design
security(root default, operation override,security: []/ empty{}alternative = unauthenticated), picks the first satisfiable OR alternative (AND within one), and injects credentials from a hostauth.resolvecallback into the carrier the scheme declares.undefinedfrom the resolver tries the next alternative; a failure aborts the call so an expired refresh token cannot fall through to unauthenticated.HttpClient.HttpClient(effect/unstable/http) in R; hosts provideFetchHttpClient.layeror a custom/test layer. No new dependencies; the spec is a parsed document (hosts parse JSON/YAML themselves).fromSpecis sync and total: returns{ tools, skipped }. Operations it cannot represent (non-JSON request bodies, non-absolute server URLs) land inskippedwith a reason instead of becoming broken tools.path/query/headers/body); outputs come from the first success (2xx/2XX) JSON response, no-content success ->null;#/components/schemas/*refs are shared as$defsso signatures expand referenced types. Reserved header parameters (Accept/Content-Type/Authorization) are ignored per the spec. Non-2xx responses become safe catchable tool failures carrying status + size-capped body summary../../empty rejected (URL retargeting), required query/header/body inputs fail before auth/network, operation names avoid CodeMode-blocked members, and record lookups keyed by spec/model-controlled names guard against prototype-inherited values.allOf(union members parenthesized) and teachesServices<Tools>to infer R from index-signature tool records.Deliberately out of scope for a basic converter: YAML parsing, server URL templates/variables, path/operation-level server overrides, cookie parameters, multipart/binary bodies, and
default-response schemas.Verification
bun typecheckandbun testfrompackages/codemode(243 pass; 19 adapter tests covering auth semantics, carriers, resolver failure vs unavailability, unauthenticated alternatives, response-schema selection, naming sanitization/dedup/blocking, header precedence, required query/header preflight, path traversal rejection, and skipped reporting)