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.

allow examples to be provided for each property in a typedef

See original GitHub issue

When I’m defining a schema consisting of types containing properties, it would be handy to specify the example values which should appear in the request & response examples that reference that type.

Given a type:

/**
 * A song
 * @typedef {object} Song
 * @property {string} title.required - The title
 * @property {string} artist - The artist
 * @property {number} year - The year - double
 */

I’d like some way (if it doesn’t already exist) to specify example values of “My Song”, “Artist X”, and “2021” for the 3 properties.

I may have an API GET /api/songs would automatically have a sample response like

[
  {
    "song": "My Song",
    "artist": "Artist X",
    "year": 2021,
  }
]

instead of

[
  {
    "song": "string",
    "artist": "string",
    "year": 0,
  }
]

Other APIs GET /api/song/:name and PUT /api/song could each benefit from those example values without duplicating those sample values in @example request and @example response blocks.

Eventually, I’d like to have types derived from Song using anyOf which would inherit those sample values for each property.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
paulishcommented, Oct 26, 2021

With release 1.6.7 you can do it this way: @param {string} page.query.required - Page number - json:{"minimum": 0, "example":2}

1reaction
kevinccbsgcommented, Apr 18, 2021

Hi @mmcfarland-novetta,

Yes, you are right 🤔 we still don’t have support for that. I will mark this as an enhancement to take a look at in future releases.

Read more comments on GitHub >

github_iconTop Results From Across the Web

typedef command - IBM
typedef command. Rational® Synergy supports type-dependent behaviors. For example, you can allow parallel versions for one type of object but not another.
Read more >
How to use the typedef struct in C - Educative.io
The C language contains the typedef keyword to allow users to provide alternative names for the primitive (e.g.,​ int) and user-defined​ (e.g struct)...
Read more >
Documentation - Advanced Types - TypeScript
In a mapped type, the new type transforms each property in the old type in the same way. For example, you can make...
Read more >
Typedef Task - Apache Ant
For property files each line defines a single data type in the format: ... or types that share the same classpath with multiple...
Read more >
Learn JSON Typedef in 5 Minutes
JSON Type Definition (aka “JSON Typedef”, or just “JTD”) schemas are just JSON ... where each key has a separate type of value,...
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