Merge tag 'v2.0.0-rc.65' into sections-at-the-end

This commit is contained in:
Roberto Fernández 2022-03-23 08:28:36 +01:00
commit 99f35d22ab
37 changed files with 1624 additions and 246 deletions

View File

@ -1,3 +1,25 @@
# [2.0.0-rc.65](https://github.com/Redocly/redoc/compare/v2.0.0-rc.64...v2.0.0-rc.65) (2022-03-15)
### Bug Fixes
* auth link scroll for Firerox ([#1922](https://github.com/Redocly/redoc/issues/1922)) ([fe67e9c](https://github.com/Redocly/redoc/commit/fe67e9c332fee716582a00d60fdf34767bff22d4))
* improve customization fab ([#1891](https://github.com/Redocly/redoc/issues/1891)) ([635f379](https://github.com/Redocly/redoc/commit/635f379eb086268c91eef715148eca8f080cfb86))
* sanitize array of items ([#1920](https://github.com/Redocly/redoc/issues/1920)) ([059bd80](https://github.com/Redocly/redoc/commit/059bd8000e5fd65753d5ca9e0c47940394e0c79b))
* use x-displayName in securityDefinitions [#1444](https://github.com/Redocly/redoc/pull/1444)) ([ac6fb4](https://github.com/Redocly/redoc/commit/
# [2.0.0-rc.64](https://github.com/Redocly/redoc/compare/v2.0.0-rc.63...v2.0.0-rc.64) (2022-02-24)
### Bug Fixes
* bump json-pointer version to avoid CVE-2021-23820 ([#1910](https://github.com/Redocly/redoc/issues/1910)) ([777efdd](https://github.com/Redocly/redoc/commit/777efdde35c1c8dc79dd714e1666279e9192dddb))
* external ref in schema definition ([#1894](https://github.com/Redocly/redoc/issues/1894)) ([57cdd9f](https://github.com/Redocly/redoc/commit/57cdd9f6da38418d6214ac3c6480c5847ecd0228))
# [2.0.0-rc.63](https://github.com/Redocly/redoc/compare/v2.0.0-rc.61...v2.0.0-rc.63) (2022-01-27) # [2.0.0-rc.63](https://github.com/Redocly/redoc/compare/v2.0.0-rc.61...v2.0.0-rc.63) (2022-01-27)

View File

@ -217,12 +217,18 @@ You can use all of the following options with the standalone version of the <red
* `hideDownloadButton` - do not show "Download" spec button. **THIS DOESN'T MAKE YOUR SPEC PRIVATE**, it just hides the button. * `hideDownloadButton` - do not show "Download" spec button. **THIS DOESN'T MAKE YOUR SPEC PRIVATE**, it just hides the button.
* `hideHostname` - if set, the protocol and hostname is not shown in the operation definition. * `hideHostname` - if set, the protocol and hostname is not shown in the operation definition.
* `hideLoading` - do not show loading animation. Useful for small docs. * `hideLoading` - do not show loading animation. Useful for small docs.
* `hideFab` - do not show FAB in mobile view. Useful for implementing a custom floating action button.
* `hideSchemaPattern` - if set, the pattern is not shown in the schema. * `hideSchemaPattern` - if set, the pattern is not shown in the schema.
* `hideSingleRequestSampleTab` - do not show the request sample tab for requests with only one sample. * `hideSingleRequestSampleTab` - do not show the request sample tab for requests with only one sample.
* `showObjectSchemaExamples` - show object schema example in the properties, default `false`.
* `expandSingleSchemaField` - automatically expand single field in a schema * `expandSingleSchemaField` - automatically expand single field in a schema
* `schemaExpansionLevel` - specifies whether to automatically expand schemas. Special value `"all"` expands all levels. The default value is `0`.
* `jsonSampleExpandLevel` - set the default expand level for JSON payload samples (responses and request body). Special value `"all"` expands all levels. The default value is `2`. * `jsonSampleExpandLevel` - set the default expand level for JSON payload samples (responses and request body). Special value `"all"` expands all levels. The default value is `2`.
* `hideSchemaTitles` - do not display schema `title` next to to the type * `hideSchemaTitles` - do not display schema `title` next to to the type
* `simpleOneOfTypeLabel` - show only unique oneOf types in the label without titles * `simpleOneOfTypeLabel` - show only unique oneOf types in the label without titles
* `sortEnumValuesAlphabetically` - set to true, sorts all enum values in all schemas alphabetically
* `sortOperationsAlphabetically` - set to true, sorts operations in the navigation sidebar and in the middle panel alphabetically
* `sortTagsAlphabetically` - set to true, sorts tags in the navigation sidebar and in the middle panel alphabetically
* `lazyRendering` - _Not implemented yet_ ~~if set, enables lazy rendering mode in ReDoc. This mode is useful for APIs with big number of operations (e.g. > 50). In this mode ReDoc shows initial screen ASAP and then renders the rest operations asynchronously while showing progress bar on the top. Check out the [demo](\\redocly.github.io/redoc) for the example.~~ * `lazyRendering` - _Not implemented yet_ ~~if set, enables lazy rendering mode in ReDoc. This mode is useful for APIs with big number of operations (e.g. > 50). In this mode ReDoc shows initial screen ASAP and then renders the rest operations asynchronously while showing progress bar on the top. Check out the [demo](\\redocly.github.io/redoc) for the example.~~
* `menuToggle` - if true clicking second time on expanded menu item will collapse it, default `true`. * `menuToggle` - if true clicking second time on expanded menu item will collapse it, default `true`.
* `nativeScrollbars` - use native scrollbar for sidemenu instead of perfect-scroll (scrolling performance optimization for big specs). * `nativeScrollbars` - use native scrollbar for sidemenu instead of perfect-scroll (scrolling performance optimization for big specs).
@ -300,6 +306,9 @@ You can use all of the following options with the standalone version of the <red
* `backgroundColor`: '#263238' * `backgroundColor`: '#263238'
* `width`: '40%' * `width`: '40%'
* `textColor`: '#ffffff' * `textColor`: '#ffffff'
* `fab`
* `backgroundColor`: '#263238'
* `color`: '#ffffff'
----------- -----------
## Development ## Development

1337
cli/npm-shrinkwrap.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "redoc-cli", "name": "redoc-cli",
"version": "0.13.6", "version": "0.13.8",
"description": "ReDoc's Command Line Interface", "description": "ReDoc's Command Line Interface",
"main": "index.js", "main": "index.js",
"bin": "index.js", "bin": "index.js",
@ -19,7 +19,7 @@
"node-libs-browser": "^2.2.1", "node-libs-browser": "^2.2.1",
"react": "^17.0.1", "react": "^17.0.1",
"react-dom": "^17.0.1", "react-dom": "^17.0.1",
"redoc": "2.0.0-rc.62", "redoc": "2.0.0-rc.64",
"styled-components": "^5.3.0", "styled-components": "^5.3.0",
"yargs": "^17.0.1" "yargs": "^17.0.1"
}, },

View File

@ -1,10 +1,10 @@
--- ---
title: Using the Redoc CLI title: Use the Redoc CLI
redirectFrom: redirectFrom:
- /docs/quickstart/cli/ - /docs/quickstart/cli/
--- ---
# Using the Redoc CLI # How to use the Redoc CLI
With Redoc's command-line interface you can bundle your OpenAPI definition and API documentation With Redoc's command-line interface you can bundle your OpenAPI definition and API documentation
(made with Redoc) into a zero-dependency HTML file and locally render your (made with Redoc) into a zero-dependency HTML file and locally render your
@ -21,7 +21,7 @@ Or you can install `redoc-cli` using [npx](https://www.freecodecamp.org/news/npm
### Install Redoc CLI with yarn ### Install Redoc CLI with yarn
To install the `redoc-cli` package globally with yarn: To install the `redoc-cli` package globally with yarn:
```bash ```bash
yarn global add redoc-cli yarn global add redoc-cli
@ -29,7 +29,7 @@ yarn global add redoc-cli
### Install Redoc with npm ### Install Redoc with npm
To install the `redoc-cli` package globally with npm: To install the `redoc-cli` package globally with npm:
```bash ```bash
npm i -g redoc-cli npm i -g redoc-cli
@ -52,9 +52,9 @@ The CLI includes the following commands:
- **`redoc-cli serve [spec]`:** Starts a local server with Redoc. You must include the required parameter, spec, which is - **`redoc-cli serve [spec]`:** Starts a local server with Redoc. You must include the required parameter, spec, which is
a reference to an OpenAPI definition. Options include: a reference to an OpenAPI definition. Options include:
- `--ssr`: Implements a server-side rendering model. - `--ssr`: Implements a server-side rendering model.
- `--watch`: Automatically reloads the server while you edit your OpenAPI definition. - `--watch`: Automatically reloads the server while you edit your OpenAPI definition.
- `--options`: Customizes your output using [Redoc options](https://redoc.ly/docs/api-reference-docs/configuration/). - `--options`: Customizes your output using [Redoc options](https://redocly.com/docs/api-reference-docs/configuration/).
To add nested options, use dot notation. To add nested options, use dot notation.
- **`redoc-cli bundle [spec]`:** Bundles `spec` and Redoc into a zero-dependency HTML file. Options include: - **`redoc-cli bundle [spec]`:** Bundles `spec` and Redoc into a zero-dependency HTML file. Options include:
- `-t` or `--template`: Uses custom [Handlebars](https://handlebarsjs.com/) templates to render your OpenAPI definition. - `-t` or `--template`: Uses custom [Handlebars](https://handlebarsjs.com/) templates to render your OpenAPI definition.

View File

@ -1,10 +1,10 @@
--- ---
title: Using the Redoc Docker image title: Use the Redoc Docker image
redirectFrom: redirectFrom:
- /docs/quickstart/docker/ - /docs/quickstart/docker/
--- ---
# Using the Redoc Docker image # How to use the Redoc Docker image
Redoc is available as a pre-built Docker image in [Docker Hub](https://hub.docker.com/r/redocly/redoc/). Redoc is available as a pre-built Docker image in [Docker Hub](https://hub.docker.com/r/redocly/redoc/).
@ -26,7 +26,7 @@ To exit the preview, use `control+C`.
By default Redoc starts with a demo Swagger Petstore OpenAPI definition located at By default Redoc starts with a demo Swagger Petstore OpenAPI definition located at
http://petstore.swagger.io/v2/swagger.json. You can update this URL using http://petstore.swagger.io/v2/swagger.json. You can update this URL using
the environment variable `SPEC_URL`. the environment variable `SPEC_URL`.
For example: For example:
@ -34,8 +34,8 @@ For example:
docker run -p 8080:80 -e SPEC_URL=https://api.example.com/openapi.json redocly/redoc docker run -p 8080:80 -e SPEC_URL=https://api.example.com/openapi.json redocly/redoc
``` ```
## Using a Dockerfile ## Create a Dockerfile
You can also create a Dockerfile with some predefined environment variables. Check out You can also create a Dockerfile with some predefined environment variables. Check out
a sample [Dockerfile](https://github.com/Redocly/redoc/blob/master/config/docker/Dockerfile) a sample [Dockerfile](https://github.com/Redocly/redoc/blob/master/config/docker/Dockerfile)
in our code repo. in our code repo.

View File

@ -1,10 +1,10 @@
--- ---
title: Using the Redoc HTML element title: Use the Redoc HTML element
redirectFrom: redirectFrom:
- /docs/quickstart/html/ - /docs/quickstart/html/
--- ---
# Using the Redoc HTML element # How to use the Redoc HTML element
## Step 1 - Install Redoc ## Step 1 - Install Redoc
@ -17,9 +17,9 @@ You can install Redoc using one of the following package managers:
If you do not have a `package.json` file in your project directory, If you do not have a `package.json` file in your project directory,
you need to add one by initializing npm or yarn in your project. Use the command `npm init` for npm, you need to add one by initializing npm or yarn in your project. Use the command `npm init` for npm,
or `yarn init` for yarn. These initialization commands will lead you through the process or `yarn init` for yarn. These initialization commands will lead you through the process
of creating a `package.json` file in your project. of creating a `package.json` file in your project.
For more information, see For more information, see
[Creating a package.json file](https://docs.npmjs.com/creating-a-package-json-file) [Creating a package.json file](https://docs.npmjs.com/creating-a-package-json-file)
in the npm documentation or [Yarn init](https://classic.yarnpkg.com/en/docs/cli/init/) in the npm documentation or [Yarn init](https://classic.yarnpkg.com/en/docs/cli/init/)
in the yarn documentation. in the yarn documentation.
@ -27,7 +27,7 @@ in the yarn documentation.
### Install Redoc with yarn ### Install Redoc with yarn
After navigating to your project directory in your terminal, use the following command: After navigating to your project directory in your terminal, use the following command:
```bash ```bash
yarn add redoc yarn add redoc
@ -35,7 +35,7 @@ yarn add redoc
### Install Redoc with npm ### Install Redoc with npm
After navigating to your project directory in your terminal, use the following command: After navigating to your project directory in your terminal, use the following command:
```bash ```bash
npm i redoc npm i redoc
@ -68,7 +68,7 @@ You can add the <redoc> element to your HTML page and reference your OpenAPI
definition using the `spec-url` attribute, or you can initialize Redoc using definition using the `spec-url` attribute, or you can initialize Redoc using
a globally exposed Redoc object. a globally exposed Redoc object.
### Using the `spec-url` attribute ### The `spec-url` attribute
To add the <redoc> element with the `spec-url` attribute: To add the <redoc> element with the `spec-url` attribute:
@ -88,7 +88,7 @@ You can also use a local file (JSON or YAML) in your project, for instance:
<redoc spec-url="dist.json"></redoc> <redoc spec-url="dist.json"></redoc>
``` ```
### Using a Redoc object ### The Redoc object
To add the <redoc> element with a globally exposed Redoc object: To add the <redoc> element with a globally exposed Redoc object:
@ -97,7 +97,7 @@ Redoc.init(specOrSpecUrl, options, element, callback)
``` ```
- `specOrSpecUrl`: Either a JSON object with the OpenAPI definition or a URL to the - `specOrSpecUrl`: Either a JSON object with the OpenAPI definition or a URL to the
definition in JSON or YAML format. definition in JSON or YAML format.
- `options`: See [options object](https://redoc.ly/docs/api-reference-docs/configuration/) reference. - `options`: See [options object](https://redocly.com/docs/api-reference-docs/configuration/) reference.
- `element`: DOM element Redoc will be inserted into. - `element`: DOM element Redoc will be inserted into.
- `callback`(optional): Callback to be called after Redoc has been fully rendered. - `callback`(optional): Callback to be called after Redoc has been fully rendered.
It is also called on errors with `error` as the first argument. It is also called on errors with `error` as the first argument.
@ -120,4 +120,4 @@ Redoc.init('dist.yaml', {
scrollYOffset: 50 scrollYOffset: 50
}, document.getElementById('redoc-container')) }, document.getElementById('redoc-container'))
</script> </script>
``` ```

View File

@ -38,20 +38,20 @@ You will need an OpenAPI definition. For testing purposes, you can use one of th
- [Fitbit Plus OpenAPI Definition](https://raw.githubusercontent.com/TwineHealth/TwineDeveloperDocs/master/spec/swagger.yaml) - [Fitbit Plus OpenAPI Definition](https://raw.githubusercontent.com/TwineHealth/TwineDeveloperDocs/master/spec/swagger.yaml)
:::info OpenAPI specification :::info OpenAPI specification
For more information on the OpenAPI specification, refer to the [Learning OpenAPI 3](https://redoc.ly/docs/resources/learning-openapi/) For more information on the OpenAPI specification, refer to the [Learning OpenAPI 3](https://redocly.com/docs/resources/learning-openapi/)
section in the documentation. section in the documentation.
::: :::
### Running Redoc locally ### How to run Redoc locally
If you want to view your Redoc output locally, you can simulate an HTTP server. If you want to view your Redoc output locally, you can simulate an HTTP server.
#### Using Redocly OpenAPI CLI #### Redocly OpenAPI CLI
Redocly OpenAPI CLI is an open source command-line tool that includes a command Redocly OpenAPI CLI is an open source command-line tool that includes a command
for simulating an HTTP server to provide a preview of your OpenAPI definition locally. for simulating an HTTP server to provide a preview of your OpenAPI definition locally.
If you have [OpenAPI CLI](https://redoc.ly/docs/cli/#installation-and-usage) installed, `cd` into your If you have [OpenAPI CLI](https://redocly.com/docs/cli/#installation-and-usage) installed, `cd` into your
project directory and run the following command: project directory and run the following command:
```bash ```bash
@ -72,9 +72,9 @@ openapi preview-docs -p 8888 openapi.yaml
Replace `openapi.yaml` in the example command with the file path to your OpenAPI definition. Replace `openapi.yaml` in the example command with the file path to your OpenAPI definition.
For more information about the `preview-docs` command, refer to For more information about the `preview-docs` command, refer to
[OpenAPI CLI commands](https://redoc.ly/docs/cli/commands/preview-docs/#preview-docs) in the OpenAPI CLI documentation. [OpenAPI CLI commands](https://redocly.com/docs/cli/commands/preview-docs/#preview-docs) in the OpenAPI CLI documentation.
#### Using Python #### Python
If you have [Python 3](https://www.python.org/downloads/) installed, `cd` into your If you have [Python 3](https://www.python.org/downloads/) installed, `cd` into your
project directory and run the following command: project directory and run the following command:
@ -93,7 +93,7 @@ python -m SimpleHTTPServer 8000
The output after entering the command provides the local URL where the preview can be accessed. The output after entering the command provides the local URL where the preview can be accessed.
To exit the preview, use `control-C`. To exit the preview, use `control-C`.
#### Using Node.js #### Node.js
If you have [Node.js](https://nodejs.org/en/download/) installed, install `http-server` If you have [Node.js](https://nodejs.org/en/download/) installed, install `http-server`
using the following npm command: using the following npm command:

View File

@ -1,10 +1,10 @@
--- ---
title: Using the Redoc React component title: Use the Redoc React component
redirectFrom: redirectFrom:
- /docs/quickstart/react/ - /docs/quickstart/react/
--- ---
# Using the Redoc React component # How to use the Redoc React component
## Before you start ## Before you start
@ -44,7 +44,7 @@ Or you can pass your OpenAPI definition as an object, using the following format
## Optional - Pass options ## Optional - Pass options
Options can be passed into the RedocStandalone component to alter how it renders. Options can be passed into the RedocStandalone component to alter how it renders.
For example: For example:
@ -58,8 +58,8 @@ For example:
/> />
``` ```
For more information on configuration options, refer to the For more information on configuration options, refer to the
[Configuration options for Reference docs](https://redoc.ly/docs/api-reference-docs/configuration/) [Configuration options for Reference docs](https://redocly.com/docs/api-reference-docs/configuration/)
section of the documentation. Options available for Redoc are noted, section of the documentation. Options available for Redoc are noted,
"Supported in Redoc CE". "Supported in Redoc CE".

View File

@ -43,11 +43,12 @@ replace the `spec-url` attribute with the URL or local file address to your defi
</html> </html>
``` ```
:::attention Running Redoc locally requires an HTTP server :::attention Redoc requires an HTTP server to run locally
Loading local OpenAPI definitions is impossible without running a web server because of issues with Loading local OpenAPI definitions is impossible without running a web server because of issues with
[same-origin policy](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy) and [same-origin policy](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy) and
other security reasons. Refer to [Running Redoc locally](./deployment/intro.md#running-redoc-locally) for other security reasons. Refer to [Running Redoc locally](./deployment/intro.md#how-to-run-redoc-locally) for more information.
more information.
::: :::
For a more detailed explanation with step-by-step instructions and additional options for using Redoc, refer to the [Redoc deployment guide](./deployment/intro.md). For a more detailed explanation with step-by-step instructions and additional options for using Redoc, refer to the [Redoc deployment guide](./deployment/intro.md).

View File

@ -19,7 +19,7 @@ Or you can install `redoc-cli` using [npx](https://www.freecodecamp.org/news/npm
### Install Redoc CLI with yarn ### Install Redoc CLI with yarn
To install the `redoc-cli` package globally with yarn: To install the `redoc-cli` package globally with yarn:
```bash ```bash
yarn global add redoc-cli yarn global add redoc-cli
@ -27,7 +27,7 @@ yarn global add redoc-cli
### Install Redoc with npm ### Install Redoc with npm
To install the `redoc-cli` package globally with npm: To install the `redoc-cli` package globally with npm:
```bash ```bash
npm i -g redoc-cli npm i -g redoc-cli
@ -50,9 +50,9 @@ The CLI includes the following commands:
- **`redoc-cli serve [spec]`:** Starts a local server with Redoc. You must include the required parameter, spec, which is - **`redoc-cli serve [spec]`:** Starts a local server with Redoc. You must include the required parameter, spec, which is
a reference to an OpenAPI definition. Options include: a reference to an OpenAPI definition. Options include:
- `--ssr`: Implements a server-side rendering model. - `--ssr`: Implements a server-side rendering model.
- `--watch`: Automatically reloads the server while you edit your OpenAPI definition. - `--watch`: Automatically reloads the server while you edit your OpenAPI definition.
- `--options`: Customizes your output using [Redoc options](https://redoc.ly/docs/api-reference-docs/configuration/). - `--options`: Customizes your output using [Redoc options](https://redocly.com/docs/api-reference-docs/configuration/).
To add nested options, use dot notation. To add nested options, use dot notation.
- **`redoc-cli bundle [spec]`:** Bundles `spec` and Redoc into a zero-dependency HTML file. Options include: - **`redoc-cli bundle [spec]`:** Bundles `spec` and Redoc into a zero-dependency HTML file. Options include:
- `-t` or `--template`: Uses custom [Handlebars](https://handlebarsjs.com/) templates to render your OpenAPI definition. - `-t` or `--template`: Uses custom [Handlebars](https://handlebarsjs.com/) templates to render your OpenAPI definition.

View File

@ -37,7 +37,7 @@ title: Using the Redoc HTML element
:::attention Running Redoc locally requires an HTTP server :::attention Running Redoc locally requires an HTTP server
Loading local OpenAPI definitions is impossible without running a web server because of issues with Loading local OpenAPI definitions is impossible without running a web server because of issues with
[same-origin policy](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy) and [same-origin policy](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy) and
other security reasons. other security reasons.
::: :::
### Running Redoc locally ### Running Redoc locally
@ -49,7 +49,7 @@ If you want to view your Redoc output locally, you can simulate an HTTP server.
Redocly OpenAPI CLI is an open source command-line tool that includes a command Redocly OpenAPI CLI is an open source command-line tool that includes a command
for simulating an HTTP server to provide a preview of your OpenAPI definition locally. for simulating an HTTP server to provide a preview of your OpenAPI definition locally.
If you have [OpenAPI CLI](https://redoc.ly/docs/cli/#installation-and-usage) installed, `cd` into your If you have [OpenAPI CLI](https://redocly.com/docs/cli/#installation-and-usage) installed, `cd` into your
project directory and run the following command: project directory and run the following command:
```bash ```bash
@ -107,9 +107,9 @@ You can install Redoc using one of the following package managers:
If you do not have a `package.json` file in your project directory, If you do not have a `package.json` file in your project directory,
you need to add one by initializing npm or yarn in your project. Use the command `npm init` for npm, you need to add one by initializing npm or yarn in your project. Use the command `npm init` for npm,
or `yarn init` for yarn. These initialization commands will lead you through the process or `yarn init` for yarn. These initialization commands will lead you through the process
of creating a `package.json` file in your project. of creating a `package.json` file in your project.
For more information, see For more information, see
[Creating a package.json file](https://docs.npmjs.com/creating-a-package-json-file) [Creating a package.json file](https://docs.npmjs.com/creating-a-package-json-file)
in the npm documentation or [Yarn init](https://classic.yarnpkg.com/en/docs/cli/init/) in the npm documentation or [Yarn init](https://classic.yarnpkg.com/en/docs/cli/init/)
in the yarn documentation. in the yarn documentation.
@ -118,7 +118,7 @@ in the yarn documentation.
### Install Redoc with yarn ### Install Redoc with yarn
After navigating to your project directory in your terminal, use the following command: After navigating to your project directory in your terminal, use the following command:
```bash ```bash
yarn add redoc yarn add redoc
@ -126,7 +126,7 @@ yarn add redoc
### Install Redoc with npm ### Install Redoc with npm
After navigating to your project directory in your terminal, use the following command: After navigating to your project directory in your terminal, use the following command:
```bash ```bash
npm i redoc npm i redoc
@ -188,7 +188,7 @@ Redoc.init(specOrSpecUrl, options, element, callback)
``` ```
- `specOrSpecUrl`: Either a JSON object with the OpenAPI definition or a URL to the - `specOrSpecUrl`: Either a JSON object with the OpenAPI definition or a URL to the
definition in JSON or YAML format. definition in JSON or YAML format.
- `options`: See [options object](https://redoc.ly/docs/api-reference-docs/configuration/) reference. - `options`: See [options object](https://redocly.com/docs/api-reference-docs/configuration/) reference.
- `element`: DOM element Redoc will be inserted into. - `element`: DOM element Redoc will be inserted into.
- `callback`(optional): Callback to be called after Redoc has been fully rendered. - `callback`(optional): Callback to be called after Redoc has been fully rendered.
It is also called on errors with `error` as the first argument. It is also called on errors with `error` as the first argument.
@ -211,4 +211,4 @@ Redoc.init('dist.yaml', {
scrollYOffset: 50 scrollYOffset: 50
}, document.getElementById('redoc-container')) }, document.getElementById('redoc-container'))
</script> </script>
``` ```

View File

@ -25,7 +25,7 @@ The following options are supported:
## Before you start ## Before you start
You will need an OpenAPI definition. For testing purposes, you can use one of the following sample OpenAPI definitions: You will need an OpenAPI definition. For testing purposes, you can use one of the following sample OpenAPI definitions:
- OpenAPI 3.0 - OpenAPI 3.0
- [Rebilly Users OpenAPI Definition](https://raw.githubusercontent.com/Rebilly/api-definitions/main/openapi/users.yaml) - [Rebilly Users OpenAPI Definition](https://raw.githubusercontent.com/Rebilly/api-definitions/main/openapi/users.yaml)
- [Swagger Petstore Sample OpenAPI Definition](https://petstore3.swagger.io/api/v3/openapi.json) - [Swagger Petstore Sample OpenAPI Definition](https://petstore3.swagger.io/api/v3/openapi.json)
@ -33,7 +33,7 @@ You will need an OpenAPI definition. For testing purposes, you can use one of th
- [Thingful OpenAPI Definition](https://raw.githubusercontent.com/thingful/openapi-spec/master/spec/swagger.yaml) - [Thingful OpenAPI Definition](https://raw.githubusercontent.com/thingful/openapi-spec/master/spec/swagger.yaml)
- [Fitbit Plus OpenAPI Definition](https://raw.githubusercontent.com/TwineHealth/TwineDeveloperDocs/master/spec/swagger.yaml) - [Fitbit Plus OpenAPI Definition](https://raw.githubusercontent.com/TwineHealth/TwineDeveloperDocs/master/spec/swagger.yaml)
For more information on the OpenAPI specification, refer to the [Learning OpenAPI 3](https://redoc.ly/docs/resources/learning-openapi/) For more information on the OpenAPI specification, refer to the [Learning OpenAPI 3](https://redocly.com/docs/resources/learning-openapi/)
section in the documentation. section in the documentation.
## Live demo online ## Live demo online

View File

@ -42,7 +42,7 @@ Or you can pass your OpenAPI definition as an object, using the following format
## Optional - Pass options ## Optional - Pass options
Options can be passed into the RedocStandalone component to alter how it renders. Options can be passed into the RedocStandalone component to alter how it renders.
For example: For example:
@ -56,8 +56,8 @@ For example:
/> />
``` ```
For more information on configuration options, refer to the For more information on configuration options, refer to the
[Configuration options for Reference docs](https://redoc.ly/docs/api-reference-docs/configuration/) [Configuration options for Reference docs](https://redocly.com/docs/api-reference-docs/configuration/)
section of the documentation. Options available for Redoc are noted, section of the documentation. Options available for Redoc are noted,
"Supported in Redoc CE". "Supported in Redoc CE".

View File

@ -1,4 +1,4 @@
# ReDoc vendor extensions # Redoc vendor extensions
You can use the following [vendor extensions](https://swagger.io/specification/#specificationExtensions) with Redoc. You can use the following [vendor extensions](https://swagger.io/specification/#specificationExtensions) with Redoc.
@ -194,8 +194,8 @@ Extends the OpenAPI [Operation Object](http://swagger.io/specification/#operatio
| :------------- | :------: | :---------- | | :------------- | :------: | :---------- |
| x-codeSamples | [ [Code Sample Object](#codeSampleObject) ] | A list of code samples associated with operation | | x-codeSamples | [ [Code Sample Object](#codeSampleObject) ] | A list of code samples associated with operation |
###### How to use with ReDoc ###### How to use with Redoc
`x-codeSamples` are rendered on the right panel in ReDoc. `x-codeSamples` are rendered on the right panel in Redoc.
#### <a name="codeSampleObject"></a>Code Sample Object #### <a name="codeSampleObject"></a>Code Sample Object
Operation code sample Operation code sample
@ -230,8 +230,8 @@ Extends the OpenAPI [Parameter Object](http://swagger.io/specification/#paramete
| :------------- | :------: | :---------- | | :------------- | :------: | :---------- |
| x-examples | [Example Object](http://swagger.io/specification/#exampleObject) | Object that contains examples for the request. Applies when `in` is `body` and mime-type is `application/json` | | x-examples | [Example Object](http://swagger.io/specification/#exampleObject) | Object that contains examples for the request. Applies when `in` is `body` and mime-type is `application/json` |
###### How to use with ReDoc ###### How to use with Redoc
`x-examples` are rendered in the JSON tab on the right panel in ReDoc. `x-examples` are rendered in the JSON tab on the right panel in Redoc.
### Response Object vendor extensions ### Response Object vendor extensions
Extends the OpenAPI [Response Object](https://swagger.io/specification/#responseObject) Extends the OpenAPI [Response Object](https://swagger.io/specification/#responseObject)
@ -241,7 +241,7 @@ Extends the OpenAPI [Response Object](https://swagger.io/specification/#response
| :------------- | :------: | :---------- | | :------------- | :------: | :---------- |
| x-summary | string | a short summary of the response | | x-summary | string | a short summary of the response |
###### How to use with ReDoc ###### How to use with Redoc
If specified, you can use `x-summary` as the response button text, with description rendered under the button. If specified, you can use `x-summary` as the response button text, with description rendered under the button.
### Schema Object ### Schema Object
@ -252,21 +252,21 @@ Extends the OpenAPI [Schema Object](http://swagger.io/specification/#schemaObjec
| :------------- | :------: | :---------- | | :------------- | :------: | :---------- |
| x-nullable | boolean | marks schema as a nullable | | x-nullable | boolean | marks schema as a nullable |
###### How to use with ReDoc ###### How to use with Redoc
Schemas marked as `x-nullable` are marked in ReDoc with the label Nullable Schemas marked as `x-nullable` are marked in Redoc with the label Nullable
#### x-extendedDiscriminator #### x-extendedDiscriminator
**ATTENTION**: This is a ReDoc-specific vendor extension, and is not supported by other tools. **ATTENTION**: This is a Redoc-specific vendor extension, and is not supported by other tools.
| Field Name | Type | Description | | Field Name | Type | Description |
| :------------- | :------: | :---------- | | :------------- | :------: | :---------- |
| x-extendedDiscriminator | string | specifies extended discriminator | | x-extendedDiscriminator | string | specifies extended discriminator |
###### How to use with ReDoc ###### How to use with Redoc
ReDoc uses this vendor extension to solve name-clash issues with the standard `discriminator`. Redoc uses this vendor extension to solve name-clash issues with the standard `discriminator`.
Value of this field specifies the field which will be used as a extended discriminator. Value of this field specifies the field which will be used as a extended discriminator.
ReDoc displays definition with selectpicker using which user can select value of the `x-extendedDiscriminator`-marked field. Redoc displays definition with selectpicker using which user can select value of the `x-extendedDiscriminator`-marked field.
ReDoc displays the definition derived from the current (using `allOf`) and has `enum` with only one value which is the same as the selected value of the field specified as `x-extendedDiscriminator`. Redoc displays the definition derived from the current (using `allOf`) and has `enum` with only one value which is the same as the selected value of the field specified as `x-extendedDiscriminator`.
###### x-extendedDiscriminator example ###### x-extendedDiscriminator example
@ -309,7 +309,7 @@ PayPalPayment:
In the example above, the names of definitions (`PayPalPayment`) are named differently than names in the payload (`paypal`) which is not supported by default `discriminator`. In the example above, the names of definitions (`PayPalPayment`) are named differently than names in the payload (`paypal`) which is not supported by default `discriminator`.
#### x-additionalPropertiesName #### x-additionalPropertiesName
**ATTENTION**: This is a ReDoc-specific vendor extension, and is not supported by other tools. **ATTENTION**: This is a Redoc-specific vendor extension, and is not supported by other tools.
Extends the `additionalProperties` property of the schema object. Extends the `additionalProperties` property of the schema object.
@ -317,8 +317,8 @@ Extends the `additionalProperties` property of the schema object.
| :------------- | :------: | :---------- | | :------------- | :------: | :---------- |
| x-additionalPropertiesName | string | descriptive name of additional properties keys | | x-additionalPropertiesName | string | descriptive name of additional properties keys |
###### How to use with ReDoc ###### How to use with Redoc
ReDoc uses this extension to display a more descriptive property name in objects with `additionalProperties` when viewing the property list with an `object`. Redoc uses this extension to display a more descriptive property name in objects with `additionalProperties` when viewing the property list with an `object`.
###### x-additionalPropertiesName example ###### x-additionalPropertiesName example
@ -337,7 +337,7 @@ Player:
``` ```
#### x-explicitMappingOnly #### x-explicitMappingOnly
**ATTENTION**: This is ReDoc-specific vendor extension, and is not supported by other tools. **ATTENTION**: This is Redoc-specific vendor extension, and is not supported by other tools.
Extends the `discriminator` property of the schema object. Extends the `discriminator` property of the schema object.
@ -345,8 +345,8 @@ Extends the `discriminator` property of the schema object.
| :------------- | :------: | :---------- | | :------------- | :------: | :---------- |
| x-explicitMappingOnly | boolean | limit the discriminator selectpicker to the explicit mappings only | | x-explicitMappingOnly | boolean | limit the discriminator selectpicker to the explicit mappings only |
###### How to use with ReDoc ###### How to use with Redoc
ReDoc uses this extension to filter the `discriminator` mappings shown in the selectpicker. Redoc uses this extension to filter the `discriminator` mappings shown in the selectpicker.
When set to `true`, the selectpicker will only list the the explicitly defined mappings. When `false`, the default behavior is kept, i.e. explicit and implicit mappings will be shown. When set to `true`, the selectpicker will only list the the explicitly defined mappings. When `false`, the default behavior is kept, i.e. explicit and implicit mappings will be shown.
###### x-explicitMappingOnly example ###### x-explicitMappingOnly example

65
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "redoc", "name": "redoc",
"version": "2.0.0-rc.63", "version": "2.0.0-rc.65",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "redoc", "name": "redoc",
"version": "2.0.0-rc.63", "version": "2.0.0-rc.65",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@redocly/openapi-core": "^1.0.0-beta.54", "@redocly/openapi-core": "^1.0.0-beta.54",
@ -15,16 +15,16 @@
"decko": "^1.2.0", "decko": "^1.2.0",
"dompurify": "^2.2.8", "dompurify": "^2.2.8",
"eventemitter3": "^4.0.7", "eventemitter3": "^4.0.7",
"json-pointer": "^0.6.1", "json-pointer": "^0.6.2",
"lunr": "^2.3.9", "lunr": "^2.3.9",
"mark.js": "^8.11.1", "mark.js": "^8.11.1",
"marked": "^4.0.10", "marked": "^4.0.10",
"mobx-react": "^7.2.0", "mobx-react": "^7.2.0",
"openapi-sampler": "^1.1.1", "openapi-sampler": "^1.2.1",
"path-browserify": "^1.0.1", "path-browserify": "^1.0.1",
"perfect-scrollbar": "^1.5.1", "perfect-scrollbar": "^1.5.1",
"polished": "^4.1.3", "polished": "^4.1.3",
"prismjs": "^1.24.1", "prismjs": "^1.27.0",
"prop-types": "^15.7.2", "prop-types": "^15.7.2",
"react-tabs": "^3.2.2", "react-tabs": "^3.2.2",
"slugify": "~1.4.7", "slugify": "~1.4.7",
@ -8209,9 +8209,9 @@
"dev": true "dev": true
}, },
"node_modules/follow-redirects": { "node_modules/follow-redirects": {
"version": "1.14.7", "version": "1.14.8",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz",
"integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==", "integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==",
"dev": true, "dev": true,
"funding": [ "funding": [
{ {
@ -12463,9 +12463,9 @@
"dev": true "dev": true
}, },
"node_modules/json-pointer": { "node_modules/json-pointer": {
"version": "0.6.1", "version": "0.6.2",
"resolved": "https://registry.npmjs.org/json-pointer/-/json-pointer-0.6.1.tgz", "resolved": "https://registry.npmjs.org/json-pointer/-/json-pointer-0.6.2.tgz",
"integrity": "sha512-3OvjqKdCBvH41DLpV4iSt6v2XhZXV1bPB4OROuknvUXI7ZQNofieCPkmE26stEJ9zdQuvIxDHCuYhfgxFAAs+Q==", "integrity": "sha512-vLWcKbOaXlO+jvRy4qNd+TI1QUPZzfJj1tpJ3vAXDych5XJf93ftpUKe5pKCrzyIIwgBJcOcCVRUfqQP25afBw==",
"dependencies": { "dependencies": {
"foreach": "^2.0.4" "foreach": "^2.0.4"
} }
@ -14191,12 +14191,12 @@
} }
}, },
"node_modules/openapi-sampler": { "node_modules/openapi-sampler": {
"version": "1.1.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/openapi-sampler/-/openapi-sampler-1.1.1.tgz", "resolved": "https://registry.npmjs.org/openapi-sampler/-/openapi-sampler-1.2.1.tgz",
"integrity": "sha512-WAFsl5SPYuhQwaMTDFOcKhnEY1G1rmamrMiPmJdqwfl1lr81g63/befcsN9BNi0w5/R0L+hfcUj13PANEBeLgg==", "integrity": "sha512-mHrYmyvcLD0qrfqPkPRBAL2z16hGT2rW0d0B7nklfoTcc3pmkJLkSZlKSeFgerUM41E5c7jlxf0Y19xrM7mWQQ==",
"dependencies": { "dependencies": {
"@types/json-schema": "^7.0.7", "@types/json-schema": "^7.0.7",
"json-pointer": "^0.6.1" "json-pointer": "0.6.2"
} }
}, },
"node_modules/optionator": { "node_modules/optionator": {
@ -15036,9 +15036,12 @@
} }
}, },
"node_modules/prismjs": { "node_modules/prismjs": {
"version": "1.25.0", "version": "1.27.0",
"resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.25.0.tgz", "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.27.0.tgz",
"integrity": "sha512-WCjJHl1KEWbnkQom1+SzftbtXMKQoezOCYs5rECqMN+jP+apI7ftoflyqigqzopSO3hMhTEb0mFClA8lkolgEg==" "integrity": "sha512-t13BGPUlFDR7wRB5kQDG4jjl7XeuH6jbJGt11JHPL96qwsEHNX2+68tFXqc1/k+/jALsbSWJKUOT/hcYAZ5LkA==",
"engines": {
"node": ">=6"
}
}, },
"node_modules/process": { "node_modules/process": {
"version": "0.11.10", "version": "0.11.10",
@ -25358,9 +25361,9 @@
"dev": true "dev": true
}, },
"follow-redirects": { "follow-redirects": {
"version": "1.14.7", "version": "1.14.8",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz",
"integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==", "integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==",
"dev": true "dev": true
}, },
"foreach": { "foreach": {
@ -28493,9 +28496,9 @@
"dev": true "dev": true
}, },
"json-pointer": { "json-pointer": {
"version": "0.6.1", "version": "0.6.2",
"resolved": "https://registry.npmjs.org/json-pointer/-/json-pointer-0.6.1.tgz", "resolved": "https://registry.npmjs.org/json-pointer/-/json-pointer-0.6.2.tgz",
"integrity": "sha512-3OvjqKdCBvH41DLpV4iSt6v2XhZXV1bPB4OROuknvUXI7ZQNofieCPkmE26stEJ9zdQuvIxDHCuYhfgxFAAs+Q==", "integrity": "sha512-vLWcKbOaXlO+jvRy4qNd+TI1QUPZzfJj1tpJ3vAXDych5XJf93ftpUKe5pKCrzyIIwgBJcOcCVRUfqQP25afBw==",
"requires": { "requires": {
"foreach": "^2.0.4" "foreach": "^2.0.4"
} }
@ -29794,12 +29797,12 @@
} }
}, },
"openapi-sampler": { "openapi-sampler": {
"version": "1.1.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/openapi-sampler/-/openapi-sampler-1.1.1.tgz", "resolved": "https://registry.npmjs.org/openapi-sampler/-/openapi-sampler-1.2.1.tgz",
"integrity": "sha512-WAFsl5SPYuhQwaMTDFOcKhnEY1G1rmamrMiPmJdqwfl1lr81g63/befcsN9BNi0w5/R0L+hfcUj13PANEBeLgg==", "integrity": "sha512-mHrYmyvcLD0qrfqPkPRBAL2z16hGT2rW0d0B7nklfoTcc3pmkJLkSZlKSeFgerUM41E5c7jlxf0Y19xrM7mWQQ==",
"requires": { "requires": {
"@types/json-schema": "^7.0.7", "@types/json-schema": "^7.0.7",
"json-pointer": "^0.6.1" "json-pointer": "0.6.2"
} }
}, },
"optionator": { "optionator": {
@ -30430,9 +30433,9 @@
} }
}, },
"prismjs": { "prismjs": {
"version": "1.25.0", "version": "1.27.0",
"resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.25.0.tgz", "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.27.0.tgz",
"integrity": "sha512-WCjJHl1KEWbnkQom1+SzftbtXMKQoezOCYs5rECqMN+jP+apI7ftoflyqigqzopSO3hMhTEb0mFClA8lkolgEg==" "integrity": "sha512-t13BGPUlFDR7wRB5kQDG4jjl7XeuH6jbJGt11JHPL96qwsEHNX2+68tFXqc1/k+/jALsbSWJKUOT/hcYAZ5LkA=="
}, },
"process": { "process": {
"version": "0.11.10", "version": "0.11.10",

View File

@ -1,6 +1,6 @@
{ {
"name": "redoc", "name": "redoc",
"version": "2.0.0-rc.63", "version": "2.0.0-rc.65",
"description": "ReDoc", "description": "ReDoc",
"repository": { "repository": {
"type": "git", "type": "git",
@ -145,16 +145,16 @@
"decko": "^1.2.0", "decko": "^1.2.0",
"dompurify": "^2.2.8", "dompurify": "^2.2.8",
"eventemitter3": "^4.0.7", "eventemitter3": "^4.0.7",
"json-pointer": "^0.6.1", "json-pointer": "^0.6.2",
"lunr": "^2.3.9", "lunr": "^2.3.9",
"mark.js": "^8.11.1", "mark.js": "^8.11.1",
"marked": "^4.0.10", "marked": "^4.0.10",
"mobx-react": "^7.2.0", "mobx-react": "^7.2.0",
"openapi-sampler": "^1.1.1", "openapi-sampler": "^1.2.1",
"path-browserify": "^1.0.1", "path-browserify": "^1.0.1",
"perfect-scrollbar": "^1.5.1", "perfect-scrollbar": "^1.5.1",
"polished": "^4.1.3", "polished": "^4.1.3",
"prismjs": "^1.24.1", "prismjs": "^1.27.0",
"prop-types": "^15.7.2", "prop-types": "^15.7.2",
"react-tabs": "^3.2.2", "react-tabs": "^3.2.2",
"slugify": "~1.4.7", "slugify": "~1.4.7",
@ -191,6 +191,9 @@
"modulePathIgnorePatterns": [ "modulePathIgnorePatterns": [
"/benchmark/" "/benchmark/"
], ],
"snapshotSerializers": [
"enzyme-to-json/serializer"
],
"moduleNameMapper": { "moduleNameMapper": {
"\\.(css|less)$": "<rootDir>/src/empty.js" "\\.(css|less)$": "<rootDir>/src/empty.js"
} }

View File

@ -1,5 +1,6 @@
import styled from '../styled-components'; import styled from '../styled-components';
import { darken } from 'polished'; import { darken } from 'polished';
import { deprecatedCss } from './mixins';
export const OneOfList = styled.div` export const OneOfList = styled.div`
margin: 0 0 3px 0; margin: 0 0 3px 0;
@ -14,7 +15,7 @@ export const OneOfLabel = styled.span`
} }
`; `;
export const OneOfButton = styled.button<{ active: boolean }>` export const OneOfButton = styled.button<{ active: boolean; deprecated: boolean }>`
display: inline-block; display: inline-block;
margin-right: 10px; margin-right: 10px;
margin-bottom: 5px; margin-bottom: 5px;
@ -28,6 +29,8 @@ export const OneOfButton = styled.button<{ active: boolean }>`
box-shadow: 0 0 0 1px ${props => props.theme.colors.primary.main}; box-shadow: 0 0 0 1px ${props => props.theme.colors.primary.main};
} }
${({ deprecated }) => (deprecated && deprecatedCss) || ''};
${props => { ${props => {
if (props.active) { if (props.active) {
return ` return `

View File

@ -11,7 +11,7 @@ export function ArrayItemDetails({ schema }: { schema: SchemaModel }) {
return ( return (
<Wrapper> <Wrapper>
[ items [ items
{schema.displayFormat && <TypeFormat>{` &lt;${schema.displayFormat}&gt; `}</TypeFormat>} {schema.displayFormat && <TypeFormat> &lt;{schema.displayFormat} &gt;</TypeFormat>}
<ConstraintsView constraints={schema.constraints} /> <ConstraintsView constraints={schema.constraints} />
<Pattern schema={schema} /> <Pattern schema={schema} />
{schema.items && <ArrayItemDetails schema={schema.items} />} ] {schema.items && <ArrayItemDetails schema={schema.items} />} ]

View File

@ -6,6 +6,7 @@ import {
OneOfLabel, OneOfLabel,
OneOfList, OneOfList,
} from '../../common-elements/schema'; } from '../../common-elements/schema';
import { Badge } from '../../common-elements/shelfs';
import { SchemaModel } from '../../services/models'; import { SchemaModel } from '../../services/models';
import { Schema, SchemaProps } from './Schema'; import { Schema, SchemaProps } from './Schema';
@ -20,7 +21,11 @@ export class OneOfButton extends React.Component<OneOfButtonProps> {
render() { render() {
const { idx, schema, subSchema } = this.props; const { idx, schema, subSchema } = this.props;
return ( return (
<StyledOneOfButton active={idx === schema.activeOneOf} onClick={this.activateOneOf}> <StyledOneOfButton
deprecated={subSchema.deprecated}
active={idx === schema.activeOneOf}
onClick={this.activateOneOf}
>
{subSchema.title || subSchema.typePrefix + subSchema.displayType} {subSchema.title || subSchema.typePrefix + subSchema.displayType}
</StyledOneOfButton> </StyledOneOfButton>
); );
@ -50,6 +55,9 @@ export class OneOfSchema extends React.Component<SchemaProps> {
<OneOfButton key={subSchema.pointer} schema={schema} subSchema={subSchema} idx={idx} /> <OneOfButton key={subSchema.pointer} schema={schema} subSchema={subSchema} idx={idx} />
))} ))}
</OneOfList> </OneOfList>
<div>
{oneOf[schema.activeOneOf].deprecated && <Badge type="warning">Deprecated</Badge>}
</div>
<Schema {...this.props} schema={oneOf[schema.activeOneOf]} /> <Schema {...this.props} schema={oneOf[schema.activeOneOf]} />
</div> </div>
); );

View File

@ -70,7 +70,7 @@ export class SecurityRequirement extends React.PureComponent<SecurityRequirement
security.schemes.map(scheme => { security.schemes.map(scheme => {
return ( return (
<SecurityRequirementAndWrap key={scheme.id}> <SecurityRequirementAndWrap key={scheme.id}>
<Link to={scheme.sectionId}>{scheme.id}</Link> <Link to={scheme.sectionId}>{scheme.displayName}</Link>
{scheme.scopes.length > 0 && ' ('} {scheme.scopes.length > 0 && ' ('}
{scheme.scopes.map(scope => ( {scheme.scopes.map(scope => (
<ScopeName key={scope}>{scope}</ScopeName> <ScopeName key={scope}>{scope}</ScopeName>

View File

@ -73,7 +73,7 @@ export class SecurityDefs extends React.PureComponent<SecurityDefsProps> {
<MiddlePanel> <MiddlePanel>
<H2> <H2>
<ShareLink to={scheme.sectionId} /> <ShareLink to={scheme.sectionId} />
{scheme.id} {scheme.displayName}
</H2> </H2>
<Markdown source={scheme.description || ''} /> <Markdown source={scheme.description || ''} />
<StyledMarkdownBlock> <StyledMarkdownBlock>

View File

@ -56,7 +56,7 @@ const StyledStickySidebar = styled.div<{ open?: boolean }>`
const FloatingButton = styled.div` const FloatingButton = styled.div`
outline: none; outline: none;
user-select: none; user-select: none;
background-color: #f2f2f2; background-color: ${({ theme }) => theme.fab.backgroundColor};
color: ${props => props.theme.colors.primary.main}; color: ${props => props.theme.colors.primary.main};
display: none; display: none;
cursor: pointer; cursor: pointer;
@ -74,6 +74,9 @@ const FloatingButton = styled.div`
width: 60px; width: 60px;
height: 60px; height: 60px;
padding: 0 20px; padding: 0 20px;
svg {
color: ${({ theme }) => theme.fab.color};
}
@media print { @media print {
display: none; display: none;
@ -140,9 +143,11 @@ export class StickyResponsiveSidebar extends React.Component<
> >
{this.props.children} {this.props.children}
</StyledStickySidebar> </StyledStickySidebar>
<FloatingButton onClick={this.toggleNavMenu}> {!this.context.hideFab && (
<AnimatedChevronButton open={open} /> <FloatingButton onClick={this.toggleNavMenu}>
</FloatingButton> <AnimatedChevronButton open={open} />
</FloatingButton>
)}
</> </>
); );
} }

View File

@ -6,18 +6,19 @@ import * as React from 'react';
import { OneOfSchema, Schema } from '../'; import { OneOfSchema, Schema } from '../';
import { OpenAPIParser, SchemaModel } from '../../services'; import { OpenAPIParser, SchemaModel } from '../../services';
import { RedocNormalizedOptions } from '../../services/RedocNormalizedOptions'; import { RedocNormalizedOptions } from '../../services/RedocNormalizedOptions';
import { withTheme } from '../testProviders';
const options = new RedocNormalizedOptions({}); const options = new RedocNormalizedOptions({});
describe('Components', () => { describe('Components', () => {
describe('SchemaView', () => { describe('SchemaView', () => {
const parser = new OpenAPIParser(
{ openapi: '3.0', info: { title: 'test', version: '0' }, paths: {} },
undefined,
options,
);
describe('OneOf', () => { describe('OneOf', () => {
it('should pass down skipReadOnly/skipReadWrite to nested oneOf', () => { it('should pass down skipReadOnly/skipReadWrite to nested oneOf', () => {
const parser = new OpenAPIParser(
{ openapi: '3.0', info: { title: 'test', version: '0' }, paths: {} },
undefined,
options,
);
const schema = new SchemaModel( const schema = new SchemaModel(
parser, parser,
{ oneOf: [{ type: 'string' }, { type: 'integer' }] }, { oneOf: [{ type: 'string' }, { type: 'integer' }] },
@ -38,5 +39,19 @@ describe('Components', () => {
expect(schemaViewElement.props.skipReadOnly).toBeTruthy(); expect(schemaViewElement.props.skipReadOnly).toBeTruthy();
}); });
}); });
describe('OneOf deprecated', () => {
const schema = new SchemaModel(
parser,
{ oneOf: [{ type: 'string', deprecated: true }, { type: 'integer' }] },
'',
options,
);
it('should match snapshot', () => {
const component = shallow(withTheme(<Schema schema={schema} />));
expect(component.render()).toMatchSnapshot();
});
});
}); });
}); });

View File

@ -80,6 +80,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"expandSingleSchemaField": false, "expandSingleSchemaField": false,
"generatedPayloadSamplesMaxDepth": 10, "generatedPayloadSamplesMaxDepth": 10,
"hideDownloadButton": false, "hideDownloadButton": false,
"hideFab": false,
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
@ -187,6 +188,10 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
}, },
}, },
"extensionsHook": undefined, "extensionsHook": undefined,
"fab": Object {
"backgroundColor": "#f2f2f2",
"color": "#0065FB",
},
"logo": Object { "logo": Object {
"gutter": "2px", "gutter": "2px",
"maxHeight": "260px", "maxHeight": "260px",
@ -321,6 +326,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"expandSingleSchemaField": false, "expandSingleSchemaField": false,
"generatedPayloadSamplesMaxDepth": 10, "generatedPayloadSamplesMaxDepth": 10,
"hideDownloadButton": false, "hideDownloadButton": false,
"hideFab": false,
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
@ -428,6 +434,10 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
}, },
}, },
"extensionsHook": undefined, "extensionsHook": undefined,
"fab": Object {
"backgroundColor": "#f2f2f2",
"color": "#0065FB",
},
"logo": Object { "logo": Object {
"gutter": "2px", "gutter": "2px",
"maxHeight": "260px", "maxHeight": "260px",
@ -538,6 +548,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"expandSingleSchemaField": false, "expandSingleSchemaField": false,
"generatedPayloadSamplesMaxDepth": 10, "generatedPayloadSamplesMaxDepth": 10,
"hideDownloadButton": false, "hideDownloadButton": false,
"hideFab": false,
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
@ -645,6 +656,10 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
}, },
}, },
"extensionsHook": undefined, "extensionsHook": undefined,
"fab": Object {
"backgroundColor": "#f2f2f2",
"color": "#0065FB",
},
"logo": Object { "logo": Object {
"gutter": "2px", "gutter": "2px",
"maxHeight": "260px", "maxHeight": "260px",
@ -820,6 +835,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"expandSingleSchemaField": false, "expandSingleSchemaField": false,
"generatedPayloadSamplesMaxDepth": 10, "generatedPayloadSamplesMaxDepth": 10,
"hideDownloadButton": false, "hideDownloadButton": false,
"hideFab": false,
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
@ -927,6 +943,10 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
}, },
}, },
"extensionsHook": undefined, "extensionsHook": undefined,
"fab": Object {
"backgroundColor": "#f2f2f2",
"color": "#0065FB",
},
"logo": Object { "logo": Object {
"gutter": "2px", "gutter": "2px",
"maxHeight": "260px", "maxHeight": "260px",
@ -1061,6 +1081,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"expandSingleSchemaField": false, "expandSingleSchemaField": false,
"generatedPayloadSamplesMaxDepth": 10, "generatedPayloadSamplesMaxDepth": 10,
"hideDownloadButton": false, "hideDownloadButton": false,
"hideFab": false,
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
@ -1168,6 +1189,10 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
}, },
}, },
"extensionsHook": undefined, "extensionsHook": undefined,
"fab": Object {
"backgroundColor": "#f2f2f2",
"color": "#0065FB",
},
"logo": Object { "logo": Object {
"gutter": "2px", "gutter": "2px",
"maxHeight": "260px", "maxHeight": "260px",
@ -1278,6 +1303,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"expandSingleSchemaField": false, "expandSingleSchemaField": false,
"generatedPayloadSamplesMaxDepth": 10, "generatedPayloadSamplesMaxDepth": 10,
"hideDownloadButton": false, "hideDownloadButton": false,
"hideFab": false,
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
@ -1385,6 +1411,10 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
}, },
}, },
"extensionsHook": undefined, "extensionsHook": undefined,
"fab": Object {
"backgroundColor": "#f2f2f2",
"color": "#0065FB",
},
"logo": Object { "logo": Object {
"gutter": "2px", "gutter": "2px",
"maxHeight": "260px", "maxHeight": "260px",
@ -1518,6 +1548,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"expandSingleSchemaField": false, "expandSingleSchemaField": false,
"generatedPayloadSamplesMaxDepth": 10, "generatedPayloadSamplesMaxDepth": 10,
"hideDownloadButton": false, "hideDownloadButton": false,
"hideFab": false,
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
@ -1625,6 +1656,10 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
}, },
}, },
"extensionsHook": undefined, "extensionsHook": undefined,
"fab": Object {
"backgroundColor": "#f2f2f2",
"color": "#0065FB",
},
"logo": Object { "logo": Object {
"gutter": "2px", "gutter": "2px",
"maxHeight": "260px", "maxHeight": "260px",
@ -1797,6 +1832,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"expandSingleSchemaField": false, "expandSingleSchemaField": false,
"generatedPayloadSamplesMaxDepth": 10, "generatedPayloadSamplesMaxDepth": 10,
"hideDownloadButton": false, "hideDownloadButton": false,
"hideFab": false,
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
@ -1904,6 +1940,10 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
}, },
}, },
"extensionsHook": undefined, "extensionsHook": undefined,
"fab": Object {
"backgroundColor": "#f2f2f2",
"color": "#0065FB",
},
"logo": Object { "logo": Object {
"gutter": "2px", "gutter": "2px",
"maxHeight": "260px", "maxHeight": "260px",
@ -2038,6 +2078,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"expandSingleSchemaField": false, "expandSingleSchemaField": false,
"generatedPayloadSamplesMaxDepth": 10, "generatedPayloadSamplesMaxDepth": 10,
"hideDownloadButton": false, "hideDownloadButton": false,
"hideFab": false,
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
@ -2145,6 +2186,10 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
}, },
}, },
"extensionsHook": undefined, "extensionsHook": undefined,
"fab": Object {
"backgroundColor": "#f2f2f2",
"color": "#0065FB",
},
"logo": Object { "logo": Object {
"gutter": "2px", "gutter": "2px",
"maxHeight": "260px", "maxHeight": "260px",
@ -2255,6 +2300,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"expandSingleSchemaField": false, "expandSingleSchemaField": false,
"generatedPayloadSamplesMaxDepth": 10, "generatedPayloadSamplesMaxDepth": 10,
"hideDownloadButton": false, "hideDownloadButton": false,
"hideFab": false,
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
@ -2362,6 +2408,10 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
}, },
}, },
"extensionsHook": undefined, "extensionsHook": undefined,
"fab": Object {
"backgroundColor": "#f2f2f2",
"color": "#0065FB",
},
"logo": Object { "logo": Object {
"gutter": "2px", "gutter": "2px",
"maxHeight": "260px", "maxHeight": "260px",

View File

@ -0,0 +1,53 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Components SchemaView OneOf deprecated should match snapshot 1`] = `
<div>
<span
class="sc-kfYoZR juYXUf"
>
One of
</span>
<div
class="sc-dlMDgC EoFth"
>
<button
class="sc-fKgJPI iEPbLk"
>
string
</button>
<button
class="sc-fKgJPI bpjiHN"
>
integer
</button>
</div>
<div>
<span
class="sc-bqGGPW eSYQnm"
type="warning"
>
Deprecated
</span>
</div>
<div>
<div>
<div>
<span
class="sc-fbIWvP sc-FRrlG CMpTe bBFKjV"
/>
<span
class="sc-fbIWvP sc-fXazdy CMpTe gJKPGC"
>
string
</span>
</div>
<div>
<div
class="sc-iBzEeX sc-cOifOu dFWqin hjSJYo"
/>
</div>
</div>
</div>
</div>
`;

View File

@ -1,11 +1,11 @@
import * as React from 'react'; import * as React from 'react';
import { ThemeProvider } from 'styled-components'; import { ThemeProvider } from 'styled-components';
import defaultTheme from '../theme'; import defaultTheme, { resolveTheme } from '../theme';
export default class TestThemeProvider extends React.Component { export default class TestThemeProvider extends React.Component {
render() { render() {
return ( return (
<ThemeProvider theme={defaultTheme}> <ThemeProvider theme={resolveTheme(defaultTheme)}>
{React.Children.only(this.props.children as any)} {React.Children.only(this.props.children as any)}
</ThemeProvider> </ThemeProvider>
); );

View File

@ -152,7 +152,7 @@ export class MenuStore {
} else { } else {
if (id.startsWith(SECURITY_SCHEMES_SECTION_PREFIX)) { if (id.startsWith(SECURITY_SCHEMES_SECTION_PREFIX)) {
item = this.flatItems.find(i => SECURITY_SCHEMES_SECTION_PREFIX.startsWith(i.id)); item = this.flatItems.find(i => SECURITY_SCHEMES_SECTION_PREFIX.startsWith(i.id));
this.activate(item); this.activateAndScroll(item, false);
} }
this.scroll.scrollIntoViewBySelector(`[${SECTION_ATTR}="${id}"]`); this.scroll.scrollIntoViewBySelector(`[${SECTION_ATTR}="${id}"]`);
} }

View File

@ -191,6 +191,9 @@ export class OpenAPIParser {
const { $ref, ...rest } = ref; const { $ref, ...rest } = ref;
const keys = Object.keys(rest); const keys = Object.keys(rest);
if (keys.length === 0) { if (keys.length === 0) {
if (this.isRef(resolved)) {
return this.shallowDeref(resolved);
}
return resolved; return resolved;
} }
if ( if (

View File

@ -54,6 +54,7 @@ export interface RedocRawOptions {
ignoreNamedSchemas?: string[] | string; ignoreNamedSchemas?: string[] | string;
hideSchemaPattern?: boolean; hideSchemaPattern?: boolean;
generatedPayloadSamplesMaxDepth?: number; generatedPayloadSamplesMaxDepth?: number;
hideFab?: boolean;
} }
export function argValueToBoolean(val?: string | boolean, defaultValue?: boolean): boolean { export function argValueToBoolean(val?: string | boolean, defaultValue?: boolean): boolean {
@ -255,6 +256,7 @@ export class RedocNormalizedOptions {
ignoreNamedSchemas: Set<string>; ignoreNamedSchemas: Set<string>;
hideSchemaPattern: boolean; hideSchemaPattern: boolean;
generatedPayloadSamplesMaxDepth: number; generatedPayloadSamplesMaxDepth: number;
hideFab: boolean;
constructor(raw: RedocRawOptions, defaults: RedocRawOptions = {}) { constructor(raw: RedocRawOptions, defaults: RedocRawOptions = {}) {
raw = { ...defaults, ...raw }; raw = { ...defaults, ...raw };
@ -326,5 +328,6 @@ export class RedocNormalizedOptions {
RedocNormalizedOptions.normalizeGeneratedPayloadSamplesMaxDepth( RedocNormalizedOptions.normalizeGeneratedPayloadSamplesMaxDepth(
raw.generatedPayloadSamplesMaxDepth, raw.generatedPayloadSamplesMaxDepth,
); );
this.hideFab = argValueToBoolean(raw.hideFab);
} }
} }

View File

@ -26,5 +26,16 @@ describe('Models', () => {
expect(parser.shallowDeref(schemaOrRef)).toMatchSnapshot(); expect(parser.shallowDeref(schemaOrRef)).toMatchSnapshot();
}); });
test('should correct resolve double $ref if no need sibling', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const spec = require('./fixtures/3.1/schemaDefinition.json');
parser = new OpenAPIParser(spec, undefined, opts);
const schemaOrRef: Referenced<OpenAPIParameter> = {
$ref: '#/components/schemas/Parent',
};
expect(parser.deref(schemaOrRef, false, true)).toMatchSnapshot();
});
}); });
}); });

View File

@ -1,5 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Models Schema should correct resolve double $ref if no need sibling 1`] = `
Object {
"properties": Object {
"test": Object {
"type": "string",
},
},
"type": "object",
}
`;
exports[`Models Schema should hoist oneOfs when mergin allOf 1`] = ` exports[`Models Schema should hoist oneOfs when mergin allOf 1`] = `
Object { Object {
"oneOf": Array [ "oneOf": Array [

View File

@ -0,0 +1,54 @@
{
"openapi": "3.1.0",
"info": {
"title": "Schema definition double $ref",
"version": "1.0.0"
},
"servers": [
{
"url": "example.com"
}
],
"tags": [
{
"name": "test",
"x-displayName": "The test Model",
"description": "<SchemaDefinition schemaRef=\"#/components/schemas/Parent\" />\n"
}
],
"paths": {
"/newPath": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Child"
}
}
}
},
"responses": {
"200": {
"description": "all ok"
}
}
}
}
},
"components": {
"schemas": {
"Parent": {
"$ref": "#/components/schemas/Child"
},
"Child": {
"type": "object",
"properties": {
"test": {
"type": "string"
}
}
}
}
}
}

View File

@ -40,5 +40,13 @@ describe('Models', () => {
expect(schema.oneOf).toHaveLength(2); expect(schema.oneOf).toHaveLength(2);
expect(schema.displayType).toBe('(Array of strings or numbers) or string'); expect(schema.displayType).toBe('(Array of strings or numbers) or string');
}); });
test('schemaDefinition should resolve double ref', () => {
const spec = require('../fixtures/3.1/schemaDefinition.json');
parser = new OpenAPIParser(spec, undefined, opts);
const schema = new SchemaModel(parser, spec.components.schemas.Parent, '', opts);
expect(schema.fields).toHaveLength(1);
expect(schema.pointer).toBe('#/components/schemas/Child');
});
}); });
}); });

View File

@ -5,6 +5,7 @@ import { OpenAPIParser } from '../OpenAPIParser';
export interface SecurityScheme extends OpenAPISecurityScheme { export interface SecurityScheme extends OpenAPISecurityScheme {
id: string; id: string;
sectionId: string; sectionId: string;
displayName: string;
scopes: string[]; scopes: string[];
} }
@ -23,11 +24,13 @@ export class SecurityRequirementModel {
console.warn(`Non existing security scheme referenced: ${id}. Skipping`); console.warn(`Non existing security scheme referenced: ${id}. Skipping`);
return undefined; return undefined;
} }
const displayName = scheme['x-displayName'] || id;
return { return {
...scheme, ...scheme,
id, id,
sectionId: SECURITY_SCHEMES_SECTION_PREFIX + id, sectionId: SECURITY_SCHEMES_SECTION_PREFIX + id,
displayName,
scopes, scopes,
}; };
}) })

View File

@ -7,6 +7,7 @@ export class SecuritySchemeModel {
sectionId: string; sectionId: string;
type: OpenAPISecurityScheme['type']; type: OpenAPISecurityScheme['type'];
description: string; description: string;
displayName: string;
apiKey?: { apiKey?: {
name: string; name: string;
in: OpenAPISecurityScheme['in']; in: OpenAPISecurityScheme['in'];
@ -27,6 +28,7 @@ export class SecuritySchemeModel {
this.id = id; this.id = id;
this.sectionId = SECURITY_SCHEMES_SECTION_PREFIX + id; this.sectionId = SECURITY_SCHEMES_SECTION_PREFIX + id;
this.type = info.type; this.type = info.type;
this.displayName = info['x-displayName'] || id;
this.description = info.description || ''; this.description = info.description || '';
if (info.type === 'apiKey') { if (info.type === 'apiKey') {
this.apiKey = { this.apiKey = {

View File

@ -162,6 +162,10 @@ const defaultTheme: ThemeInterface = {
codeBlock: { codeBlock: {
backgroundColor: ({ rightPanel }) => darken(0.1, rightPanel.backgroundColor), backgroundColor: ({ rightPanel }) => darken(0.1, rightPanel.backgroundColor),
}, },
fab: {
backgroundColor: '#f2f2f2',
color: '#0065FB',
},
}; };
export default defaultTheme; export default defaultTheme;
@ -338,6 +342,10 @@ export interface ResolvedThemeInterface {
codeBlock: { codeBlock: {
backgroundColor: string; backgroundColor: string;
}; };
fab: {
backgroundColor: string;
color: string;
};
extensionsHook?: (name: string, props: any) => string; extensionsHook?: (name: string, props: any) => string;
} }