source: node_modules/swagger-ui-react/README.md@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 11.5 KB
RevLine 
[d24f17c]1# `swagger-ui-react`
2
3[![NPM version](https://badge.fury.io/js/swagger-ui-react.svg)](http://badge.fury.io/js/swagger-ui-react)
4
5`swagger-ui-react` is a flavor of Swagger UI suitable for use in React applications.
6
7It has a few differences from the main version of Swagger UI:
8* Declares `react` and `react-dom` as peerDependencies instead of production dependencies
9* Exports a component instead of a constructor function
10
11Versions of this module mirror the version of Swagger UI included in the distribution.
12
13## Quick start
14
15Install `swagger-ui-react`:
16
17```
18$ npm i --save swagger-ui-react
19```
20
21Use it in your React application:
22
23```js
24import SwaggerUI from "swagger-ui-react"
25import "swagger-ui-react/swagger-ui.css"
26
27export default App = () => <SwaggerUI url="https://petstore.swagger.io/v2/swagger.json" />
28```
29
30## Props
31
32These props map to [Swagger UI configuration options](https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md) of the same name.
33
34#### `spec`: PropTypes.object
35
36An OpenAPI document represented as a JavaScript object, JSON string, or YAML string for Swagger UI to display.
37
38⚠️ Don't use this in conjunction with `url` - unpredictable behavior may occur.
39
40#### `url`: PropTypes.string
41
42Remote URL to an OpenAPI document that Swagger UI will fetch, parse, and display.
43
44⚠️ Don't use this in conjunction with `spec` - unpredictable behavior may occur.
45
46#### `layout`: PropTypes.string
47
48The name of a component available via the plugin system to use as the top-level layout for Swagger UI. The default value is `BaseLayout`.
49
50⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
51
52#### `onComplete`: PropTypes.func
53
54> `(system) => void`
55
56A callback function that is triggered when Swagger-UI finishes rendering an OpenAPI document.
57
58Swagger UI's `system` object is passed as an argument.
59
60#### `requestInterceptor`: PropTypes.func
61
62> `req => req` or `req => Promise<req>`.
63
64A function that accepts a request object, and returns either a request object
65or a Promise that resolves to a request object.
66
67#### `responseInterceptor`: PropTypes.func
68
69> `res => res` or `res => Promise<res>`.
70
71A function that accepts a response object, and returns either a response object
72or a Promise that resolves to a response object.
73
74#### `docExpansion`: PropTypes.oneOf(['list', 'full', 'none'])
75
76Controls the default expansion setting for the operations and tags. It can be 'list' (expands only the tags), 'full' (expands the tags and operations) or 'none' (expands nothing). The default value is 'list'.
77
78⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
79
80#### `defaultModelExpandDepth`: PropTypes.number
81
82The default expansion depth for models (set to -1 completely hide the models).
83
84⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
85
86#### `defaultModelRendering`: PropTypes.oneOf(["example", "model"])
87
88Controls how the model is shown when the API is first rendered. (The user can always switch the rendering for a given model by clicking the 'Model' and 'Example Value' links.) The default value is 'example'.
89
90⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
91
92
93#### `displayOperationId`: PropTypes.bool
94
95Controls the display of operationId in operations list. The default is false.
96
97⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
98
99#### `plugins`: PropTypes.arrayOf(PropTypes.object),
100
101An array of objects that augment and modify Swagger UI's functionality. See Swagger UI's [Plugin API](https://github.com/swagger-api/swagger-ui/blob/master/docs/customization/plugin-api.md) for more details.
102
103⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
104
105#### `supportedSubmitMethods`: PropTypes.arrayOf(PropTypes.oneOf(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']))
106
107HTTP methods that have the Try it out feature enabled. An empty array disables Try it out for all operations. This does not filter the operations from the display.
108
109⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
110
111#### `showExtensions`: PropTypes.bool
112
113Controls the display of vendor extension (`x-`) fields and values for Operations, Parameters, Responses, and Schema.
114
115⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
116
117#### `showCommonExtensions`: PropTypes.bool
118
119Controls the display of extensions (pattern, maxLength, minLength, maximum, minimum) fields and values for Parameters.
120
121⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
122
123#### `showMutatedRequest`: PropTypes.bool
124
125If set to `true`, uses the mutated request returned from a requestInterceptor to produce the curl command in the UI, otherwise the request before the requestInterceptor was applied is used.
126
127⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
128
129#### `presets`: PropTypes.arrayOf(PropTypes.func),
130
131An array of functions that augment and modify Swagger UI's functionality. See Swagger UI's [Plugin API](https://github.com/swagger-api/swagger-ui/blob/master/docs/customization/plugin-api.md) for more details.
132
133⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
134
135#### `tryItOutEnabled`: PropTypes.bool
136
137Controls whether the "Try it out" section should start enabled. The default is false.
138
139⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
140
141#### `displayRequestDuration`: PropTypes.bool
142
143Controls the display of the request duration (in milliseconds) for "Try it out" requests. The default is false.
144
145#### `filter`: PropTypes.oneOfType([PropTypes.string, PropTypes.bool])
146
147If set, enables filtering. The top bar will show an edit box that you can use to filter the tagged operations that are shown. Can be Boolean to enable or disable, or a string, in which case filtering will be enabled using that string as the filter expression. Filtering is case sensitive matching the filter expression anywhere inside the tag. See Swagger UI's [Plug Points](https://github.com/swagger-api/swagger-ui/blob/master/docs/customization/plug-points.md#fnopsfilter) to customize the filtering behavior.
148
149#### `requestSnippetsEnabled`: PropTypes.bool,
150
151Enables the request snippet section. When disabled, the legacy curl snippet will be used. The default is false.
152
153⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
154
155#### `requestSnippets`: PropTypes.object,
156
157Configures the request snippet core plugin. See Swagger UI's [Display Configuration](https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md#display) for more details.
158
159⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
160
161#### `persistAuthorization`: PropTypes.bool
162
163If set, it persists authorization data and it would not be lost on browser close/refresh. The default is false.
164
165⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
166
167#### `withCredentials`: PropTypes.bool
168
169If set to `true`, enables passing credentials, [as defined in the Fetch standard](https://fetch.spec.whatwg.org/#credentials), in CORS requests that are sent by the browser. Note that Swagger UI cannot currently set cookies cross-domain (see [swagger-js#1163](https://github.com/swagger-api/swagger-js/issues/1163)) - as a result, you will have to rely on browser-supplied cookies (which this setting enables sending) that Swagger UI cannot control.
170
171⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
172
173#### `oauth2RedirectUrl`: PropTypes.string
174
175Redirect url given as parameter to the oauth2 provider. Default the url refers to oauth2-redirect.html at the same path as the Swagger UI is available.
176
177⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change.
178
179
180## Limitations
181
182* Not all configuration bindings are available.
183* Some props are only applied on mount, and cannot be updated reliably.
184* OAuth redirection handling is not supported.
185* Topbar/Standalone mode is not supported.
186
187We intend to address these limitations based on user demand, so please open an issue or pull request if you have a specific request.
188
189## Notes
190
191* The `package.json` in the same folder as this README is _not_ the manifest that should be used for releases - another manifest is generated at build-time and can be found in `./dist/`.
192
193---
194
195For anything else, check the [Swagger-UI](https://github.com/swagger-api/swagger-ui) repository.
Note: See TracBrowser for help on using the repository browser.