diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index daf1b22a..c30fc24f 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -8,7 +8,7 @@ ### Customization - [Overview](customization/overview.md) -- [Creating a Custom Layout](customization/custom-layout.md) +- [Creating a custom layout](customization/custom-layout.md) - [Plugin API](customization/plugin-api.md) ### Development diff --git a/docs/_book/customization/custom-layout.html b/docs/_book/customization/custom-layout.html index 0e82da19..f21c9386 100644 --- a/docs/_book/customization/custom-layout.html +++ b/docs/_book/customization/custom-layout.html @@ -4,7 +4,7 @@ - Creating a Custom Layout · Swagger-UI + Creating a custom layout · Swagger-UI @@ -192,7 +192,7 @@ - Creating a Custom Layout + Creating a custom layout @@ -289,7 +289,7 @@

- Creating a Custom Layout + Creating a custom layout

@@ -304,7 +304,89 @@
- +

Creating a custom layout

+

Layouts 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.

+

By default, Swagger-UI uses BaseLayout, which is built into the application. You can specify a different layout to be used by passing the layout's name as the layout parameter to Swagger-UI. Be sure to provide your custom layout as a component to Swagger-UI.

+


+

For example, if you wanted to create a custom layout that only displayed operations, you could define an OperationsLayout:

+
import React from "react"
+
+// Create the layout component
+class OperationsLayout extends React.Component {
+  render() {
+    const {
+      getComponent
+    } = this.props
+
+    const Operations = getComponent("Operations", true)
+
+    return {
+      <div>
+        <Operations />
+      </div>
+    }
+  }
+}
+
+// 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"
+})
+
+

Augmenting the default layout

+

If you'd like to build around the BaseLayout instead of replacing it, you can pull the BaseLayout into your custom layout and use it:

+
import React from "react"
+
+// Create the layout component
+class AugmentingLayout extends React.Component {
+  render() {
+    const {
+      getComponent
+    } = this.props
+
+    const BaseLayout = getComponent("BaseLayout", true)
+
+    return {
+      <div>
+        <div className="myCustomHeader">
+          <h1>I have a custom header above Swagger-UI!</h1>
+        </div>
+        <BaseLayout />
+      </div>
+    }
+  }
+}
+
+// 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"
+})
+
+
@@ -347,7 +429,7 @@ diff --git a/docs/_book/customization/overview.html b/docs/_book/customization/overview.html index ad1caf11..5ff7f5a3 100644 --- a/docs/_book/customization/overview.html +++ b/docs/_book/customization/overview.html @@ -192,7 +192,7 @@ - Creating a Custom Layout + Creating a custom layout @@ -309,10 +309,14 @@

Swagger-UI leans heavily on concepts and patterns found in React and Redux.

If you aren't already familiar, here's some suggested reading:

In the following documentation, we won't take the time to define the fundamentals covered in the resources above.

+
+

Note: Some of the examples in this section contain JSX, which is a syntax extension to JavaScript that is useful for writing React components.

+

If you don't want to set up a build pipeline capable of translating JSX to JavaScript, take a look at React without JSX (reactjs.org).

+

The System

The system is the heart of the Swagger-UI application. At runtime, it's a JavaScript object that holds many things: