25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 6.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # `swagger-ui-react`
  2. [![NPM version](https://badge.fury.io/js/swagger-ui-react.svg)](http://badge.fury.io/js/swagger-ui-react)
  3. `swagger-ui-react` is a flavor of Swagger UI suitable for use in React applications.
  4. It has a few differences from the main version of Swagger UI:
  5. * Declares `react` and `react-dom` as peerDependencies instead of production dependencies
  6. * Exports a component instead of a constructor function
  7. Versions of this module mirror the version of Swagger UI included in the distribution.
  8. ## Quick start
  9. Install `swagger-ui-react`:
  10. ```
  11. $ npm i --save swagger-ui-react
  12. ```
  13. Use it in your React application:
  14. ```js
  15. import SwaggerUI from "swagger-ui-react"
  16. import "swagger-ui-react/swagger-ui.css"
  17. export default App = () => <SwaggerUI url="https://petstore.swagger.io/v2/swagger.json" />
  18. ```
  19. ## Props
  20. These props map to [Swagger UI configuration options](https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md) of the same name.
  21. #### `spec`: PropTypes.object
  22. An OpenAPI document respresented as a JavaScript object, JSON string, or YAML string for Swagger UI to display.
  23. ⚠️ Don't use this in conjunction with `url` - unpredictable behavior may occur.
  24. #### `url`: PropTypes.string
  25. Remote URL to an OpenAPI document that Swagger UI will fetch, parse, and display.
  26. ⚠️ Don't use this in conjunction with `spec` - unpredictable behavior may occur.
  27. #### `onComplete`: PropTypes.func
  28. > `(system) => void`
  29. A callback function that is triggered when Swagger-UI finishes rendering an OpenAPI document.
  30. Swagger UI's `system` object is passed as an argument.
  31. #### `requestInterceptor`: PropTypes.func
  32. > `req => req` or `req => Promise<req>`.
  33. A function that accepts a request object, and returns either a request object
  34. or a Promise that resolves to a request object.
  35. #### `responseInterceptor`: PropTypes.func
  36. > `res => res` or `res => Promise<res>`.
  37. A function that accepts a response object, and returns either a response object
  38. or a Promise that resolves to a response object.
  39. #### `docExpansion`: PropTypes.oneOf(['list', 'full', 'none'])
  40. Controls 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'.
  41. ⚠️ 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.
  42. #### `defaultModelExpandDepth`: PropTypes.number
  43. The default expansion depth for models (set to -1 completely hide the models).
  44. ⚠️ 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.
  45. #### `displayOperationId`: PropTypes.bool
  46. Controls the display of operationId in operations list. The default is false.
  47. ⚠️ 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.
  48. #### `plugins`: PropTypes.arrayOf(PropTypes.object),
  49. An 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.
  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. #### `supportedSubmitMethods`: PropTypes.arrayOf(PropTypes.oneOf(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']))
  52. HTTP 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.
  53. ⚠️ 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.
  54. #### `showMutatedRequest`: PropTypes.bool
  55. If 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.
  56. ⚠️ 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.
  57. #### `presets`: PropTypes.arrayOf(PropTypes.func),
  58. An 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.
  59. ⚠️ 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.
  60. ## Limitations
  61. * Not all configuration bindings are available.
  62. * Some props are only applied on mount, and cannot be updated reliably.
  63. * OAuth redirection handling is not supported.
  64. * Topbar/Standalone mode is not supported.
  65. * Custom plugins are not supported.
  66. We intend to address these limitations based on user demand, so please open an issue or pull request if you have a specific request.
  67. ## Notes
  68. * 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/`.
  69. ---
  70. For anything else, check the [Swagger-UI](https://github.com/swagger-api/swagger-ui) repository.