Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSOD]Adds new quickstart doc #1718

Merged
merged 9 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 185 additions & 0 deletions docs/quickstart/html.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
---
title: Redoc HTML element
---

# ReDoc HTML element
HCloward marked this conversation as resolved.
Show resolved Hide resolved

## TL;DR Final code example

```html
<!DOCTYPE html>
<html>
<head>
<title>ReDoc</title>
<!-- needed for adaptive design -->
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">

<!--
ReDoc doesn't change outer page styles
-->
<style>
body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<redoc spec-url='http://petstore.swagger.io/v2/swagger.json'></redoc>
<script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
</body>
</html>

```

:::attention Running Redoc locally requires an HTTP server
Loading local OpenAPI specifications is impossible without running a web-server because of issues with
HCloward marked this conversation as resolved.
Show resolved Hide resolved
[same-origin policy](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy) and
other security reasons.
:::

### Running ReDoc locally

If you want to view your ReDoc output locally, you can simulate an HTTP server.
HCloward marked this conversation as resolved.
Show resolved Hide resolved

#### Using Python

If you have [Python3](https://www.python.org/downloads/) installed, `cd` into your
HCloward marked this conversation as resolved.
Show resolved Hide resolved
project directory and run the following command:

```python
python3 -m http.server
```

#### Using Node.js

If you have [Node.js](https://nodejs.org/en/download/) installed, install `http-server`
using the following npm command:

```bash
npm install -g http-server
```

Then, `cd` into your project directory and run the following command:

```node
http-server
```

## Step 1 - Install ReDoc

You can install ReDoc using one of the following package managers,
HCloward marked this conversation as resolved.
Show resolved Hide resolved
[npm](https://docs.npmjs.com/about-npm) or [yarn](https://classic.yarnpkg.com/en/docs/getting-started).
HCloward marked this conversation as resolved.
Show resolved Hide resolved

:::attention Initialize your package manager
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,
or `yarn init` for yarn. These initialization commands will lead you through the process
of creating a `package.json` file in your project.

For more information, see
[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 yarn documentation.
:::

### Install with yarn
HCloward marked this conversation as resolved.
Show resolved Hide resolved

To install ReDoc using yarn, after navigating to your project directory in your terminal,
HCloward marked this conversation as resolved.
Show resolved Hide resolved
use the following command:

```sh
yarn add redoc
```

### Install with npm
HCloward marked this conversation as resolved.
Show resolved Hide resolved

To install ReDoc using npm, after navigating to your project directory in your terminal,
HCloward marked this conversation as resolved.
Show resolved Hide resolved
use the following command:

```sh
npm i redoc
```

## Step 2 - Reference the ReDoc script

You can reference the ReDoc script using either a link to the files hosted on a CDN
or the files located in your node modules folder.
HCloward marked this conversation as resolved.
Show resolved Hide resolved

### CDN link

To reference the ReDoc script with a CDN link:

```html
<script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
HCloward marked this conversation as resolved.
Show resolved Hide resolved
```

### Node modules link

To reference the ReDoc script with a node modules link:

```html
<script src="node_modules/redoc/bundles/redoc.standalone.js"> </script>
```

## Step 3 - Add the <redoc> element

You can add the <redoc> element to your html page and reference your OpenAPI
HCloward marked this conversation as resolved.
Show resolved Hide resolved
specification using a `spec-url` attribute, or you can initialize ReDoc using
HCloward marked this conversation as resolved.
Show resolved Hide resolved
a globally exposed ReDoc object.

### Using a `spec-url` attribute
HCloward marked this conversation as resolved.
Show resolved Hide resolved

To add the <redoc> element with a `spec-url` attribute:
HCloward marked this conversation as resolved.
Show resolved Hide resolved

```html
<redoc spec-url="url/to/your/spec"></redoc>
```

#### Examples

```html
<redoc spec-url="http://petstore.swagger.io/v2/swagger.json"></redoc>
```

You can also use a local file (JSON or YAML) in your project, for instance:

```html
<redoc spec-url="dist.json"></redoc>
```

### Using a ReDoc object

To add the <redoc> element with a globally exposed ReDoc object:

```js
Redoc.init(specOrSpecUrl, options, element, callback)
```
- `specOrSpecUrl`: Either a JSON object with OpenAPI specification or a URL to the
specification in JSON or YAML format.
- `options`: See [options object](https://redoc.ly/docs/api-reference-docs/configuration/) reference.
- `element`: DOM element ReDoc will be inserted into.
- `callback`(optional): Callback to be called after ReDoc has been fully rendered.
It is also called on errors with error as the first argument.
HCloward marked this conversation as resolved.
Show resolved Hide resolved

#### Examples

```html
<script>
Redoc.init('http://petstore.swagger.io/v2/swagger.json', {
scrollYOffset: 50
}, document.getElementById('redoc-container'))
</script>
```

You can also use a local file (JSON or YAML) in your project, for instance:

```html
<script>
Redoc.init('dist.yaml', {
scrollYOffset: 50
}, document.getElementById('redoc-container'))
</script>
```
23 changes: 23 additions & 0 deletions docs/quickstart/live-demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: Live demo
enableToc: false
---

# Before you start

You will need an OpenAPI specification. For testing purposes, you can use one of the following sample OpenAPI specifications:
HCloward marked this conversation as resolved.
Show resolved Hide resolved
- OpenAPI 3.0
- [Rebilly Users OpenAPI Specification](https://github.com/raw/Rebilly/api-definitions/master/openapi/users.yaml)
- [Swagger Petstore Sample OpenAPI Specification](https://petstore3.swagger.io/api/v3/openapi.json)
- OpenAPI 2.0
- [Thingful OpenAPI Specification](https://github.com/raw/thingful/openapi-spec/master/spec/swagger.yaml)
- [Fitbit Plus OpenAPI Specification](https://github.com/raw/TwineHealth/TwineDeveloperDocs/master/spec/swagger.yaml)

For more information on OpenAPI specifications see [Learning OpenAPI 3](https://redoc.ly/docs/resources/learning-openapi/).
HCloward marked this conversation as resolved.
Show resolved Hide resolved

## Live demo online

If you want to see how ReDoc will render your OpenAPI specification, you can try it out online at https://redocly.github.io/redoc/.

A version of the Swagger Petstore API is already displayed. Try with your own OpenAPI specification by
HCloward marked this conversation as resolved.
Show resolved Hide resolved
entering the URL for your specification and clicking the **TRY IT** button.
HCloward marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 8 additions & 0 deletions docs/sidebars.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
redoc:
- group: Quickstart
expanded: false
pages:
- label: Live demo
page: redoc/quickstart/live-demo.md
- label: ReDoc HTML element
page: redoc/quickstart/html.md