### Quick Start: Scalar CLI Help
Source: https://guides.scalar.com/scalar/scalar-cli/getting-started
Execute the help command for the Scalar CLI without global installation using npx.
```bash
npx @scalar/cli help
```
--------------------------------
### Install Scalar CLI Globally
Source: https://guides.scalar.com/scalar/scalar-cli/getting-started
Install the Scalar CLI globally using npm for direct command execution.
```bash
npm -g install @scalar/cli
```
--------------------------------
### AdonisJS Project Setup Prompts
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/adonisjs
Example prompts and selections for initializing an AdonisJS project, including API Starter Kit, Access Token authentication, SQLite database, and npm dependency installation.
```plaintext
Which starter kit would you like to use?
❯ API Starter Kit
Select the authentication guard you want to use …
❯ Access Token
Select the database driver you want to use …
❯ SQLite
Do you want us to install dependencies using "npm"?
❯ Yes
```
--------------------------------
### Steps Container Example (Markdown)
Source: https://guides.scalar.com/scalar/scalar-docs/components/steps
Shows how to group multiple scalar-step components within a scalar-steps container using Markdown, with examples for project setup, dependency installation, and starting development.
```markdown
::::scalar-steps
:::scalar-step{ id="step-1" title="Setup Project" }
Initialize a new project:
```bash
mkdir my-project
cd my-project
npm init -y
```
:::
:::scalar-step{ id="step-2" title="Install Dependencies" }
Install the required packages:
```bash
npm install react react-dom
```
:::
:::scalar-step{ id="step-3" title="Start Development" }
Begin development:
```bash
npm start
```
:::
::::
```
--------------------------------
### Force Install Scalar CLI (Conflict Resolution)
Source: https://guides.scalar.com/scalar/scalar-cli/getting-started
Force install the Scalar CLI globally using npm to resolve naming conflicts with other CLIs.
```bash
npm -g --force install @scalar/cli
```
--------------------------------
### Run Docusaurus Playground Example
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/docusaurus
Executes a playground script to run an example Docusaurus project, likely demonstrating the Scalar integration. This command is used to test the setup.
```bash
npm run playground
```
--------------------------------
### Start Docusaurus Development Server
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/docusaurus
Starts the Docusaurus development server after navigating into the project directory. This command allows for live previewing of the Docusaurus site.
```bash
cd my-awesome-website
pnpm start
```
--------------------------------
### Steps Container Example (HTML)
Source: https://guides.scalar.com/scalar/scalar-docs/components/steps
Provides an example of using a scalar-steps container in HTML to group multiple scalar-step components, including setup, installation, and development commands.
```html
Initialize a new project:
```bash
mkdir my-project
cd my-project
npm init -y
```
Install the required packages:
```bash
npm install react react-dom
```
Begin development:
```bash
npm start
```
```
--------------------------------
### Start AdonisJS Development Server
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/adonisjs
Commands to navigate into the project directory and start the AdonisJS development server.
```bash
cd my-awesome-app
npm run dev
```
--------------------------------
### Execute Scalar CLI Without Installation (npm/pnpm)
Source: https://guides.scalar.com/scalar/scalar-cli/getting-started
Execute Scalar CLI commands without global installation using npx (npm) or pnpm dlx.
```bash
# Execute without installation (npm)
npx @scalar/cli help
# Execute without installation (pnpm)
pnpm dlx @scalar/cli help
```
--------------------------------
### Install Scalar Guide Elements
Source: https://guides.scalar.com/scalar/scalar-docs/components/tabs
Installs the '@scalar/guide-elements' package using npm. This is a prerequisite for using the Scalar guide components.
```bash
npm install @scalar/guide-elements
```
--------------------------------
### Basic Scalar Step Example (Markdown)
Source: https://guides.scalar.com/scalar/scalar-docs/components/steps
Shows how to implement a basic scalar-step in Markdown, including a command to install dependencies.
```markdown
:::scalar-step{ id="step-1" title="Install Dependencies"}
First, install the required dependencies by running:
```bash
npm install @scalar/guide-elements
```
:::
```
--------------------------------
### Basic Scalar Step Example (HTML)
Source: https://guides.scalar.com/scalar/scalar-docs/components/steps
Demonstrates the basic usage of the scalar-step component in HTML, including installation instructions for dependencies.
```html
First, install the required dependencies by running:
```bash
npm install @scalar/guide-elements
```
```
--------------------------------
### Install Scalar.AspNetCore Package
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/net-aspnet-core/integration
Installs the Scalar.AspNetCore NuGet package using the .NET CLI.
```shell
dotnet add package Scalar.AspNetCore
```
--------------------------------
### Scalar CLI Authentication: Web Login
Source: https://guides.scalar.com/scalar/scalar-cli/getting-started
Initiate the web-based authentication process for the Scalar CLI.
```bash
scalar auth login
```
--------------------------------
### Installing React Renderer for Scalar
Source: https://guides.scalar.com/scalar/scalar-api-references/plugins
Provides the command to install the necessary package for rendering Scalar API reference extensions using React.
```bash
npm install @scalar/react-renderer react react-dom
```
--------------------------------
### Scalar CLI Authentication: Token/Machine Based
Source: https://guides.scalar.com/scalar/scalar-cli/getting-started
Authenticate with the Scalar platform using a token, suitable for CI/CD or programmatic use.
```bash
scalar auth login --token 1234secrettoken5678
```
--------------------------------
### Initialize AdonisJS Project
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/adonisjs
Command to create a new AdonisJS project. It prompts for starter kit, authentication guard, database driver, and dependency installation.
```bash
npm init adonisjs@latest my-awesome-app
```
--------------------------------
### Install Laravel Installer
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/laravel-scribe
Installs the Laravel installer globally using Composer, which is a prerequisite for creating new Laravel projects.
```bash
composer global require "laravel/installer=~1.1"
```
--------------------------------
### Create Docs Folder and Example File
Source: https://guides.scalar.com/scalar/scalar-docs/github-sync
This snippet demonstrates how to create a 'docs' folder and an example markdown file named 'introduction.md' using bash commands.
```bash
# Create a docs/ folder
mkdir docs
# Create an example file echo "# Hello World" > docs/introduction.md
```
--------------------------------
### Install scalar-fastapi
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/fastapi
Installs the scalar-fastapi library using pip. This is the first step to integrate Scalar with your FastAPI application.
```bash
pip install scalar-fastapi
```
--------------------------------
### Next.js Project Setup Prompts
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/nextjs
Example prompts and default answers when creating a new Next.js project.
```plaintext
? Would you like to use TypeScript? › No
? Would you like to use ESLint? › No
? Would you like to use Tailwind CSS? … No
? Would you like to use `src/` directory? › No
? Would you like to use App Router? (recommended) › Yes
? Would you like to customize the default import alias (@/*)? … No
```
--------------------------------
### Serve Laravel Project
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/laravel-scribe
Starts a local development server for the Laravel project using the Artisan command. This allows you to view the application in a browser.
```bash
php artisan serve
```
--------------------------------
### Preview Scalar Guides
Source: https://guides.scalar.com/scalar/scalar-cli/commands
Previews Scalar guides by running a local server. It takes the path to the Scalar configuration file and allows specifying the port, log level, and log formatting.
```plaintext
Usage: scalar project preview [options] [config]
Preview scalar guides
Arguments:
config Path to the Scalar configuration file
(usually `scalar.config.json5` or
`scalar.config.json`)
Options:
-p, --port [port] port to run the server on. If the port is
not available, it will select another one.
(default: "7970")
-L, --log-level Set the log level (debug, info, warn,
error, trace) (default: "info")
-F, --log-formatting Set the log formatting (pretty|none). Defaults to pretty formatting outside of CI. (default: "pretty")
-N, --no-open Do not open the browser automatically
-h, --help display help for command
```
--------------------------------
### Generate Python SDK with Scalar
Source: https://guides.scalar.com/scalar/scalar-sdks/getting-started
This snippet outlines the steps to generate a Python SDK using Scalar.com. Users select Python from the available language options during the SDK creation process.
```text
From the dashboard left-most sidebar under Products > SDKs, then click Create new SDK.
Select Python and click "Continue" to begin generating your SDKs.
```
--------------------------------
### Install Fastify API Reference
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/fastify
Installs the Scalar API reference package for Fastify using npm.
```bash
npm install @scalar/fastify-api-reference
```
--------------------------------
### Complete Scalar Configuration Example
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/spring-boot
An example demonstrating all available configuration options for the Scalar API reference, including basic settings, UI customization, themes, and document download types.
```properties
# Basic configuration
scalar.url=https://my-api-spec.json
scalar.path=/docs
scalar.enabled=true
# UI customization
scalar.showSidebar=true
scalar.hideModels=false
scalar.hideTestRequestButton=false
scalar.hideSearch=false
# Theme and appearance
scalar.darkMode=false
scalar.hideDarkModeToggle=false
scalar.theme=default
scalar.layout=modern
# Document options
scalar.documentDownloadType=both
# Custom styling
scalar.customCss=body { font-family: 'Arial', sans-serif; }
```
--------------------------------
### Install @scalar/docusaurus
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/docusaurus
Installs the Scalar Docusaurus plugin using npm. This package allows Docusaurus websites to render Scalar API references.
```bash
npm install @scalar/docusaurus
```
--------------------------------
### Generate Golang SDK with Scalar
Source: https://guides.scalar.com/scalar/scalar-sdks/getting-started
This snippet explains how to generate a Golang SDK using Scalar.com. The process involves selecting Golang as the desired language in the SDK creation interface.
```text
From the dashboard left-most sidebar under Products > SDKs, then click Create new SDK.
Select Golang and click "Continue" to begin generating your SDKs.
```
--------------------------------
### Install @scalar/nuxt Module
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/nuxt
Install the Scalar Nuxt module using npx for quick setup in your Nuxt application.
```bash
npx nuxi module add @scalar/nuxt
```
--------------------------------
### Install Scalar API Reference React Package
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/react
Installs the necessary package for using Scalar's API Reference component in a React project using npm.
```bash
npm install @scalar/api-reference-react
```
--------------------------------
### GitHub Actions: Validate OpenAPI File
Source: https://guides.scalar.com/scalar/scalar-cli/getting-started
A GitHub Actions workflow to validate an OpenAPI file using the Scalar CLI.
```yml
# .github/workflows/validate-openapi-file.yml
name: Validate OpenAPI File
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Validate OpenAPI File
# Replace "./my-openapi-file.yaml" with the correct path and filename for your project.
# Or: run `npx @scalar/cli init` and add the config file to your repository.
run: npx @scalar/cli document validate docs/openapi.yaml
```
--------------------------------
### Install Scalar Fastify API Reference
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/fastify
Installs the @scalar/fastify-api-reference package using npm, which is used to render the API reference.
```bash
npm install @scalar/fastify-api-reference
```
--------------------------------
### Start Next.js Development Server
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/nextjs
Commands to navigate into the project directory and start the development server.
```bash
cd my-awesome-app
npm run dev
```
--------------------------------
### Generate TypeScript SDK with Scalar
Source: https://guides.scalar.com/scalar/scalar-sdks/getting-started
This snippet demonstrates the process of generating a TypeScript SDK using the Scalar platform. It involves navigating the dashboard and selecting TypeScript as the target language for SDK generation.
```text
From the dashboard left-most sidebar under Products > SDKs, then click Create new SDK.
Select TypeScript and click "Continue" to begin generating your SDKs.
```
--------------------------------
### Actix Integration with Scalar
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/rust
Provides a complete Rust code example for integrating Scalar documentation with the Actix web framework. It includes setting up the documentation route, serving the OpenAPI JSON, and configuring the Actix server.
```rust
use actix_web::{get, App, HttpResponse, HttpServer, Responder};
use scalar_doc::scalar_actix::ActixDocumentation;
#[get("/")]
async fn doc() -> impl Responder {
ActixDocumentation::new("Api Documentation title", "/openapi")
.theme(scalar_doc::Theme::Kepler)
.service()
}
#[get("/openapi")]
async fn openapi() -> impl Responder {
let open = include_str!("openapi.json");
HttpResponse::Ok().body(open)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(doc).service(openapi))
.bind(("127.0.0.1", 8080))?
.run()
.await
}
```
--------------------------------
### Install Scalar Express API Reference
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/express
Installs the Scalar Express API Reference middleware using npm.
```bash
npm install @scalar/express-api-reference
```
--------------------------------
### Install Scalar API Reference Package
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/django-ninja
Installs the Scalar API Reference package for Django from GitHub.
```bash
pip install git+https://github.com/scalar/scalar.git#subdirectory=packages/scalar_django_ninja
```
--------------------------------
### Install Scalar API Reference React Package with pnpm
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/react
Installs the necessary package for using Scalar's API Reference component in a React project using pnpm.
```bash
pnpm add @scalar/api-reference-react
```
--------------------------------
### Install Hono API Reference Middleware
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/hono
Installs the Scalar Hono API Reference middleware using npm.
```bash
npm install @scalar/hono-api-reference
```
--------------------------------
### Start Docker Compose Services
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/docker
Command to start the services defined in the `docker-compose.yml` file, launching the Scalar API Reference container.
```bash
docker-compose up
```
--------------------------------
### Scalar CLI Publish Multiple APIs
Source: https://guides.scalar.com/scalar/scalar-registry/cli
Example of publishing multiple OpenAPI documents from a repository using the Scalar CLI, suitable for scripts or CI/CD pipelines.
```bash
# Example: Publish multiple APIs
scalar registry publish ./apis/user-api/openapi.json --namespace myteam --slug user-api
scalar registry publish ./apis/product-api/openapi.json --namespace myteam --slug product-api
scalar registry publish ./apis/order-api/openapi.json --namespace myteam --slug order-api
```
--------------------------------
### Install Django Ninja
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/django-ninja
Installs the Django Ninja package, which also installs Django.
```bash
pip install django-ninja
```
--------------------------------
### Install scalar-doc for Actix
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/rust
Command to add the `scalar-doc` crate to a Rust project with the `actix` feature enabled, preparing it for Actix web framework integration.
```bash
cargo add scalar-doc -F actix
```
--------------------------------
### Markdown Alert Example
Source: https://guides.scalar.com/scalar/scalar-api-references/markdown
Demonstrates how to use a 'tip' markdown alert within descriptions. This feature allows for formatted notes or tips to be displayed to users.
```markdown
> [!tip]
> You can now use markdown alerts in your descriptions.
```
--------------------------------
### Install NestJS API Reference
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/nestjs
Install the Scalar NestJS API reference package using npm.
```bash
npm install @scalar/nestjs-api-reference
```
--------------------------------
### Install Next.js API Reference Package
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/nextjs
Installs the Scalar Next.js API Reference package using npm.
```bash
npm install @scalar/nextjs-api-reference
```
--------------------------------
### Install Scalar Django Ninja Integration
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/django-ninja
Installs the Scalar Django Ninja integration package from GitHub using pip.
```bash
pip install git+https://github.com/scalar/scalar.git#subdirectory=integrations/django-ninja
```
--------------------------------
### Install Swashbuckle.AspNetCore.Cli Tool
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/net-aspnet-core/build-time-generation
Installs the Swashbuckle CLI tool, which is used for generating OpenAPI documents at build time. This involves creating a tool manifest and then installing the package.
```shell
dotnet new tool-manifest
dotnet tool install Swashbuckle.AspNetCore.Cli
```
--------------------------------
### Provide Custom SDK Installation Instructions
Source: https://guides.scalar.com/scalar/scalar-api-references/openapi
Explains how to include custom SDK installation instructions within an OpenAPI document using the 'x-scalar-sdk-installation' extension. It supports both Markdown descriptions and shell script sources.
```yaml
openapi: 3.1.0
info:
title: Example
version: 1.0
x-scalar-sdk-installation:
- lang: Node
description: Install our **Custom SDK** for Node.js from npm:
source: |-
npm install @your-awesome-company/sdk
```
--------------------------------
### Install Fastify Swagger
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/fastify
Installs the official @fastify/swagger package using npm, which is used to generate OpenAPI 3.0 files.
```bash
npm install @fastify/swagger
```
--------------------------------
### Static Scalar Step Example (HTML)
Source: https://guides.scalar.com/scalar/scalar-docs/components/steps
Illustrates how to create a non-collapsible (static) scalar-step using HTML, with an example JavaScript configuration.
```html
This step cannot be collapsed and is always visible.
```javascript
const config = {
theme: 'dark',
interactive: false,
}
```
```
--------------------------------
### Create and Run a Basic Fastify Project
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/fastify
Sets up a new Fastify project, including installing dependencies, creating an index file, and configuring package.json for ES Modules.
```bash
npm init
npm install fastify
```
```js
// index.js
import Fastify from 'fastify'
// Instantiate the framework
const fastify = Fastify({
logger: true,
})
// Declare a route
fastify.get('/', function (request, reply) {
reply.send({ hello: 'world' })
})
// Run the server
fastify.listen({ port: 3000 }, function (err, address) {
if (err) {
fastify.log.error(err)
process.exit(1)
}
console.log(`Fastify is now listening on ${address}`)
})
```
```diff
{
"name": "my-fastify-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
+ "type": "module",
"scripts": {
+ "dev": "npx nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
…
}
```
```bash
npm run dev
```
--------------------------------
### Include Custom Code Samples (x-codeSamples)
Source: https://guides.scalar.com/scalar/scalar-api-references/openapi
Provides examples for popular HTTP clients and frameworks, or custom SDK usage. Supports multiple languages and labels for different examples.
```javascript
openapi: 3.1.0
info:
title: Val Town API
version: 1.0
paths:
'/v1/eval':
post:
x-codeSamples:
- label: ValTown JS SDK
lang: JavaScript
source: |-
import ValTown from '@valtown/sdk';
const valTown = new ValTown();
async function main() {
const valRunAnonymousResponse = await valTown.vals.runAnonymous({ code: 'console.log(1);' });
console.log(valRunAnonymousResponse);
}
main();
```
--------------------------------
### Install Microsoft.AspNetCore.OpenApi Package
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/net-aspnet-core/build-time-generation
Installs the necessary NuGet package for enabling OpenAPI document generation at build time in ASP.NET Core applications.
```shell
dotnet add package Microsoft.Extensions.ApiDescription.Server
```
--------------------------------
### Install Scalar.Aspire Package
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/net-aspire
Installs the Scalar.Aspire NuGet package using the .NET CLI. This package enables the integration of Scalar API Reference into .NET Aspire applications.
```shell
dotnet add package Scalar.Aspire
```
--------------------------------
### Create New Laravel Project
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/laravel-scribe
Creates a new Laravel project named 'my-new-app' using the Laravel installer. This is an optional step if you are starting a new project.
```bash
laravel new my-new-app
```
--------------------------------
### Add @scalar/docusaurus with pnpm
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/docusaurus
Installs the Scalar Docusaurus plugin using pnpm. This is an alternative to using npm for package installation.
```bash
pnpm add @scalar/docusaurus
```
--------------------------------
### Install Laravel Scribe
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/laravel-scribe
Installs the Laravel Scribe package as a development dependency using Composer. The `--with-all-dependencies` flag ensures all necessary packages are included.
```bash
composer require --dev --with-all-dependencies knuckleswtf/scribe
```
--------------------------------
### Install Adonis Autoswagger
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/adonisjs
Command to add the adonis-autoswagger package to an AdonisJS project, which is used for OpenAPI support.
```bash
npm add adonis-autoswagger
```
--------------------------------
### Scalar SDK Build
Source: https://guides.scalar.com/scalar/scalar-cli/commands
Creates an SDK build. Requires the SDK slug, namespace, and version.
```plaintext
Usage: scalar sdk build [options]
Create an SDK build.
Options:
-s, --slug SDK slug
-n, --namespace Team namespace
-v, --version SDK Version
-h, --help display help for command
```
--------------------------------
### Create New React Project with Vite
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/react
Demonstrates the command to create a new React project using Vite and pnpm, including selecting React as the framework and JavaScript as the variant.
```bash
pnpm create vite my-awesome-app
```
```bash
? Select a framework: › - Use arrow-keys. Return to submit.
Vanilla
Vue
❯ React
Preact
Lit
Svelte
Solid
Qwik
Others
```
```bash
? Select a variant: › - Use arrow-keys. Return to submit.
TypeScript
TypeScript + SWC
❯ JavaScript
JavaScript + SWC
Remix ↗
```
```bash
cd my-awesome-app
pnpm install
pnpm run dev
```
--------------------------------
### Docusaurus Configuration with Scalar (JS)
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/docusaurus
Example Docusaurus configuration file in JavaScript, integrating the Scalar API reference plugin. It specifies the plugin, label, route, and the URL for the OpenAPI document.
```typescript
// docusaurus.config.js
// …
const config = {
// …
plugins: [
[
'@scalar/docusaurus',
{
label: 'Scalar',
route: '/scalar',
configuration: {
// Put the URL to your OpenAPI document here:
url: 'https://registry.scalar.com/@scalar/apis/galaxy/latest?format=json',
},
},
],
],
}
```
--------------------------------
### Set up Fastify with Swagger
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/fastify
Configures a Fastify application to use the @fastify/swagger plugin. It includes registering the plugin, defining basic OpenAPI information, setting up security schemes, and adding an example route with schema definition. It also includes a route to serve the generated OpenAPI JSON.
```javascript
import FastifySwagger from '@fastify/swagger'
import Fastify from 'fastify'
// Instantiate the framework
const fastify = Fastify({
logger: true,
})
// Set up @fastify/swagger
await fastify.register(FastifySwagger, {
openapi: {
info: {
title: 'My Fastify App',
version: '1.0.0',
},
components: {
securitySchemes: {
apiKey: {
type: 'apiKey',
name: 'apiKey',
in: 'header',
},
},
},
},
})
fastify.put(
'/example-route/:id',
{
schema: {
description: 'post some data',
tags: ['user', 'code'],
summary: 'qwerty',
security: [{ apiKey: [] }],
params: {
type: 'object',
properties: {
id: {
type: 'string',
description: 'user id',
},
},
},
body: {
type: 'object',
properties: {
hello: { type: 'string' },
obj: {
type: 'object',
properties: {
some: { type: 'string' },
},
},
},
},
response: {
201: {
description: 'Successful response',
type: 'object',
properties: {
hello: { type: 'string' },
},
},
default: {
description: 'Default response',
type: 'object',
properties: {
foo: { type: 'string' },
},
},
},
},
},
(req, reply) => {
reply.code(201).send({ hello: `Hello ${req.body.hello}` })
},
)
// Serve an OpenAPI file
fastify.get('/openapi.json', async (request, reply) => {
return fastify.swagger()
})
// Wait for Fastify
await fastify.ready()
// Run the server
fastify.listen({ port: 3000 }, function (err, address) {
if (err) {
fastify.log.error(err)
process.exit(1)
}
console.log(`Fastify is now listening on ${address}`)
})
```
--------------------------------
### Basic HTML Setup for Scalar API Reference
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/htmljs
This HTML snippet demonstrates the simplest way to integrate the Scalar API Reference into a web page. It includes the necessary meta tags, a div for mounting, and loads the Scalar API Reference script from a CDN, initializing it with a sample OpenAPI URL.
```html
Scalar API Reference
```
--------------------------------
### Basic Scalar Configuration
Source: https://guides.scalar.com/scalar/scalar-docs/github-sync
This JSON configuration sets up the basic structure for your Scalar documentation, including a subdomain and a guide with a single page.
```json
{
"$schema": "https://cdn.scalar.com/schema/scalar-config.json",
"subdomain": "my-awesome-documentation",
"guides": [
{
"name": "My awesome documentation",
"sidebar": [
{
"path": "docs/introduction.md",
"type": "page"
}
]
}
],
"references": []
}
```
--------------------------------
### Docusaurus Configuration with Scalar (TypeScript)
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/docusaurus
Example Docusaurus configuration file in TypeScript, integrating the Scalar API reference plugin. It includes type imports for Docusaurus configuration and Scalar options, specifying the plugin, label, route, and OpenAPI document URL.
```typescript
// docusaurus.config.ts
import type { Config } from '@docusaurus/types'
import type { ScalarOptions } from '@scalar/docusaurus'
// …
const config: Config = {
// …
plugins: [
[
'@scalar/docusaurus',
{
label: 'Scalar',
route: '/scalar',
configuration: {
// Put the URL to your OpenAPI document here:
url: 'https://registry.scalar.com/@scalar/apis/galaxy/latest?format=json',
},
} as ScalarOptions,
],
],
}
```
--------------------------------
### Embed Scalar API Reference in HTML
Source: https://guides.scalar.com/scalar/scalar-api-references/getting-started
This snippet demonstrates how to include the Scalar API Reference in an HTML page. It loads the Scalar JavaScript library from a CDN and initializes the API reference component with a specified DOM element and configuration, including the OpenAPI document URL and a proxy URL.
```html
Scalar API Reference
```
--------------------------------
### Run Django Development Server
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/django-ninja
Commands to navigate to the Django project directory and start the development server.
```bash
cd apidemo
./manage.py runserver
```
--------------------------------
### Install Scalar.AspNetCore.Swashbuckle
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/net-aspnet-core/openapi-extensions
Installs the Scalar package for Swashbuckle.AspNetCore.SwaggerGen to enable OpenAPI extensions.
```shell
dotnet add package Scalar.AspNetCore.Swashbuckle
```
--------------------------------
### Install Scalar.AspNetCore.Microsoft
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/net-aspnet-core/openapi-extensions
Installs the Scalar package for Microsoft.AspNetCore.OpenApi to enable OpenAPI extensions.
```shell
dotnet add package Scalar.AspNetCore.Microsoft
```
--------------------------------
### Scalar Project Management
Source: https://guides.scalar.com/scalar/scalar-cli/commands
Manages Scalar projects, including initialization, configuration checking, project creation, previewing, and publishing. This is the main entry point for project-related operations.
```plaintext
Usage: scalar project [options] [command]
Manage scalar project
Options:
-h, --help display help for command
Commands:
init [options] Create a new `scalar.config.json` file to
configure where your OpenAPI file is placed.
check-config [file] Check a Scalar Configuration file
create [options] Create a new project that is not linked to a
github project.
preview [options] [config] Preview scalar guides
publish [options] Publish new build for a github sync project that
is not linked.
help [command] display help for command
```
--------------------------------
### Static Scalar Step Example (Markdown)
Source: https://guides.scalar.com/scalar/scalar-docs/components/steps
Demonstrates a static (non-collapsible) scalar-step in Markdown, including a JavaScript code snippet for configuration.
```markdown
::scalar-step{ id="step-2" title="Configuration" interactivity="none" }
This step cannot be collapsed and is always visible.
```javascript
const config = {
theme: 'dark',
interactive: false,
}
```
:::
```
--------------------------------
### Build Scalar API Reference Docker Image from Source
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/docker
Clones the Scalar repository, navigates to the Docker integration directory, and builds the Docker image for Scalar API Reference using the provided Dockerfile.
```bash
# Clone the repository
git clone https://github.com/scalar/scalar.git
cd scalar/integrations/docker
# Build the Docker image
docker build -t scalarapi/api-reference:latest .
```
--------------------------------
### Install OpenAPI to Markdown Converter
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/hono
Installs the @scalar/openapi-to-markdown package, used for generating Markdown versions of API references for LLMs.
```bash
npm install @scalar/openapi-to-markdown
```
--------------------------------
### Scalar Schema CLI Overview
Source: https://guides.scalar.com/scalar/scalar-cli/commands
Provides an overview of the Scalar schema management commands. It lists available subcommands for interacting with schemas.
```bash
Usage: scalar schema [options] [command]
Manage your Scalar schemas
Options:
-h, --help display help for command
Commands:
delete [options] Delete a schema.
update [options] Update schema metadata.
list [options] List all schemas for a team namespace
publish [options] [file] Publish a shared schema to the Scalar registry
help [command] display help for command
```
--------------------------------
### Scalar SDK List
Source: https://guides.scalar.com/scalar/scalar-cli/commands
Lists all SDKs for a given team namespace. Requires the namespace.
```plaintext
Usage: scalar sdk list [options]
List all SDKs for a team namespace
Options:
--namespace Team namespace
-h, --help display help for command
```
--------------------------------
### Scalar SDK Create
Source: https://guides.scalar.com/scalar/scalar-cli/commands
Creates a new SDK. Requires the registry API slug, team namespace, and the desired language for the SDK.
```plaintext
Usage: scalar sdk create [options]
Create a new SDK.
Options:
-a, --api Registry API slug
-n, --namespace Team namespace
-l, --language Language of your SDK (choices: "typescript",
"python", "csharp", "java", "ruby", "php", "go")
-h, --help display help for command
```
--------------------------------
### Scalar Configuration Options
Source: https://guides.scalar.com/scalar/scalar-api-references/integrations/net-aspnet-core/integration
Demonstrates various configuration options for Scalar, including title, sidebar visibility, dark mode, and default open states.
```csharp
app.MapScalarApiReference(options =>
{
options.WithTitle("My API")
.WithSidebar(false)
.WithDarkMode(true)
.WithDefaultOpenAllTags(true);
});
```