Skip to main content

Test it button

You can configure the “Test it” button and accompanying window in GitBook using several OpenAPI extensions. These extensions help improve and configure the testing suite for users. The interactive test functionality is powered by Scalar and allows users to execute live API requests directly from your documentation.

Hiding the test it button

You can hide the “Test it” button from your endpoints by adding the x-hideTryItPanel extension to an endpoint, or at the root of your OpenAPI spec. For a specific endpoint:
openapi.yaml
For all endpoints (at root level):
openapi.yaml
Hiding the test functionality is useful for documentation-only endpoints, webhooks, or operations that require complex setup that can’t be easily replicated in the browser.

Enable authentication in the testing window

The request runner can only present and apply auth if your spec declares it. Define schemes under components.securitySchemes, then attach them either globally via security (applies to all operations) or per-operation (overrides global).

Declare your auth scheme

Below are common patterns. Use straight quotes in YAML.

Apply schemes globally or per operation

When you define security schemes, GitBook automatically adds an authentication input field to the “Test it” panel, allowing users to provide their credentials.

Control the endpoint URL with servers

The request runner targets the URL(s) you define in the servers array. Declare one or more servers; you can also parameterize them with variables.

Single server

openapi.yaml

Multiple servers

openapi.yaml
Users can select which server to target from a dropdown in the test panel.

Server variables

For dynamic server URLs, use variables that users can customize:
openapi.yaml
This allows users to input their specific instance and region before testing.

Per-operation servers

You can override the global servers array for specific operations:
openapi.yaml
Ensure your API servers have proper CORS headers configured to allow requests from your documentation domain. Otherwise, browser-based testing will fail.

Complete example

Here’s a complete example showing authentication, servers, and test configuration:
openapi.yaml

Best practices

1

Configure CORS properly

Ensure your API allows cross-origin requests from your documentation domain. Test the “Test it” functionality thoroughly.
2

Provide sandbox environments

Include a sandbox or staging server in your servers array so users can test without affecting production data.
3

Document authentication clearly

In your security scheme descriptions, explain how users can obtain valid credentials for testing.
4

Use realistic examples

Provide example values in your spec so the test panel is pre-populated with sensible defaults.
5

Hide when inappropriate

Use x-hideTryItPanel for operations that can’t be easily tested in a browser, like file uploads or webhooks.