Add a Custom language option to OpenAPI code samples#4310
Open
zenoachtig wants to merge 4 commits into
Open
Conversation
OpenAPI code-sample blocks now show a language icon next to every option and add a "Custom language" entry that opens the assistant pre-filled (as a draft, not sent) with the current request staged as a reference and the prompt "Rewrite this in the following language: ", letting readers rewrite the request in any language. - react-openapi: new OpenAPICodeSampleAssistant context the host app fills in; the selector renders per-language icons and the Custom action item (OpenAPISelect gains an action/onAction concept so it fires without changing the selection). Adds getCodeSampleIcon to the render context and 3 translation keys across all locales. - gitbook: new setDraft controller method + inputDraft state so the chat input can be pre-filled without sending; OpenAPICodeSampleAIProvider bridges the GitBook assistant (logo, name, reference + draft action) into react-openapi, mounted once in SpaceLayout (covers site and embed); maps languages to icons. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: ac15ae7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
Apply the language/assistant icon spacing via a margin on the icon nodes instead of adding gaps to the shared .openapi-select-item / SelectValue rules. This keeps other OpenAPI selectors (media-type, response examples) visually unchanged, instead of shifting e.g. the response status code + label spacing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…agupta-7cd6fa # Conflicts: # packages/react-openapi/src/OpenAPICodeSampleSelector.tsx # packages/react-openapi/src/context.ts
…agupta-7cd6fa # Conflicts: # packages/gitbook/src/components/DocumentView/OpenAPI/style.css
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.
Overview
x-codeSampleslanguages) now shows a language icon in the dropdown.Implementation notes
@gitbook/react-openapirenders the dropdown but can't import the app's AI code, so the assistant is bridged in through a newOpenAPICodeSampleAssistantReact context ({ label, icon, onRewrite }). The Custom option only appears when that context is provided.OpenAPISelectgains anaction/onActionconcept so an item can trigger a side effect without changing the persisted selection (the dropdown stays on the previously selected language).getCodeSampleIconon the render context; the currently displayed code is read from the panel at click time.gitbook: a newsetDraftcontroller method +inputDraftstate lets the chat input be pre-filled without sending (this didn't exist before).OpenAPICodeSampleAIProvidersupplies the assistant logo/name and theaddReference+setDraft+openaction, mounted once inSpaceLayout(covers both the site and the embed).getOpenAPIContextmaps languages to icons.Demo
Verified locally against GitBook's own API reference (assistant enabled):
</> HTTPreference chip and the input pre-filled with "Rewrite this in the following language: " — not sent (no message posted), with the code-sample selector still on the previously selected language.Validated with
bun run typecheck,bun run build, Biome, and thereact-openapiunit suite (196 passing).— Authored by Claude