|
1 | 1 | <!DOCTYPE html>
|
2 | 2 | <html>
|
| 3 | +<!-- |
| 4 | +This layout can be used to generate API docs from an OpenAPI specification. |
| 5 | +
|
| 6 | +When creating a new API reference page, you can specify these optional params in the front matter: |
| 7 | +- sourcefile: The path to the OpenAPI specification file (YAML or JSON) relative to the page. Default: ./openapi.json |
| 8 | +- backLink: The path to the page to link to in the top left corner. Default: Parent page |
| 9 | +
|
| 10 | +Here's what the file structure should look like to use this template: |
| 11 | +<containing-folder>/ |
| 12 | +├---------api-reference/ |
| 13 | +| └------<spec-file-name> (default openapi.json) |
| 14 | +| |
| 15 | +├---------api-reference.md |
| 16 | +| |
| 17 | +└---------<other files> |
| 18 | +
|
| 19 | +Here's what the api-reference.md front matter should look like: |
| 20 | +--- |
| 21 | +Title: <API Name> |
| 22 | +linkTitle: API reference |
| 23 | +layout: apireference |
| 24 | +type: page |
| 25 | +params: |
| 26 | + sourcefile: ./<spec-file-name> (optional - only specify if not using ./openapi.json) |
| 27 | + backLink: <path-to-page> (optional - only specify if not using the parent page) |
| 28 | +--- |
| 29 | +
|
| 30 | +Example usage for the Redis Cloud API with all params set: |
| 31 | +--- |
| 32 | +Title: Redis Cloud API |
| 33 | +linkTitle: API reference |
| 34 | +layout: apireference |
| 35 | +type: page |
| 36 | +params: |
| 37 | + sourcefile: ./openapi.json |
| 38 | + backLink: operate/rc/api |
| 39 | +--- |
| 40 | +--> |
3 | 41 |
|
4 | 42 | <head>
|
5 |
| - <title>Redis Cloud API</title> |
| 43 | + <title>{{ .Title }}</title> |
6 | 44 | {{ partial "scss.html" (dict "path" "scss/style.scss") }}
|
7 | 45 | {{ partial "css.html" (dict "path" "css/index.css") }}
|
8 |
| - {{ $relref := printf "%s%s" .Site.BaseURL "operate/rc/api/" }} |
| 46 | + {{ $relref := .Parent.Permalink }} |
| 47 | + {{ if .Params.backLink}} |
| 48 | + {{ $relref = printf "%s%s" .Site.BaseURL .Params.backLink }} |
| 49 | + {{ end }} |
9 | 50 | <!-- needed for adaptive design -->
|
10 | 51 | <!-- <link rel="preload" href="/public/scss/style.min.65324e4de191c292ee8b6f4f0ebf01320e8c4bc8623b04e9dfad322ebb490b31.css" as="style">
|
11 | 52 | <link href="/public/scss/style.min.65324e4de191c292ee8b6f4f0ebf01320e8c4bc8623b04e9dfad322ebb490b31.css" rel="stylesheet" integrity="">
|
|
62 | 103 | <body>
|
63 | 104 | <div>
|
64 | 105 | <redoc
|
65 |
| - spec-url='./openapi.json' |
| 106 | + spec-url='{{ .Params.sourcefile | default "./openapi.json" }}' |
66 | 107 | scroll-y-offset='#apiReferenceHeader'
|
67 | 108 | json-sample-expand-level=all
|
68 | 109 | sort-operations-alphabetically="true"
|
|
0 commit comments