Ask a Question

Can I use $ref in examples?

piyushkurkure10
New Member

Can I use $ref in examples?

I want to use ref in example for a schema
My openapi code:

 

'200':
  description: The request is successful
  content:
     application/json:
         schema:
            $ref: '#/components/schemas/ResponseSchema'
         example:
            $ref: '#/components/examples/200Example'

 

but I get warning like: 
warning no-invalid-media-type-examples Example value must conform to the schema: must NOT have additional properties `$ref`. 
And the example properly matches the schema so no problem with that.

1 REPLY 1
HKosova
Moderator

Re: Can I use $ref in examples?

Replace "example" with "examples" (plural) as shown below:

'200':
  description: The request is successful
  content:
     application/json:
         schema:
            $ref: '#/components/schemas/ResponseSchema'
         examples:      # <------
            example1:   # <------ arbitrary name
               $ref: '#/components/examples/200Example'

...
components:
  examples:
    200Example:
      summary: A short summary of this example
      value:
        key1: value1
        key2: value2

 


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: