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.

Examples with Valid Request / Response Pairs

See original GitHub issue

Goal:

  • Be able to define 1…N vaild request / response pairs as examples.

Use

  • This pairs could be used to test the final implementation.
  • This pairs could be used to generate easy a some mock for the interfaces.
{
  "paths": {
    "/pets": {
      "get": {
        "summary": "List all pets",
        "operationId": "listPets",
        "parameters": "...",
        "responses": "...",
        "examples": {
          "example_one": {
            "request": {
              "parameters": {
                "limit": 10
              }
            },
            "response": {
              "status": 200,
              "headers": {
                "x-next": 11
              },
              "content": {
                "application/json": {
                  "id": 55226688,
                  "category": {
                    "id": 0,
                    "name": "string"
                  },
                  "name": "doggie",
                  "photoUrls": [
                    "string"
                  ],
                  "tags": [
                    {
                      "id": 0,
                      "name": "string"
                    }
                  ],
                  "status": "available"
                }
              }
            }
          }
        }
      }
    }
  }
}

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
ambition-consultingcommented, Feb 27, 2021

I strongly disagree with the answer and the decision to close this request, and find the request still valid:

  • Correlating request and response examples is hard requirement for understanding services employing responses with multiple strongly typed response types. Strong typing is a way of letting the compiler help you by providing it with additional information, thus reducing the number of required tests dramatically. Or said differently: A good API doing more than just CRUD resource mappings, will not just return some stupid base class and let the user figure out what it means, but strongly type the different possible return types - which absolutely requires some examples to be better understood.
  • Providing instances of a contract does not define the contract, but provides sample data to be used for good testing, documentation etc… That’s why it’s called example, and not schema.
  • Reliable testing with external dependencies (such as a REST service specified with OpenAPI) requires Mocks, which are really just request/response pairs. Techniques such as Consumer-Driven-Contract can also make sure, that the Contract is uphold from both sides. A servise will evolve nicely not by letting it’s clients break all the time when something got changed, but by making sure they know about changes automatically and can evolve together with the API.
  • Not following this request effectively stops the integration of OpenAPI into automated Unit Testing. And wouldn’t it be nice to not just write down some specification, but also automatically validate that its implementation actually also works?
  • Instead, people like myself need to implement all kind of absurd pipelines, just so that we can produce some test data elsewhere to validate our service responses against. And due to the examples specification not getting picked up in time, we even have to duplicate the examples, rendering this great OpenAPI feature less valueable.
3reactions
handrewscommented, Feb 11, 2020

Sounds like this was definitively answered in 2018, closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Request/Response Pairs - TechDocs - Broadcom Inc.
A request/response pair consists of one request file and one or more response files. Multiple response files are applicable to messaging ...
Read more >
Access to HTTP request/response pairs - Micro Focus
Access to HTTP request/response pairs. Conditions used within HttpParsingRule rules can ... Valid Component values for HTTP requests, plus return values: ...
Read more >
RESTful HTTP Request and Response Examples
This section provides examples of RESTful HTTP Request and Response. The RESTful HTTP Requests are categorized according to method types as the following:....
Read more >
15.3 Request and Response XML Examples
This section presents some feature requests to the WFS engine, and the response to each request, for each of the following operations: GetCapabilities....
Read more >
What is a request-response pair called? - Stack Overflow
For example in HTTP you send a request and receive a response; is there a noun that describes that request-response pair? I'd thought...
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