npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@scalar/api-reference

v1.22.42

Published

generate beautiful API references from OpenAPI specs

Downloads

49,367

Readme

Scalar API Reference

Version Downloads Hits on jsdelivr License Discord

Generate interactive API documentations from Swagger files. Try our Demo

Screenshot of an API Reference

Installation

npm install @scalar/api-reference

Usage

<script setup>
import { ApiReference } from '@scalar/api-reference'
</script>

<template>
  <ApiReference />
</template>

You can even mount the component in React.

OpenAPI Specification

We’re expecting the passed specification to adhere to the Swagger 2.0, OpenAPI 3.0 or OpenAPI 3.1 specification.

On top of that, we’ve added a few things for your convenience:

x-displayName

You can overwrite tag names with x-displayName.

openapi: 3.1.0
info:
  title: Example
  version: "1.0"
tags:
  - name: pl4n3t5
+    x-displayName: planets
paths:
  '/planets':
    get:
      summary: Get all planets
      tags:
        - pl4n3t5

x-tagGroup

You can group your tags with x-tagGroup.

openapi: 3.1.0
info:
  title: Example
  version: "1.0"
tags:
  - name: planets
+x-tagGroups:
+  - name: galaxy
+    tags:
+      - planets
paths:
  '/planets':
    get:
      summary: Get all planets
      tags:
        - planets

x-internal

You can hide operations from the reference with x-internal.

openapi: 3.1.0
info:
  title: Example
  version: "1.0"
paths:
  '/planets':
    get:
      summary: Get all planets
    post:
      summary: Create a new planet
+      x-internal: true

Configuration

There’s a configuration object that can be used on all platforms. In Vue.js, you use it like this:

isEditable?: boolean

Whether the Swagger editor should be shown.

<ApiReference :configuration="{ isEditable: true }" />

spec.content?: string

Directly pass an OpenAPI/Swagger spec.

<ApiReference :configuration="{ spec: { content: '{ … }' } }" />

spec.url?: string

Pass the URL of a spec file (JSON or Yaml).

<ApiReference :configuration="{ spec: { url: '/openapi.json' } }" />

proxyUrl?: string

Making requests to other domains is restricted in the browser and requires CORS headers. It’s recommended to use a proxy to send requests to other origins.

<ApiReference :configuration="{ proxy: 'https://proxy.example.com' }" />

ℹ️ You can use @scalar/api-client-proxy to host your own proxy or you can just use ours:

<ApiReference
  :configuration="{ proxy: 'https://api.scalar.com/request-proxy' }" />

showSidebar?: boolean

Whether the sidebar should be shown.

<ApiReference :configuration="{ showSidebar: true } />

hideModels?: boolean

Whether models (components.schemas or definitions) should be shown in the sidebar, search and content.

@default false

<ApiReference :configuration="{ hideModels: true } />

hideDownloadButton?: boolean

Whether to show the "Download OpenAPI Specification" button

@default false

<ApiReference :configuration="{ hideDownloadButton: true } />

customCss?: string

You can pass custom CSS directly to the component. This is helpful for the integrations for Fastify, Express, Hono and others where you it’s easier to add CSS to the configuration.

In Vue or React you’d probably use other ways to add custom CSS.

<script setup>
const customCss = `* { font-family: "Comic Sans MS", cursive, sans-serif; }`
</script>

<template>
  <ApiReference :configuration="{ customCss }" />
</template>

searchHotKey?: string

Key used with CTRL/CMD to open the search modal (defaults to 'k' e.g. CMD+k)

<ApiReference :configuration="{ searchHotKey: 'l'} />

metaData?: object

You can pass information to the config object to configure meta information out of the box.

<ApiReference :configuration="{
  metaData: {
        title: 'Page title',
        description: 'My page page',
        ogDescription: 'Still about my my page',
        ogTitle: 'Page title',
        ogImage: 'https://example.com/image.png',
        twitterCard: 'summary_large_image',
        //Add more...
      }
  } />

hiddenClients?: array

You can pass an array of httpsnippet clients to hide from the clients menu.

<ApiReference :configuration="{
  hiddenClients: ['fetch']
  } />

By default hides Unirest, pass [] to show all clients

onSpecUpdate?: (spec: string) => void

You can listen to spec changes with onSpecUpdate that runs on spec/swagger content change

<ApiReference :configuration="{
    onSpecUpdate: (value: string) => {
      console.log('Content updated:', value)
    }
  } />

authentication?: Partial

To make authentication easier you can prefill the credentials for your users:

<ApiReference :configuration="{
  authentication: {
      // The OpenAPI file has keys for all security schemes:
      // Which one should be used by default?
      preferredSecurityScheme: 'my_custom_security_scheme',
      // The `my_custom_security_scheme` security scheme is of type `apiKey`, so prefill the token:
      apiKey: {
        token: 'super-secret-token',
      },
    },
  } />

For OpenAuth2 it’s more looking like this:

<ApiReference :configuration="{
  authentication: {
      // The OpenAPI file has keys for all security schemes
      // Which one should be used by default?
      preferredSecurityScheme: 'oauth2',
      // The `oauth2` security scheme is of type `oAuth2`, so prefill the client id and the scopes:
      oAuth2: {
        clientId: 'foobar123',
        // optional:
        scopes: ['read:planets', 'write:planets'],
      },
    },
  } />

withDefaultFonts?: boolean

By default we’re using Inter and JetBrains Mono, served by Google Fonts. If you use a different font or just don’t want to use Google Fonts, pass withDefaultFonts: false to the configuration.

<ApiReference :configuration="{
  withDefaultFonts: false
} />