Last updated

codeSamples

Configure the code samples generated from your OpenAPI description.

Options

OptionTypeDescription
languages[language object]REQUIRED. Array of language objects, one per language. The samples are displayed in the order that they are listed. Default array value is:
[
  { lang: curl },
  { lang: JavaScript },
  { lang: Node.js },
  { lang: Python },
  { lang: Java },
  { lang: C# },
  { lang: PHP },
  { lang: Go },
  { lang: Ruby },
  { lang: R },
  { lang: Payload }
]
skipOptionalParametersbooleanExcludes optional parameters (cookies, headers, query params) from the generated code samples. Defaults to false.

Language object

OptionTypeDescription
langstringREQUIRED. Sets the language to create code samples for. Supported values: curl, C#, C#+Newtonsoft, Go, Java, Java8+Apache, JavaScript, Node.js, PHP, Python, R, Ruby
labelstringCustom label to use for the generated code sample. In the Request samples section of your reference docs, the code sample tab uses the custom label instead of the default lang value.

Examples

The following example generates code samples for five tech stacks, including only the required parameters:

openapi:
  codeSamples:
    skipOptionalParameters: true
    languages:
      - lang: 'curl'
        label: 'cURL'
      - lang: 'JavaScript'
        label: 'JS'
      - lang: 'Go'
      - lang: 'Ruby'
      - lang: 'Java8+Apache'
        label: 'Java 8'

With this configuration, each endpoint has code samples in these five languages generated and displayed in the documentation.

  • openapi - Learn more about using openapi configuration.

Resources