Skip to content

Commit fe0c219

Browse files
authored
Add documentation for languageTabs and request method labels. (#256)
* Add documentation for languageTabs and request method labels. * Make requested changes. * Remove PowerShell from example config - not yet supported.
1 parent 86ba916 commit fe0c219

4 files changed

Lines changed: 231 additions & 1 deletion

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
id: languagetabs
3+
hide_title: true
4+
sidebar_label: Language Tabs
5+
title: Language Tabs
6+
description: Configuring language tabs for the API Demo Panel.
7+
---
8+
9+
## Overview
10+
11+
The Docusaurus OpenAPI docs plugin comes with support for 7 languages which you can render as tabs on an API method page. Currently supported languages are:
12+
13+
1. `bash`/`cURL`
14+
1. `python`/`requests`
15+
1. `go`/`native`
16+
1. `nodejs`/`axios`
17+
1. `ruby`/`Net::HTTP`
18+
1. `c#`/`RestSharp`
19+
1. `php`/`cURL`
20+
21+
The enabled languages are defined for your site in a `languageTabs` array in the `themeConfig` object in your config file. If you do not define this configuration item all of the languages above are enabled. The config schema for each language is as follows:
22+
23+
| Name | Type | Default | Description |
24+
| ----------------- | --------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------- |
25+
| `highlight` | `string` | `null` | The syntax highlighting ruleset to use. |
26+
| `language` | `string` | `null` | The programming language to use when generating the example. |
27+
| `logoClass` | `string` | `null` | The CSS class to be added to render the appropriate logo. |
28+
| `variant` | `string` | `null` | The language variant to use when generating the example, see below for a tip on where you can find the variants. |
29+
| `options` | `object` | `null` | _Optional:_ Set of options for language customization. See below for common options, exact options depend on language. |
30+
| `followRedirect` | `string` | `null` | _Optional:_ Follow redirects when handling requests. |
31+
| `trimRequestBody` | `string` | `null` | _Optional:_ Trim request body fields. |
32+
| `indentCount` | `integer` | _language dependent_ | _Optional:_ Alter the number of indentations used when generating the examples. |
33+
| `indentType` | `string` | _language dependent_ | _Optional:_ Alter the type of indentation used, `Space` or `Tab` are acceptable options for this. |
34+
35+
## Demo Languages
36+
37+
The demo site disables the `ruby` and `php` languages using the following `languageTabs` config object.
38+
39+
```js
40+
languageTabs: [
41+
{
42+
highlight: "bash",
43+
language: "curl",
44+
logoClass: "bash",
45+
},
46+
{
47+
highlight: "python",
48+
language: "python",
49+
logoClass: "python",
50+
},
51+
{
52+
highlight: "go",
53+
language: "go",
54+
logoClass: "go",
55+
},
56+
{
57+
highlight: "javascript",
58+
language: "nodejs",
59+
logoClass: "nodejs",
60+
},
61+
//{
62+
// highlight: "ruby",
63+
// language: "ruby",
64+
// logoClass: "ruby",
65+
//},
66+
{
67+
highlight: "csharp",
68+
language: "csharp",
69+
logoClass: "csharp",
70+
},
71+
// {
72+
// highlight: "php",
73+
// language: "php",
74+
// logoClass: "php",
75+
// },
76+
],
77+
```

demo/docs/customization/styling.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
id: styling
3+
hide_title: true
4+
sidebar_label: Styling
5+
title: Styling
6+
description: Styling tweaks for docusaurus-openapi-docs.
7+
---
8+
9+
## Overview
10+
11+
The Docusaurus OpenAPI docs plugin comes with Infima based styling as standard. In the demos on this site you'll see some features which are not included in the default styling including the request method labels before each request. To add these to your site you can use one of the two options outlined below.
12+
13+
The method labels are pure CSS and as a result there are few, if any, limits on how you style / present these on your site.
14+
15+
## Demo Styling
16+
17+
The demo site uses the following CSS to add coloured labels to each request including the name of the method. Adding this to your site's custom CSS will replicate exactly the demo-site's label aesthetic using your site's variables.
18+
19+
```css
20+
/* API Menu Items */
21+
.api-method > .menu__link {
22+
  align-items: center;
23+
  justify-content: start;
24+
}
25+
26+
.api-method > .menu__link::before {
27+
  width: 50px;
28+
  height: 20px;
29+
  font-size: 12px;
30+
  line-height: 20px;
31+
  text-transform: uppercase;
32+
  font-weight: 600;
33+
  border-radius: 0.25rem;
34+
  border: 1px solid;
35+
  margin-right: var(--ifm-spacing-horizontal);
36+
  text-align: center;
37+
  flex-shrink: 0;
38+
  border-color: transparent;
39+
  color: white;
40+
}
41+
42+
.get > .menu__link::before {
43+
  content: "get";
44+
  background-color: var(--ifm-color-primary);
45+
}
46+
47+
.post > .menu__link::before {
48+
  content: "post";
49+
  background-color: var(--openapi-code-green);
50+
}
51+
52+
.delete > .menu__link::before {
53+
  content: "del";
54+
  background-color: var(--openapi-code-red);
55+
}
56+
57+
.put > .menu__link::before {
58+
  content: "put";
59+
  background-color: var(--openapi-code-blue);
60+
}
61+
62+
.patch > .menu__link::before {
63+
  content: "patch";
64+
  background-color: var(--openapi-code-orange);
65+
}
66+
67+
.head > .menu__link::before {
68+
  content: "head";
69+
  background-color: var(--ifm-color-secondary-darkest);
70+
}
71+
```
72+
73+
## Alternative Styling
74+
75+
In [this issue](https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/249) community member [@ThomasHeartman](https://github.com/thomasheartman) shared some alternative CSS with better contrast and some other stylistic tweaks to the method labels. The CSS to replicate this is below:
76+
77+
```css
78+
/* Sidebar Method labels */
79+
.api-method > .menu__link {
80+
align-items: center;
81+
justify-content: start;
82+
}
83+
84+
.api-method > .menu__link::before {
85+
width: 50px;
86+
height: 20px;
87+
font-size: 12px;
88+
line-height: 20px;
89+
text-transform: uppercase;
90+
font-weight: 600;
91+
border-radius: 0.25rem;
92+
border: 1px solid;
93+
border-inline-start-width: 5px;
94+
margin-right: var(--ifm-spacing-horizontal);
95+
text-align: center;
96+
flex-shrink: 0;
97+
}
98+
99+
.get > .menu__link::before {
100+
content: "get";
101+
background-color: var(--ifm-color-info-contrast-background);
102+
color: var(--ifm-color-info-contrast-foreground);
103+
border-color: var(--ifm-color-info-dark);
104+
}
105+
106+
.post > .menu__link::before {
107+
content: "post";
108+
background-color: var(--ifm-color-success-contrast-background);
109+
color: var(--ifm-color-success-contrast-foreground);
110+
border-color: var(--ifm-color-success-dark);
111+
}
112+
113+
.delete > .menu__link::before {
114+
content: "del";
115+
background-color: var(--ifm-color-danger-contrast-background);
116+
color: var(--ifm-color-danger-contrast-foreground);
117+
border-color: var(--ifm-color-danger-dark);
118+
}
119+
120+
.put > .menu__link::before {
121+
content: "put";
122+
background-color: var(--ifm-color-warning-contrast-background);
123+
color: var(--ifm-color-warning-contrast-foreground);
124+
border-color: var(--ifm-color-warning-dark);
125+
}
126+
127+
.patch > .menu__link::before {
128+
content: "patch";
129+
background-color: var(--ifm-color-success-contrast-background);
130+
color: var(--ifm-color-success-contrast-foreground);
131+
border-color: var(--ifm-color-success-dark);
132+
}
133+
134+
.head > .menu__link::before {
135+
content: "head";
136+
background-color: var(--ifm-color-secondary-contrast-background);
137+
color: var(--ifm-color-secondary-contrast-foreground);
138+
border-color: var(--ifm-color-secondary-dark);
139+
}
140+
```

demo/docs/intro.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ plugins: [
103103
],
104104
```
105105

106-
### Configurating the theme
106+
### Configuring the theme
107107

108108
To use the theme you"ll need to define it under `themes` in `docusaurus.config.js`:
109109

demo/sidebars.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ const sidebars = {
3333
type: "doc",
3434
id: "versioning",
3535
},
36+
{
37+
type: "category",
38+
label: "Customization",
39+
link: {
40+
type: "generated-index",
41+
},
42+
items: [
43+
{
44+
type: "autogenerated",
45+
dirName: "customization",
46+
},
47+
],
48+
},
3649
],
3750
petstore: [
3851
{

0 commit comments

Comments
 (0)