Skip to main content

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:

LanguagePrism HighlighterVariants
curlbashcurl
pythonpythonrequests, http.client
gogonative
nodejsjavascriptaxios, native, request, unirest
rubyrubynet::http
csharpcsharphttpclient, restsharp
phpphpcurl, guzzle, pecl_http, http_request2
javajavaokhttp, unirest
powershellpowershellrestmethod
dartdartdio, http
javascriptjavascriptfetch, jquery, xhr
kotlinkotlinokhttp
cc_cpplibcurl
objective-cobjectivecnsurlsession
ocamlocamlcohttp
rrhttr, rcurl
rustrustreqwest
swiftswifturlsession

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:

NameTypeDefaultDescription
languagestringnullThe programming language to use when generating the example.
highlightstringlanguage dependentOptional: The prism syntax highlighting language to use.
logoClassstringlanguage dependentOptional: The CSS class suffix to be added to render the appropriate logo.
variantstringlanguage dependentOptional: The default language variant to use when generating the code snippet.
variantsarraylanguage dependentOptional: An array of strings representing the variants available for the language.
optionsobjectlanguage dependentOptional: Set of options for language customization. See below for common options, exact options depend on language.
    followRedirectbooleanlanguage dependentOptional: Follow redirects when handling requests.
    trimRequestBodybooleanlanguage dependentOptional: Trim request body fields.
    indentCountintegerlanguage dependentOptional: Alter the number of indentations used when generating the examples.
    indentTypestringlanguage dependentOptional: 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. 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.

Languages in Demo

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.

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",
},
],