1

In Redocly, how is it possible to reference an external file in an x-codeSamples tag? The Redocly reference guide: https://redoc.ly/docs/api-reference-docs/vendor-extensions/redoc-supported-extensions/#x-codesamples

In the following example, the first case ('Example request') renders properly. The second case ('Schema'), renders only as "[object object]". Does this tag support $ref statements?

x-codeSamples:
    - lang: 'Example request'
      source: |
        PetStore.v1.Pet pet = new PetStore.v1.Pet();
        pet.setApiKey("your api key");
    - lang: 'Schema'
      source:
        $ref: ../components/schemas/Test_schema.yaml
ForEachLoop
  • 2,508
  • 3
  • 18
  • 28

2 Answers2

3

Not sure if you still need it, but you could try with the scheme definition tag, do something like:

x-codeSamples:
    - lang: 'Example request'
      source: |
        PetStore.v1.Pet pet = new PetStore.v1.Pet();
        pet.setApiKey("your api key");
    - lang: 'Schema'
      source: |
        <SchemaDefinition schemaRef="../components/schemas/Test_schema.yaml" />

Based on how SchemaDefinition is used in the Petstore example at https://github.com/Redocly/redoc/blob/master/demo/openapi.yaml

0

See also: Is there a way to import test files into redoc x-codeSamples source field?

The following should do the trick:

                label: 'Schema'
                source: {$ref: ../components/schemas/Test_schema.yaml}
Linda
  • 61
  • 5