WIP
This commit is contained in:
446
docs/_book/customization/custom-layout.html
Normal file
446
docs/_book/customization/custom-layout.html
Normal file
@@ -0,0 +1,446 @@
|
||||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Creating a custom layout · Swagger-UI</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="description" content="">
|
||||
<meta name="generator" content="GitBook 3.2.3">
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/style.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="HandheldFriendly" content="true"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
|
||||
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
|
||||
|
||||
|
||||
<link rel="next" href="plugin-api.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="overview.html" />
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="book">
|
||||
<div class="book-summary">
|
||||
|
||||
|
||||
<div id="book-search-input" role="search">
|
||||
<input type="text" placeholder="Type to search" />
|
||||
</div>
|
||||
|
||||
|
||||
<nav role="navigation">
|
||||
|
||||
|
||||
|
||||
<ul class="summary">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.1" data-path="../">
|
||||
|
||||
<a href="../">
|
||||
|
||||
|
||||
Intro
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="header">Usage</li>
|
||||
|
||||
|
||||
|
||||
<li class="chapter " data-level="2.1" data-path="../usage/installation.html">
|
||||
|
||||
<a href="../usage/installation.html">
|
||||
|
||||
|
||||
Installation
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="2.2" data-path="../usage/configuration.html">
|
||||
|
||||
<a href="../usage/configuration.html">
|
||||
|
||||
|
||||
Configuration
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="2.2.1" data-path="../usage/deep-linking.html">
|
||||
|
||||
<a href="../usage/deep-linking.html">
|
||||
|
||||
|
||||
deepLinking
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="2.3" data-path="../usage/version-detection.html">
|
||||
|
||||
<a href="../usage/version-detection.html">
|
||||
|
||||
|
||||
Version detection
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="header">Customization</li>
|
||||
|
||||
|
||||
|
||||
<li class="chapter " data-level="3.1" data-path="overview.html">
|
||||
|
||||
<a href="overview.html">
|
||||
|
||||
|
||||
Overview
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter active" data-level="3.2" data-path="custom-layout.html">
|
||||
|
||||
<a href="custom-layout.html">
|
||||
|
||||
|
||||
Creating a custom layout
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="3.3" data-path="plugin-api.html">
|
||||
|
||||
<a href="plugin-api.html">
|
||||
|
||||
|
||||
Plugin API
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="header">Development</li>
|
||||
|
||||
|
||||
|
||||
<li class="chapter " data-level="4.1" data-path="../development/setting-up.html">
|
||||
|
||||
<a href="../development/setting-up.html">
|
||||
|
||||
|
||||
Setting up a dev environment
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="divider"></li>
|
||||
|
||||
<li>
|
||||
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
|
||||
Published with GitBook
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
</nav>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="book-body">
|
||||
|
||||
<div class="body-inner">
|
||||
|
||||
|
||||
|
||||
<div class="book-header" role="navigation">
|
||||
|
||||
|
||||
<!-- Title -->
|
||||
<h1>
|
||||
<i class="fa fa-circle-o-notch fa-spin"></i>
|
||||
<a href=".." >Creating a custom layout</a>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="page-wrapper" tabindex="-1" role="main">
|
||||
<div class="page-inner">
|
||||
|
||||
<div id="book-search-results">
|
||||
<div class="search-noresults">
|
||||
|
||||
<section class="normal markdown-section">
|
||||
|
||||
<h1 id="creating-a-custom-layout">Creating a custom layout</h1>
|
||||
<p><strong>Layouts</strong> are a special type of component that Swagger-UI uses as the root component for the entire application. You can define custom layouts in order to have high-level control over what ends up on the page.</p>
|
||||
<p>By default, Swagger-UI uses <code>BaseLayout</code>, which is built into the application. You can specify a different layout to be used by passing the layout's name as the <code>layout</code> parameter to Swagger-UI. Be sure to provide your custom layout as a component to Swagger-UI.</p>
|
||||
<p><br></p>
|
||||
<p>For example, if you wanted to create a custom layout that only displayed operations, you could define an <code>OperationsLayout</code>:</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>
|
||||
|
||||
<span class="hljs-comment">// Create the layout component</span>
|
||||
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">OperationsLayout</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">React</span>.<span class="hljs-title">Component</span> </span>{
|
||||
render() {
|
||||
<span class="hljs-keyword">const</span> {
|
||||
getComponent
|
||||
} = <span class="hljs-keyword">this</span>.props
|
||||
|
||||
<span class="hljs-keyword">const</span> Operations = getComponent(<span class="hljs-string">"Operations"</span>, <span class="hljs-literal">true</span>)
|
||||
|
||||
<span class="hljs-keyword">return</span> {
|
||||
<span class="xml"><span class="hljs-tag"><<span class="hljs-name">div</span>></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">Operations</span> /></span>
|
||||
<span class="hljs-tag"></<span class="hljs-name">div</span>></span>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create the plugin that provides our layout component
|
||||
const OperationsLayoutPlugin = function() {
|
||||
return {
|
||||
components: {
|
||||
OperationsLayout: OperationsLayout
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Provide the plugin to Swagger-UI, and select OperationsLayout
|
||||
// as the layout for Swagger-UI
|
||||
SwaggerUI({
|
||||
url: "http://petstore.swagger.io/v2/swagger.json",
|
||||
plugins: [ OperationsLayoutPlugin ],
|
||||
layout: "OperationsLayout"
|
||||
})
|
||||
</span></code></pre>
|
||||
<h3 id="augmenting-the-default-layout">Augmenting the default layout</h3>
|
||||
<p>If you'd like to build around the <code>BaseLayout</code> instead of replacing it, you can pull the <code>BaseLayout</code> into your custom layout and use it:</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>
|
||||
|
||||
<span class="hljs-comment">// Create the layout component</span>
|
||||
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AugmentingLayout</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">React</span>.<span class="hljs-title">Component</span> </span>{
|
||||
render() {
|
||||
<span class="hljs-keyword">const</span> {
|
||||
getComponent
|
||||
} = <span class="hljs-keyword">this</span>.props
|
||||
|
||||
<span class="hljs-keyword">const</span> BaseLayout = getComponent(<span class="hljs-string">"BaseLayout"</span>, <span class="hljs-literal">true</span>)
|
||||
|
||||
<span class="hljs-keyword">return</span> {
|
||||
<span class="xml"><span class="hljs-tag"><<span class="hljs-name">div</span>></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"myCustomHeader"</span>></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">h1</span>></span>I have a custom header above Swagger-UI!<span class="hljs-tag"></<span class="hljs-name">h1</span>></span>
|
||||
<span class="hljs-tag"></<span class="hljs-name">div</span>></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">BaseLayout</span> /></span>
|
||||
<span class="hljs-tag"></<span class="hljs-name">div</span>></span>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create the plugin that provides our layout component
|
||||
const AugmentingLayoutPlugin = function() {
|
||||
return {
|
||||
components: {
|
||||
AugmentingLayout: AugmentingLayout
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Provide the plugin to Swagger-UI, and select AugmentingLayout
|
||||
// as the layout for Swagger-UI
|
||||
SwaggerUI({
|
||||
url: "http://petstore.swagger.io/v2/swagger.json",
|
||||
plugins: [ AugmentingLayoutPlugin ],
|
||||
layout: "AugmentingLayout"
|
||||
})
|
||||
</span></code></pre>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
</div>
|
||||
<div class="search-results">
|
||||
<div class="has-results">
|
||||
|
||||
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
|
||||
<ul class="search-results-list"></ul>
|
||||
|
||||
</div>
|
||||
<div class="no-results">
|
||||
|
||||
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<a href="overview.html" class="navigation navigation-prev " aria-label="Previous page: Overview">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="plugin-api.html" class="navigation navigation-next " aria-label="Next page: Plugin API">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Creating a custom layout","level":"3.2","depth":1,"next":{"title":"Plugin API","level":"3.3","depth":1,"path":"customization/plugin-api.md","ref":"customization/plugin-api.md","articles":[]},"previous":{"title":"Overview","level":"3.1","depth":1,"path":"customization/overview.md","ref":"customization/overview.md","articles":[]},"dir":"ltr"},"config":{"plugins":["livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Swagger-UI","gitbook":"*"},"file":{"path":"customization/custom-layout.md","mtime":"2017-11-01T00:00:09.663Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-11-01T03:42:59.286Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook.js"></script>
|
||||
<script src="../gitbook/theme.js"></script>
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
413
docs/_book/customization/overview.html
Normal file
413
docs/_book/customization/overview.html
Normal file
@@ -0,0 +1,413 @@
|
||||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Overview · Swagger-UI</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="description" content="">
|
||||
<meta name="generator" content="GitBook 3.2.3">
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/style.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="HandheldFriendly" content="true"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
|
||||
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
|
||||
|
||||
|
||||
<link rel="next" href="custom-layout.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="../usage/version-detection.html" />
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="book">
|
||||
<div class="book-summary">
|
||||
|
||||
|
||||
<div id="book-search-input" role="search">
|
||||
<input type="text" placeholder="Type to search" />
|
||||
</div>
|
||||
|
||||
|
||||
<nav role="navigation">
|
||||
|
||||
|
||||
|
||||
<ul class="summary">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.1" data-path="../">
|
||||
|
||||
<a href="../">
|
||||
|
||||
|
||||
Intro
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="header">Usage</li>
|
||||
|
||||
|
||||
|
||||
<li class="chapter " data-level="2.1" data-path="../usage/installation.html">
|
||||
|
||||
<a href="../usage/installation.html">
|
||||
|
||||
|
||||
Installation
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="2.2" data-path="../usage/configuration.html">
|
||||
|
||||
<a href="../usage/configuration.html">
|
||||
|
||||
|
||||
Configuration
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="2.2.1" data-path="../usage/deep-linking.html">
|
||||
|
||||
<a href="../usage/deep-linking.html">
|
||||
|
||||
|
||||
deepLinking
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="2.3" data-path="../usage/version-detection.html">
|
||||
|
||||
<a href="../usage/version-detection.html">
|
||||
|
||||
|
||||
Version detection
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="header">Customization</li>
|
||||
|
||||
|
||||
|
||||
<li class="chapter active" data-level="3.1" data-path="overview.html">
|
||||
|
||||
<a href="overview.html">
|
||||
|
||||
|
||||
Overview
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="3.2" data-path="custom-layout.html">
|
||||
|
||||
<a href="custom-layout.html">
|
||||
|
||||
|
||||
Creating a custom layout
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="3.3" data-path="plugin-api.html">
|
||||
|
||||
<a href="plugin-api.html">
|
||||
|
||||
|
||||
Plugin API
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="header">Development</li>
|
||||
|
||||
|
||||
|
||||
<li class="chapter " data-level="4.1" data-path="../development/setting-up.html">
|
||||
|
||||
<a href="../development/setting-up.html">
|
||||
|
||||
|
||||
Setting up a dev environment
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="divider"></li>
|
||||
|
||||
<li>
|
||||
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
|
||||
Published with GitBook
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
</nav>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="book-body">
|
||||
|
||||
<div class="body-inner">
|
||||
|
||||
|
||||
|
||||
<div class="book-header" role="navigation">
|
||||
|
||||
|
||||
<!-- Title -->
|
||||
<h1>
|
||||
<i class="fa fa-circle-o-notch fa-spin"></i>
|
||||
<a href=".." >Overview</a>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="page-wrapper" tabindex="-1" role="main">
|
||||
<div class="page-inner">
|
||||
|
||||
<div id="book-search-results">
|
||||
<div class="search-noresults">
|
||||
|
||||
<section class="normal markdown-section">
|
||||
|
||||
<h1 id="plugin-system-overview">Plugin system overview</h1>
|
||||
<h3 id="prior-art">Prior art</h3>
|
||||
<p>Swagger-UI leans heavily on concepts and patterns found in React and Redux.</p>
|
||||
<p>If you aren't already familiar, here's some suggested reading:</p>
|
||||
<ul>
|
||||
<li><a href="https://reactjs.org/docs/hello-world.html" target="_blank">React: Quick Start (reactjs.org)</a></li>
|
||||
<li><a href="http://redux.js.org/" target="_blank">Redux README (redux.js.org)</a></li>
|
||||
</ul>
|
||||
<p>In the following documentation, we won't take the time to define the fundamentals covered in the resources above.</p>
|
||||
<blockquote>
|
||||
<p><strong>Note</strong>: Some of the examples in this section contain JSX, which is a syntax extension to JavaScript that is useful for writing React components.</p>
|
||||
<p>If you don't want to set up a build pipeline capable of translating JSX to JavaScript, take a look at <a href="https://reactjs.org/docs/react-without-jsx.html" target="_blank">React without JSX (reactjs.org)</a>.</p>
|
||||
</blockquote>
|
||||
<h3 id="the-system">The System</h3>
|
||||
<p>The <em>system</em> is the heart of the Swagger-UI application. At runtime, it's a JavaScript object that holds many things:</p>
|
||||
<ul>
|
||||
<li>React components</li>
|
||||
<li>Bound Redux actions and reducers</li>
|
||||
<li>Bound Reselect state selectors</li>
|
||||
<li>System-wide collection of available components</li>
|
||||
<li>Built-in helpers like <code>getComponent</code>, <code>makeMappedContainer</code>, and <code>getStore</code></li>
|
||||
<li>User-defined helper functions</li>
|
||||
</ul>
|
||||
<p>The system is built up when Swagger-UI is called by iterating through ("compiling") each plugin that Swagger-UI has been given, through the <code>presets</code> and <code>plugins</code> configuration options.</p>
|
||||
<h3 id="presets">Presets</h3>
|
||||
<p>Presets are arrays of plugins, which are provided to Swagger-UI through the <code>presets</code> configuration option. All plugins within presets are compiled before any plugins provided via the <code>plugins</code> configuration option. Consider the following example:</p>
|
||||
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> MyPreset = [FirstPlugin, SecondPlugin, ThirdPlugin]
|
||||
|
||||
SwaggerUI({
|
||||
presets: [
|
||||
MyPreset
|
||||
]
|
||||
})
|
||||
</code></pre>
|
||||
<p>By default, Swagger-UI includes the internal <code>ApisPreset</code>, which contains a set of plugins that provide baseline functionality for Swagger-UI. If you specify your own <code>presets</code> option, you need to add the ApisPreset manually, like so:</p>
|
||||
<pre><code class="lang-javascript">SwaggerUI({
|
||||
presets: [
|
||||
SwaggerUI.presets.apis,
|
||||
MyAmazingCustomPreset
|
||||
]
|
||||
})
|
||||
</code></pre>
|
||||
<p>The need to provide the <code>apis</code> preset when adding other presets is an artifact of Swagger-UI's original design, and will likely be removed in the next major version.</p>
|
||||
<h3 id="getcomponent">getComponent</h3>
|
||||
<p><code>getComponent</code> is a helper function injected into every container component, which is used to get references to components provided by the plugin system.</p>
|
||||
<p>All components should be loaded through <code>getComponent</code>, since it allows other plugins to modify the component. It is preferred over a conventional <code>import</code> statement.</p>
|
||||
<p>Container components in Swagger-UI can be loaded by passing <code>true</code> as the second argument to <code>getComponent</code>, like so:</p>
|
||||
<pre><code>getComponent("ContainerComponentName", true)
|
||||
</code></pre><p>This will map the current system as props to the component.</p>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
</div>
|
||||
<div class="search-results">
|
||||
<div class="has-results">
|
||||
|
||||
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
|
||||
<ul class="search-results-list"></ul>
|
||||
|
||||
</div>
|
||||
<div class="no-results">
|
||||
|
||||
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<a href="../usage/version-detection.html" class="navigation navigation-prev " aria-label="Previous page: Version detection">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="custom-layout.html" class="navigation navigation-next " aria-label="Next page: Creating a custom layout">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Overview","level":"3.1","depth":1,"next":{"title":"Creating a custom layout","level":"3.2","depth":1,"path":"customization/custom-layout.md","ref":"customization/custom-layout.md","articles":[]},"previous":{"title":"Version detection","level":"2.3","depth":1,"path":"usage/version-detection.md","ref":"usage/version-detection.md","articles":[]},"dir":"ltr"},"config":{"plugins":["livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Swagger-UI","gitbook":"*"},"file":{"path":"customization/overview.md","mtime":"2017-11-01T00:16:30.163Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-11-01T03:42:59.286Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook.js"></script>
|
||||
<script src="../gitbook/theme.js"></script>
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
612
docs/_book/customization/plugin-api.html
Normal file
612
docs/_book/customization/plugin-api.html
Normal file
@@ -0,0 +1,612 @@
|
||||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>Plugin API · Swagger-UI</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="description" content="">
|
||||
<meta name="generator" content="GitBook 3.2.3">
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/style.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="HandheldFriendly" content="true"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
|
||||
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
|
||||
|
||||
|
||||
<link rel="next" href="../development/setting-up.html" />
|
||||
|
||||
|
||||
<link rel="prev" href="custom-layout.html" />
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="book">
|
||||
<div class="book-summary">
|
||||
|
||||
|
||||
<div id="book-search-input" role="search">
|
||||
<input type="text" placeholder="Type to search" />
|
||||
</div>
|
||||
|
||||
|
||||
<nav role="navigation">
|
||||
|
||||
|
||||
|
||||
<ul class="summary">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="chapter " data-level="1.1" data-path="../">
|
||||
|
||||
<a href="../">
|
||||
|
||||
|
||||
Intro
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="header">Usage</li>
|
||||
|
||||
|
||||
|
||||
<li class="chapter " data-level="2.1" data-path="../usage/installation.html">
|
||||
|
||||
<a href="../usage/installation.html">
|
||||
|
||||
|
||||
Installation
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="2.2" data-path="../usage/configuration.html">
|
||||
|
||||
<a href="../usage/configuration.html">
|
||||
|
||||
|
||||
Configuration
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<ul class="articles">
|
||||
|
||||
|
||||
<li class="chapter " data-level="2.2.1" data-path="../usage/deep-linking.html">
|
||||
|
||||
<a href="../usage/deep-linking.html">
|
||||
|
||||
|
||||
deepLinking
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="2.3" data-path="../usage/version-detection.html">
|
||||
|
||||
<a href="../usage/version-detection.html">
|
||||
|
||||
|
||||
Version detection
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="header">Customization</li>
|
||||
|
||||
|
||||
|
||||
<li class="chapter " data-level="3.1" data-path="overview.html">
|
||||
|
||||
<a href="overview.html">
|
||||
|
||||
|
||||
Overview
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter " data-level="3.2" data-path="custom-layout.html">
|
||||
|
||||
<a href="custom-layout.html">
|
||||
|
||||
|
||||
Creating a custom layout
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<li class="chapter active" data-level="3.3" data-path="plugin-api.html">
|
||||
|
||||
<a href="plugin-api.html">
|
||||
|
||||
|
||||
Plugin API
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="header">Development</li>
|
||||
|
||||
|
||||
|
||||
<li class="chapter " data-level="4.1" data-path="../development/setting-up.html">
|
||||
|
||||
<a href="../development/setting-up.html">
|
||||
|
||||
|
||||
Setting up a dev environment
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="divider"></li>
|
||||
|
||||
<li>
|
||||
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
|
||||
Published with GitBook
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
</nav>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="book-body">
|
||||
|
||||
<div class="body-inner">
|
||||
|
||||
|
||||
|
||||
<div class="book-header" role="navigation">
|
||||
|
||||
|
||||
<!-- Title -->
|
||||
<h1>
|
||||
<i class="fa fa-circle-o-notch fa-spin"></i>
|
||||
<a href=".." >Plugin API</a>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="page-wrapper" tabindex="-1" role="main">
|
||||
<div class="page-inner">
|
||||
|
||||
<div id="book-search-results">
|
||||
<div class="search-noresults">
|
||||
|
||||
<section class="normal markdown-section">
|
||||
|
||||
<h1 id="plugins">Plugins</h1>
|
||||
<p>A plugin is a function that returns an object - more specifically, the object may contain functions and components that augment and modify Swagger-UI's functionality.</p>
|
||||
<h3 id="format">Format</h3>
|
||||
<p>A plugin return value may contain any of these keys, where <code>myStateKey</code> is a name for a piece of state:</p>
|
||||
<pre><code class="lang-javascript">{
|
||||
statePlugins: {
|
||||
myStateKey: {
|
||||
actions,
|
||||
reducers,
|
||||
selectors,
|
||||
wrapActions,
|
||||
wrapSelectors
|
||||
}
|
||||
},
|
||||
components: {},
|
||||
wrapComponents: {},
|
||||
fn: {}
|
||||
}
|
||||
</code></pre>
|
||||
<h3 id="system-is-provided-to-plugins">System is provided to plugins</h3>
|
||||
<p>Let's assume we have a plugin, <code>NormalPlugin</code>, that exposes a <code>doStuff</code> action under the <code>normal</code> state namespace.</p>
|
||||
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> ExtendingPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
statePlugins: {
|
||||
extending: {
|
||||
actions: {
|
||||
doExtendedThings: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">...args</span>) </span>{
|
||||
<span class="hljs-comment">// you can do other things in here if you want</span>
|
||||
<span class="hljs-keyword">return</span> system.normalActions.doStuff(...args)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<p>As you can see, each plugin is passed a reference to the <code>system</code> being built up. As long as <code>NormalPlugin</code> is compiled before <code>ExtendingPlugin</code>, this will work without any issues.</p>
|
||||
<p>There is no dependency management built into the plugin system, so if you create a plugin that relies on another, it is your responsibility to make sure that the dependent plugin is loaded <em>after</em> the plugin being depended on.</p>
|
||||
<h3 id="interfaces">Interfaces</h3>
|
||||
<h5 id="actions">Actions</h5>
|
||||
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> MyActionPlugin = () => {
|
||||
<span class="hljs-keyword">return</span> {
|
||||
statePlugins: {
|
||||
example: {
|
||||
actions: {
|
||||
updateFavoriteColor: (str) => {
|
||||
<span class="hljs-keyword">return</span> {
|
||||
type: <span class="hljs-string">"EXAMPLE_SET_FAV_COLOR"</span>,
|
||||
payload: str
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<pre><code class="lang-js"><span class="hljs-comment">// elsewhere</span>
|
||||
exampleActions.updateFavoriteColor(<span class="hljs-string">"blue"</span>)
|
||||
</code></pre>
|
||||
<p>The Action interface enables the creation of new Redux action creators within a piece of state in the Swagger-UI system.</p>
|
||||
<p>This action creator function will be bound to the <code>example</code> reducer dispatcher and exposed to container components as <code>exampleActions.updateFavoriteColor</code>.</p>
|
||||
<p>For more information about the concept of actions in Redux, see the <a href="http://redux.js.org/docs/basics/Actions.html" target="_blank">Redux Actions documentation</a>.</p>
|
||||
<h5 id="reducers">Reducers</h5>
|
||||
<p>Reducers take a state (which is an Immutable map) and an action, and return a new state.</p>
|
||||
<p>Reducers must be provided to the system under the name of the action type that they handle, in this case, <code>EXAMPLE_SET_FAV_COLOR</code>.</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">const</span> MyReducerPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
statePlugins: {
|
||||
example: {
|
||||
reducers: {
|
||||
<span class="hljs-string">"EXAMPLE_SET_FAV_COLOR"</span>: (state, action) => {
|
||||
<span class="hljs-comment">// `system.Im` is the Immutable.js library</span>
|
||||
<span class="hljs-keyword">return</span> state.set(<span class="hljs-string">"favColor"</span>, system.Im.fromJS(action.payload))
|
||||
<span class="hljs-comment">// we're updating the Immutable state object...</span>
|
||||
<span class="hljs-comment">// we need to convert vanilla objects into an immutable type (fromJS)</span>
|
||||
<span class="hljs-comment">// See immutable docs about how to modify the state</span>
|
||||
<span class="hljs-comment">// PS: you're only working with the state under the namespace, in this case "example".</span>
|
||||
<span class="hljs-comment">// So you can do what you want, without worrying about /other/ namespaces</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<h5 id="selectors">Selectors</h5>
|
||||
<p>Selectors reach into</p>
|
||||
<p>They're an easy way to keep logic for getting data out of state in one place, and is preferred over passing state data directly into components.</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">const</span> MySelectorPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
statePlugins: {
|
||||
example: {
|
||||
selectors: {
|
||||
myFavoriteColor: (state) => state.get(<span class="hljs-string">"favColor"</span>)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<p>You can also use the Reselect library to memoize your selectors, which is recommended for any selectors that will see heavy use:</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { createSelector } <span class="hljs-keyword">from</span> <span class="hljs-string">"reselect"</span>
|
||||
|
||||
<span class="hljs-keyword">const</span> MySelectorPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
statePlugins: {
|
||||
example: {
|
||||
selectors: {
|
||||
<span class="hljs-comment">// this selector will be memoized after it is run once for a</span>
|
||||
<span class="hljs-comment">// value of `state`</span>
|
||||
myFavoriteColor: createSelector((state) => state.get(<span class="hljs-string">"favColor"</span>))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<p>Once a selector has been defined, you can use it:</p>
|
||||
<pre><code class="lang-js">exampleSelectors.myFavoriteColor() <span class="hljs-comment">// gets `favColor` in state for you</span>
|
||||
</code></pre>
|
||||
<h5 id="components">Components</h5>
|
||||
<p>You can provide a map of components to be integrated into the system.</p>
|
||||
<p>Be mindful of the key names for the components you provide, as you'll need to use those names to refer to the components elsewhere.</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">const</span> MyComponentPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
components: {
|
||||
<span class="hljs-comment">// components can just be functions</span>
|
||||
HelloWorld: () => <span class="xml"><span class="hljs-tag"><<span class="hljs-name">h1</span>></span>Hello World!<span class="hljs-tag"></<span class="hljs-name">h1</span>></span></span>
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<pre><code class="lang-js"><span class="hljs-comment">// elsewhere</span>
|
||||
<span class="hljs-keyword">const</span> HelloWorld = getComponent(<span class="hljs-string">"HelloWorld"</span>)
|
||||
</code></pre>
|
||||
<h5 id="wrap-actions">Wrap-Actions</h5>
|
||||
<p>Wrap Actions allow you to override the behavior of an action in the system.</p>
|
||||
<p>This interface is very useful for building custom behavior on top of builtin actions.</p>
|
||||
<p>A Wrap Action's first argument is <code>oriAction</code>, which is the action being wrapped. It is your responsibility to call the <code>oriAction</code> - if you don't, the original action will not fire!</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">const</span> MySpecPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
statePlugins: {
|
||||
spec: {
|
||||
actions: {
|
||||
updateSpec: (str) => {
|
||||
<span class="hljs-keyword">return</span> {
|
||||
type: <span class="hljs-string">"SPEC_UPDATE_SPEC"</span>,
|
||||
payload: str
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="hljs-comment">// this plugin allows you to watch changes to the spec that is in memory</span>
|
||||
<span class="hljs-keyword">const</span> MyWrapActionPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
statePlugins: {
|
||||
spec: {
|
||||
wrapActions: {
|
||||
updateSpec: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">oriAction, str</span>) </span>{
|
||||
doSomethingWithSpecValue(str)
|
||||
<span class="hljs-keyword">return</span> oriAction(str) <span class="hljs-comment">// don't forget!</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<h5 id="wrap-selectors">Wrap-Selectors</h5>
|
||||
<p>Wrap Selectors allow you to override the behavior of a selector in the system.</p>
|
||||
<p>They are function factories with the signature <code>(oriSelector, system) => (...args) => result</code>.</p>
|
||||
<p>This interface is useful for controlling what data flows into components. We use this in the core code to disable selectors based on the API definition's version.</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { createSelector } <span class="hljs-keyword">from</span> <span class="hljs-string">'reselect'</span>
|
||||
|
||||
<span class="hljs-keyword">const</span> MySpecPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
statePlugins: {
|
||||
spec: {
|
||||
selectors: {
|
||||
someData: createSelector(
|
||||
state => state.get(<span class="hljs-string">"something"</span>)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="hljs-keyword">const</span> MyWrapSelectorsPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
statePlugins: {
|
||||
spec: {
|
||||
wrapSelectors: {
|
||||
someData: (oriSelector, system) => (...args) => {
|
||||
<span class="hljs-comment">// you can do other things here...</span>
|
||||
<span class="hljs-comment">// but let's just enable the default behavior</span>
|
||||
<span class="hljs-keyword">return</span> oriSelector(...args)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<h5 id="wrap-components">Wrap-Components</h5>
|
||||
<p>Wrap Components allow you to override a component registered within the system.</p>
|
||||
<p>Wrap Components are function factories with the signature <code>(OriginalComponent, system) => props => ReactElement</code>.</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">const</span> MyNumberDisplayPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
components: {
|
||||
NumberDisplay: ({ number }) => <span class="xml"><span class="hljs-tag"><<span class="hljs-name">span</span>></span>{number}<span class="hljs-tag"></<span class="hljs-name">span</span>></span></span>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="hljs-keyword">const</span> MyWrapComponentPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
wrapComponents: {
|
||||
NumberDisplay: (Original, system) => (props) => {
|
||||
<span class="hljs-keyword">if</span>(props.number > <span class="hljs-number">10</span>) {
|
||||
<span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag"><<span class="hljs-name">div</span>></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">h3</span>></span>Warning! Big number ahead.<span class="hljs-tag"></<span class="hljs-name">h3</span>></span>
|
||||
<span class="hljs-tag"></<span class="hljs-name">div</span>></span></span>
|
||||
} <span class="hljs-keyword">else</span> {
|
||||
<span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag"><<span class="hljs-name">Original</span> {<span class="hljs-attr">...props</span>} /></span>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</span></code></pre>
|
||||
<h5 id="fn">fn</h5>
|
||||
<p>The fn interface allows you to add helper functions to the system for use elsewhere.</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">import</span> leftPad <span class="hljs-keyword">from</span> <span class="hljs-string">"left-pad"</span>
|
||||
|
||||
<span class="hljs-keyword">const</span> MyFnPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
fn: {
|
||||
leftPad: leftPad
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
</div>
|
||||
<div class="search-results">
|
||||
<div class="has-results">
|
||||
|
||||
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
|
||||
<ul class="search-results-list"></ul>
|
||||
|
||||
</div>
|
||||
<div class="no-results">
|
||||
|
||||
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<a href="custom-layout.html" class="navigation navigation-prev " aria-label="Previous page: Creating a custom layout">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="../development/setting-up.html" class="navigation navigation-next " aria-label="Next page: Setting up a dev environment">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Plugin API","level":"3.3","depth":1,"next":{"title":"Setting up a dev environment","level":"4.1","depth":1,"path":"development/setting-up.md","ref":"development/setting-up.md","articles":[]},"previous":{"title":"Creating a custom layout","level":"3.2","depth":1,"path":"customization/custom-layout.md","ref":"customization/custom-layout.md","articles":[]},"dir":"ltr"},"config":{"plugins":["livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Swagger-UI","gitbook":"*"},"file":{"path":"customization/plugin-api.md","mtime":"2017-11-01T03:47:49.395Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-11-01T03:42:59.286Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook.js"></script>
|
||||
<script src="../gitbook/theme.js"></script>
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
|
||||
|
||||
|
||||
|
||||
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user