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 providing sample requests and responses

See original GitHub issue

Sometime it is handy to have sample request or response example. Working with integration of larger project SUPERHUB, we go from API design over samples, validating them and finally implementing. Samples are key component in communication about API.

Option “tree”: agreed tree structure with basePathExamples parameter

API declaration would get new attribute “basePathExamples”.

Default value for basePathExamples could be <basePath>/_examples

Real examples would be available at url build from <basePathExamples>/<resourcePath>/<operationNickname>/request/<requestExampleName> and similarly <basePathExamples>/<resourcePath>/<operationNickname>/response/<responseExampleName>

Option “index”: Index of sample files within agreed tree structure

Option “tree” has a disadvantage, that collecting all sample file names/urls might not be always easy or even possible. To resolve that, we would put into path <basePathExamples>/<resourcePath>/<operationNickname> a file called index.json. This would be an object with two properties requests and responses, each holding list of path names for sample request/responses. The path shall be relative to given directory with index.json file as it is easier to fill it in (e.g. using find) and also easy to check by using an editor (use gf in vim, standing for “go file” - you either succeed and see the sample file, or hit a problem, if the path is invalid). We could also completely relax from requirement to use names request or response for directories and leave it up to the developer.

Option “links”: Explicit links from operation items to examples

We could reuse the concept of basePathExamples above plus allowing two new attributes within operation objects.

exampleRequests would be a list of urls, pointing to request examples.

exampleResponses would be a list of urls, pointing to response examples.

However, as such an option seems too intrusive to me, I will not detail on it.

How to start

Starting with agreed tree structure shall be rather easy, as in the simplest situation (using agreed default value for basePathExamples), there is no need to modify any of existing structures.

Allowing non-default values for basePathExamples sounds practical to me and relatively easy.

If we feel a need to extend it, I would prefer the “index” solution as it is much less intrusive comparing “links” option.

How to follow up

(this is out of scope of this ticket)

Swagger UI showing sample files

Swagger UI shall be able to show sample requests and responses.

Test suite for evaluating sample files

Having all the information proposed at hand, we shall be able writing a test suite, which would detect following problems:

  • operation without sample request (if relevant) and sample response
  • sample requests and responses being invalid with respect to data structures defined in API Declaration.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
vadcommented, Sep 28, 2015

I don’t understand how to use this… I don’t see any reference in the specification

0reactions
darrelmillercommented, Nov 14, 2016

@marians You can put an example on a schema that is used by a body parameter. So it is possible, but parameter objects do not support example objects directly in 2.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Specifying examples - Postman Learning Center
You can add an example to a request by saving a response, or you can create an example with a custom response to...
Read more >
JSON requests and responses - Atlassian Developer
Representations for requests. These samples show the JSON representations that the Crowd REST Resources expect to receive.
Read more >
Step 4: Request example (API reference tutorial)
The design of this API doc site arranges the sample requests and responses in the right column of a three-column layout.
Read more >
Cross-Origin Resource Sharing (CORS) - MDN Web Docs
An example of a cross-origin request: the front-end JavaScript code served ... In response, the server returns a Access-Control-Allow-Origin ...
Read more >
Python's Requests Library (Guide)
Let's dive a little deeper into the response of that request. ... status codes as well to give you specific insights into what...
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