Overview
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 , 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 |
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 |
---|---|---|---|
language | string | null | The programming language to use when generating the example. |
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. |
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.
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
.
Languages in Demo
The demo site defines all supported languages using the following languageTabs
config object.
Only the language
property is required. The highlight
and logoClass
properties are provided only for reference.
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",
},
],