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

Supporting merging all user defined languageTabs options #952

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
207 changes: 134 additions & 73 deletions demo/docs/customization/languagetabs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,98 +8,159 @@ description: Configuring language tabs for the API Demo Panel.

## Overview

The Docusaurus OpenAPI docs plugin comes with support for 8 languages which you can render as code snippets on an API operation page. The languages currently supported are:
The Docusaurus OpenAPI docs plugin comes with support for 18 languages which you can render as code snippets on an API operation page.


### Supported Languages and Variants

The languages currently supported are:

| Language | Prism Highlighter | Variants |
| ------------ | ----------------- | ------------------------------------------------ |
| `curl` | bash | `curl`\* |
| `python` | python | `requests`\*, `http.client` |
| `go` | go | `native`\* |
| `nodejs` | javascript | `axios`\*, `native` |
| `ruby` | ruby | `net::http`\* |
| `csharp` | csharp | `restsharp`\*, `httpclient` |
| `php` | php | `curl`\*, `guzzle`, `pecl_http`, `http_request2` |
| `java` | java | `okhttp`\*, `unirest` |
| `powershell` | powershell | `RestMethod`\* |
| `curl` | bash | `curl` |
| `python` | python | `requests`, `http.client` |
| `go` | go | `native` |
| `nodejs` | javascript | `axios`, `native`, `request`, `unirest` |
| `ruby` | ruby | `net::http` |
| `csharp` | csharp | `httpclient`, `restsharp` |
| `php` | php | `curl`, `guzzle`, `pecl_http`, `http_request2` |
| `java` | java | `okhttp`, `unirest` |
| `powershell` | powershell | `restmethod` |
| `dart` | dart | `dio`, `http` |
| `javascript` | javascript | `fetch`, `jquery`, `xhr` |
| `kotlin` | kotlin | `okhttp` |
| `c` | c_cpp | `libcurl` |
| `objective-c`| objectivec | `nsurlsession` |
| `ocaml` | ocaml | `cohttp` |
| `r` | r | `httr`, `rcurl` |
| `rust` | rust | `reqwest` |
| `swift` | swift | `urlsession` |

\* Default variant
### Defining languages in languageTabs

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:

| Name | Type | Default | Description |
| ----------------- | --------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `highlight` | `string` | `null` | The syntax highlighting ruleset to use. |
| `language` | `string` | `null` | The programming language to use when generating the example. |
| `logoClass` | `string` | `null` | The CSS class to be added to render the appropriate logo. |
| `variant` | `string` | `null` | The language variant to use when generating the example, see below for a tip on where you can find the variants. |
| `options` | `object` | `null` | _Optional:_ Set of options for language customization. See below for common options, exact options depend on language. |
| `followRedirect` | `string` | `null` | _Optional:_ Follow redirects when handling requests. |
| `trimRequestBody` | `string` | `null` | _Optional:_ Trim request body fields. |
| `indentCount` | `integer` | _language dependent_ | _Optional:_ Alter the number of indentations used when generating the examples. |
| `indentType` | `string` | _language dependent_ | _Optional:_ Alter the type of indentation used, `Space` or `Tab` are acceptable options for this. |
| `highlight` | `string` | _language dependent_ | _Optional:_ The prism syntax highlighting language to use. |
| `logoClass` | `string` | _language dependent_ | _Optional:_ The CSS class suffix to be added to render the appropriate logo. |
| `variant` | `string` | _language dependent_ | _Optional:_ The default language variant to use when generating the code snippet. |
| `variants` | `array` | _language dependent_ | _Optional:_ An array of strings representing the variants available for the language. |
| `options` | `object` | _language dependent_ | _Optional:_ Set of options for language customization. See below for common options, exact options depend on language. |
|     `followRedirect` | `boolean` | _language dependent_ | _Optional:_ Follow redirects when handling requests. |
|     `trimRequestBody` | `boolean` | _language dependent_ | _Optional:_ Trim request body fields. |
|     `indentCount` | `integer` | _language dependent_ | _Optional:_ Alter the number of indentations used when generating the examples. |
|     `indentType` | `string` | _language dependent_ | _Optional:_ Alter the type of indentation used, `Space` or `Tab` are acceptable options for this. |

:::tip
The order you define the languages under `languageTabs` is the order in which they will appear once rendered.
The order you define the languages under `languageTabs` is the order in which they will appear once rendered. You may also choose a subset of languages and variants to include.
:::

:::danger
Individual languages may only be defined once, meaning you cannot define a language multiple times with different variants. For example, you cannot define both `nodejs\axios` and `nodejs\unirest` or `python/requests` and `python/http.client`.
:::

## Demo Languages
### Languages in Demo

The demo site disables the `ruby` and `php` languages using the following `languageTabs` config object.
The demo site defines all supported languages using the following `languageTabs` config object.

:::note
Only the `language` property is required. The `highlight` and `logoClass` properties are provided only for reference.
:::

```js
languageTabs: [
{
highlight: "bash",
language: "curl",
logoClass: "bash",
},
{
highlight: "python",
language: "python",
logoClass: "python",
variant: "requests",
},
{
highlight: "go",
language: "go",
logoClass: "go",
},
{
highlight: "javascript",
language: "nodejs",
logoClass: "nodejs",
variant: "axios",
},
{
highlight: "ruby",
language: "ruby",
logoClass: "ruby",
},
{
highlight: "csharp",
language: "csharp",
logoClass: "csharp",
variant: "httpclient",
},
{
highlight: "php",
language: "php",
logoClass: "php",
},
{
highlight: "java",
language: "java",
logoClass: "java",
variant: "unirest",
},
{
highlight: "powershell",
language: "powershell",
logoClass: "powershell",
},
],
languageTabs: [
{
highlight: "python",
language: "python",
logoClass: "python",
},
{
highlight: "bash",
language: "curl",
logoClass: "bash",
},
{
highlight: "csharp",
language: "csharp",
logoClass: "csharp",
},
{
highlight: "go",
language: "go",
logoClass: "go",
},
{
highlight: "javascript",
language: "nodejs",
logoClass: "nodejs",
},
{
highlight: "ruby",
language: "ruby",
logoClass: "ruby",
},
{
highlight: "php",
language: "php",
logoClass: "php",
},
{
highlight: "java",
language: "java",
logoClass: "java",
variant: "unirest",
},
{
highlight: "powershell",
language: "powershell",
logoClass: "powershell",
},
{
highlight: "dart",
language: "dart",
logoClass: "dart",
},
{
highlight: "javascript",
language: "javascript",
logoClass: "javascript",
},
{
highlight: "c",
language: "c",
logoClass: "c",
},
{
highlight: "objective-c",
language: "objective-c",
logoClass: "objective-c",
},
{
highlight: "ocaml",
language: "ocaml",
logoClass: "ocaml",
},
{
highlight: "r",
language: "r",
logoClass: "r",
},
{
highlight: "swift",
language: "swift",
logoClass: "swift",
},
{
highlight: "kotlin",
language: "kotlin",
logoClass: "kotlin",
},
{
highlight: "rust",
language: "rust",
logoClass: "rust",
},
],
```
Loading
Loading