elements
Build beautiful, interactive API Docs with embeddable React or Web Components, powered by OpenAPI and Markdown.
Top Related Projects
Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
📘 OpenAPI/Swagger-generated API Reference Documentation
RESTful web API Documentation Generator.
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
API Blueprint
GUI / visual editor for creating and editing OpenAPI / Swagger definitions
Quick Overview
Stoplight Elements is an open-source library that provides customizable API documentation components. It allows developers to create interactive API reference documentation using React components, supporting OpenAPI 3.0 and 3.1 specifications. The library aims to simplify the process of generating and maintaining API documentation.
Pros
- Easy integration with React applications
- Supports both OpenAPI 3.0 and 3.1 specifications
- Customizable components for flexible documentation layouts
- Active development and community support
Cons
- Limited to React-based projects
- May require additional setup for non-React environments
- Learning curve for customizing advanced features
- Documentation could be more comprehensive for complex use cases
Code Examples
- Basic API documentation component:
import { API } from '@stoplight/elements';
function ApiDocs() {
return (
<API
apiDescriptionUrl="https://api.example.com/openapi.yaml"
router="hash"
/>
);
}
- Customizing the layout with specific components:
import { APIExplorer, APINavigation, APIEndpoint } from '@stoplight/elements';
function CustomApiDocs() {
return (
<div>
<APINavigation apiDescriptionUrl="https://api.example.com/openapi.yaml" />
<APIExplorer apiDescriptionUrl="https://api.example.com/openapi.yaml">
<APIEndpoint />
</APIExplorer>
</div>
);
}
- Using the TryIt component for interactive API requests:
import { TryIt } from '@stoplight/elements';
function ApiTester() {
return (
<TryIt
apiDescriptionUrl="https://api.example.com/openapi.yaml"
operationId="getUserProfile"
/>
);
}
Getting Started
To start using Stoplight Elements in your React project:
- Install the package:
npm install @stoplight/elements
- Import and use the components in your React application:
import React from 'react';
import { API } from '@stoplight/elements';
import '@stoplight/elements/styles.min.css';
function App() {
return (
<div className="App">
<API
apiDescriptionUrl="https://api.example.com/openapi.yaml"
router="hash"
/>
</div>
);
}
export default App;
Make sure to include the CSS file for proper styling. You can now customize and extend the components as needed for your API documentation.
Competitor Comparisons
Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
Pros of Swagger UI
- Widely adopted and well-established in the API documentation ecosystem
- Extensive customization options and theming capabilities
- Strong community support and regular updates
Cons of Swagger UI
- Steeper learning curve for advanced customizations
- Can be resource-intensive for large API specifications
- Limited built-in interactivity features compared to Elements
Code Comparison
Swagger UI (basic setup):
import SwaggerUI from 'swagger-ui'
import 'swagger-ui/dist/swagger-ui.css'
SwaggerUI({
dom_id: '#swagger-ui',
url: 'https://petstore.swagger.io/v2/swagger.json'
})
Elements (basic setup):
import { API } from '@stoplight/elements'
import '@stoplight/elements/styles.min.css'
<API
apiDescriptionUrl="https://api.apis.guru/v2/specs/github.com/1.1.4/openapi.yaml"
router="hash"
/>
Key Differences
- Elements offers a more modern and streamlined UI out of the box
- Swagger UI provides more granular control over the documentation layout
- Elements includes built-in features like API mocking and try-it functionality
- Swagger UI has a larger ecosystem of third-party extensions and plugins
Both tools are excellent choices for API documentation, with Swagger UI being more established and customizable, while Elements offers a more modern and user-friendly experience with less setup required.
📘 OpenAPI/Swagger-generated API Reference Documentation
Pros of Redoc
- More customizable theming options
- Better support for complex OpenAPI schemas
- Offers a standalone HTML bundle for easy deployment
Cons of Redoc
- Slower rendering for large API specifications
- Less frequent updates and maintenance
- Limited interactive features compared to Elements
Code Comparison
Redoc
<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>
<redoc spec-url="https://api.example.com/openapi.json"></redoc>
Elements
<script src="https://unpkg.com/@stoplight/elements/web-components.min.js"></script>
<elements-api
apiDescriptionUrl="https://api.example.com/openapi.json"
router="hash"
></elements-api>
Both Redoc and Elements are popular tools for rendering OpenAPI documentation. Redoc excels in customization and handling complex schemas, while Elements offers better performance and more frequent updates. Redoc's standalone bundle makes it easier to deploy, but Elements provides more interactive features. The code snippets show that both can be easily integrated into web pages, with Elements using web components and Redoc using a more traditional approach.
RESTful web API Documentation Generator.
Pros of apiDoc
- Simpler setup and usage, especially for projects without OpenAPI/Swagger specs
- Generates documentation directly from code comments, reducing maintenance overhead
- Supports multiple programming languages and frameworks out-of-the-box
Cons of apiDoc
- Less interactive and visually appealing documentation output
- Limited customization options for the generated documentation
- Lacks built-in API mocking and testing features
Code Comparison
apiDoc example:
/**
* @api {get} /user/:id Request User information
* @apiName GetUser
* @apiGroup User
*
* @apiParam {Number} id Users unique ID.
*/
Elements example (using OpenAPI):
/user/{id}:
get:
summary: Request User information
parameters:
- name: id
in: path
required: true
schema:
type: integer
Elements focuses on rendering OpenAPI/Swagger specifications, offering a more modern and interactive documentation experience. It provides features like API mocking and testing, making it suitable for larger projects with existing API specs. apiDoc, on the other hand, is more straightforward and can generate documentation directly from code comments, making it easier to set up for smaller projects or those without formal API specifications.
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
Pros of openapi-generator
- Supports a wide range of programming languages and frameworks
- Generates complete client libraries, server stubs, and documentation
- Highly customizable with templates and configuration options
Cons of openapi-generator
- Steeper learning curve due to its extensive features and options
- May generate more code than necessary for simple use cases
- Requires additional setup and configuration for each project
Code Comparison
elements:
import { API } from '@stoplight/elements';
<API
apiDescriptionUrl="https://api.example.com/openapi.yaml"
router="hash"
/>
openapi-generator:
openapi-generator generate -i openapi.yaml -g javascript -o ./generated
Key Differences
elements is a React-based UI component library for rendering API documentation, while openapi-generator is a powerful code generation tool for creating client SDKs, server stubs, and documentation across multiple languages.
elements focuses on providing a user-friendly, interactive API documentation experience, while openapi-generator emphasizes code generation for various parts of the API ecosystem.
elements is more suitable for quickly creating API documentation portals, whereas openapi-generator is better suited for generating comprehensive API-related code across multiple languages and frameworks.
API Blueprint
Pros of API Blueprint
- Simpler, more human-readable syntax for API documentation
- Widely adopted and supported by various tools and services
- Focuses on design-first approach, encouraging better API planning
Cons of API Blueprint
- Less flexible for complex API structures
- Limited built-in validation capabilities
- Requires additional tools for rendering and testing
Code Comparison
API Blueprint:
# GET /users/{id}
+ Parameters
+ id: 1 (number, required) - User ID
+ Response 200 (application/json)
+ Body
{
"id": 1,
"name": "John Doe"
}
Elements (OpenAPI):
/users/{id}:
get:
parameters:
- name: id
in: path
required: true
schema:
type: integer
responses:
'200':
content:
application/json:
schema:
type: object
properties:
id:
type: integer
name:
type: string
Elements provides a more structured and detailed API definition, while API Blueprint offers a more concise and readable format. Elements supports a wider range of API specifications and offers more advanced features for API documentation and testing, making it more suitable for complex projects. API Blueprint, on the other hand, excels in simplicity and ease of use, making it ideal for rapid prototyping and smaller projects.
GUI / visual editor for creating and editing OpenAPI / Swagger definitions
Pros of openapi-gui
- Lightweight and simple interface for editing OpenAPI specifications
- Supports both YAML and JSON formats
- Provides a live preview of the API documentation
Cons of openapi-gui
- Less feature-rich compared to Elements
- Limited customization options for the generated documentation
- Lacks advanced validation and linting capabilities
Code Comparison
Elements:
import { API } from '@stoplight/elements';
function MyAPI() {
return <API apiDescriptionUrl="https://api.example.com/openapi.yaml" />;
}
openapi-gui:
<div id="editor"></div>
<script>
const editor = new OpenAPIEditor('#editor', {
spec: 'https://api.example.com/openapi.yaml'
});
</script>
Elements offers a React component for rendering API documentation, while openapi-gui provides a more traditional JavaScript-based approach for embedding the editor. Elements has a more modern and flexible integration method, making it easier to incorporate into React-based applications.
Both projects aim to simplify working with OpenAPI specifications, but Elements offers a more comprehensive set of features and better integration options for modern web development workflows. openapi-gui, on the other hand, provides a simpler and more lightweight solution for basic OpenAPI editing and visualization needs.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Beautiful API documentation powered by OpenAPI and Markdown. Use these UI components to create API reference documentation, or more complete documentation with Markdown articles covering tutorials, how-to guides, etc.
Available as React Components, or Web Components, you can use Elements all together to build beautiful three-column "Stripe-esque" documentation, or stacked documentation thats easier for integrating into existing Content Management Systems with their own navigation.
Overview
ð Community
Let's chat about features, ideas, what you're doing with Elements, on GitHub Discussions.
ðï¸ð¨ ï¸ï¸Examples
Stoplight Elements comes with a few example integration projects, showing you how to utilize Elements with different frameworks.
- react-cra - An example app built using Create React App utilizing Stoplight Elements.
- angular - An angular app utilizing the Web Components distribution of Elements.
- bootstrap - A single HTML page utilizing the Web Components distribution via a global script tag.
To run these examples yourself:
- Clone this repo.
- Go to
examples
folder and open an example, e.g.:examples/angular
. - Run
yarn
to install all dependencies. - Run
yarn start
to run the example.
Note: for bootstrap example just go straight to its directory and open the HTML file.
ð Usage
The examples will hopefully help show Elements working in close to real world situations, but the most bare bones examples of Elements can be found below.
React Component
$ npm install @stoplight/elements
import { API } from "@stoplight/elements";
<API
apiDescriptionUrl="https://api.apis.guru/v2/specs/github.com/1.1.4/openapi.yaml"
router="history"
/>
For more information on using Elements as a React component, head over to our React documentation.
Web Component
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Elements in HTML</title>
<!-- Embed elements Elements via Web Component -->
<script src="https://unpkg.com/@stoplight/elements/web-components.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@stoplight/elements/styles.min.css">
</head>
<body>
<elements-api
apiDescriptionUrl="https://api.apis.guru/v2/specs/github.com/1.1.4/openapi.yaml"
router="hash"
layout="sidebar"
/>
</body>
</html>
Load this page up in your browser and you should see the GitHub REST API documented in Stoplight Elements.
For more information on using Elements as a Web Component, head over to our Web Component documentation.
ð§ Roadmap
- API Console (a.k.a "Try it!")
- Automatic Code Samples
- Automatic Examples
- React & Web Component Support
- OpenAPI Support
- OpenAPI v3.1
- OpenAPI v3.0
- OpenAPI v2.0
- Callbacks
- Webhooks
- Multiple APIs (a.k.a "Dev Portal")
Submit your ideas for new functionality on the Stoplight Roadmap.
âï¸ Integrations
- Stoplight Studio - Free visual OpenAPI designer that uses Elements to preview your API descriptions on the fly.
- Stoplight Platform - Collaborative API Design Platform for designing, developing and documenting APIs with hosted documentation powered by Elements.
- LaravelPHP Elements - A simple API documentation package for Laravel using OpenAPI and Stoplight Elements.
ð Help Others Utilize Elements
If you're using Elements for an interesting use case, contact us for a case study. We'll add it to a list here. Spread the goodness ð
ð Contributing
If you are interested in contributing to Elements itself, check out our contributing docs â and code of conduct â to get started.
ð Thanks
Elements is built on top of lots of excellent packages, and here are a few we'd like to say a special thanks to.
- httpsnippet by Kong.
- openapi-sampler by ReDocly.
Check these projects out!
ð² Sponsor Elements by Planting a Tree
If you would like to thank us for creating Elements, we ask that you buy the world a tree.
Top Related Projects
Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
📘 OpenAPI/Swagger-generated API Reference Documentation
RESTful web API Documentation Generator.
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
API Blueprint
GUI / visual editor for creating and editing OpenAPI / Swagger definitions
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot