Adding custom code samples
Learn how to configure custom code samples to display alongside your API endpoints.
Last updated
Was this helpful?
Learn how to configure custom code samples to display alongside your API endpoints.
Last updated
Was this helpful?
GitBook can automatically generate generic code examples for each API operation. If you’d prefer to showcase custom or more detailed snippets, add x-codeSamples
to your OpenAPI definition. This way, you control how your endpoints are demonstrated and can offer language or SDK-specific examples.
Key Points
x-codeSamples
is an array of code sample objects.
Each object defines:
lang
: The language of the code (e.g., JavaScript, Java).
label
: A short label for the code block.
source
: The actual code snippet.
We’re currently improving how you build API documentation in GitBook. This page covers features that are being gradually rolled out. If you don’t see them yet, hang tight—they’re on the way!