Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

README.md 4.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #### `plugins`: PropTypes.arrayOf(PropTypes.object),
  46. 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.
  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. #### `supportedSubmitMethods`: PropTypes.arrayOf(PropTypes.oneOf(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']))
  49. 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.
  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. ## Limitations
  52. * Not all configuration bindings are available.
  53. * Some props are only applied on mount, and cannot be updated reliably.
  54. * OAuth redirection handling is not supported.
  55. * Topbar/Standalone mode is not supported.
  56. * Custom plugins are not supported.
  57. We intend to address these limitations based on user demand, so please open an issue or pull request if you have a specific request.
  58. ## Notes
  59. * 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/`.
  60. ---
  61. For anything else, check the [Swagger-UI](https://github.com/swagger-api/swagger-ui) repository.