question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using $ref in an example block

See original GitHub issue

Hi, I’m using a $ref in an example block and everything works almost exactly how I want except for this one behavior.

The definition looks like this:

SubscriptionType:
    [...]
    example:
      autorenew: true
      cycle_days: 30
      id: 33920
      name: "my 1337 subscription"
      terms:
        - $ref: '#/components/schemas/SubscriptionTypeTerm/example'

But the output looks like this

{
    "autorenew": true,
    "cycle_days": 30,
    "id": 33920,
    "name": "my 1337 subscription",
    "terms": [{
        "description": "every 3 months",
        "enabled": true,
        "id": 33922,
        "name": "3monthly",
        "num_cycles": 3,
        "subscription_type_id": 33920,
        "$$ref": "#/components/schemas/SubscriptionTypeTerm/example"
    }]
}

It’s everything that I want except I don’t want the "$$ref": "#/components/schemas/SubscriptionTypeTerm/example" at the bottom of the object.

Am I missing something obvious or am I using refs incorrectly?

Possibly related: https://github.com/swagger-api/swagger-ui/issues/4021

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
silkentrancecommented, Aug 14, 2018

So what you actually want is to include the examples from your $ref to be included in your example, and recursively so.

0reactions
krishamoudcommented, Sep 4, 2018

So I found a way around this. Instead of adding a completely separate example block I just add examples to every field in the component definition.

Example:

Below works

SubscriptionType:
      type: object
      properties:
        store_id: 
          type: integer
        name:
          type: string
          example: my 1337 subscription
        cycle_days:
          type: integer
          example: 30
        terms:
          type: array
          items:
            $ref: '#/components/schemas/SubscriptionTypeTerm'
        auto_renew:
          type: boolean
          example: false
        id:
          type: integer
          example: 33920

Below results in $$ref

SubscriptionType:
    [...]
    example:
      autorenew: true
      cycle_days: 30
      id: 33920
      name: "my 1337 subscription"
      terms:
        - $ref: '#/components/schemas/SubscriptionTypeTerm/example'
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to correct a #REF! error - Microsoft Support
The #REF! error shows when a formula refers to a cell that's not valid. This happens most often when cells that were referenced...
Read more >
Manipulating the DOM with Refs - React Docs
How to access a DOM node managed by React with the ref attribute; How the ref JSX attribute ... In this example, clicking...
Read more >
Get a Ref to BlockListBlock in the block editor - Stack Overflow
You should use useRef instead, createRef won't save the value between re-renders. You can't track it on the useEffect .
Read more >
Cross-referencing with Sphinx - Read the Docs
The numref role is used to reference numbered elements of your documentation. For example, tables and images. To activate numbered references, add this...
Read more >
reStructuredText Primer - Sphinx documentation
Literal code blocks (ref) are introduced by ending a paragraph with the special marker :: . The literal block must be indented (and,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found