Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Dredd does not output the title for a request in failure message #1326

Open
kylef opened this issue Apr 10, 2019 · 3 comments
Open

Dredd does not output the title for a request in failure message #1326

kylef opened this issue Apr 10, 2019 · 3 comments
Labels

Comments

@kylef
Copy link
Member

kylef commented Apr 10, 2019

Describe the bug

When looking at Dredd failures, it does not show the "title" of a request (transaction) so looking at a failure for an API Description where you have a lot of transactions which clear names, you cannot easily distinquish between them.

To Reproduce

Write an API Blueprint with named request/response pair, for example:

+ Request Transform API Blueprint with a warning into JSON API Elements without version (application/json)

        {
          "input_document": "# Hello\n\n# GET /\n\n+ Parameters\n\n+ Response 204\n",
          "input_type": "text/vnd.apiblueprint",
          "output_type": "application/vnd.refract.parse-result+json"
        }

+ Response 200 (application/hal+json)

        {
          "output_type": "application/vnd.refract.parse-result+json",
          "output_document": "{\n  \"element\": \"parseResult\",\n  \"content\": [\n    {\n      \"element\": \"category\",\n      \"meta\": {\n        \"classes\": [\n          \"api\"\n        ],\n        \"title\": \"Hello\"\n      },\n      \"content\": [\n        {\n          \"element\": \"category\",\n          \"meta\": {\n            \"classes\": [\n              \"resourceGroup\"\n            ],\n            \"title\": \"\"\n          },\n          \"content\": [\n            {\n              \"element\": \"resource\",\n              \"meta\": {\n                \"title\": \"\"\n              },\n              \"attributes\": {\n                \"href\": \"/\"\n              },\n              \"content\": [\n                {\n                  \"element\": \"transition\",\n                  \"meta\": {\n                    \"title\": \"\"\n                  },\n                  \"content\": [\n                    {\n                      \"element\": \"httpTransaction\",\n                      \"content\": [\n                        {\n                          \"element\": \"httpRequest\",\n                          \"attributes\": {\n                            \"method\": \"GET\"\n                          },\n                          \"content\": []\n                        },\n                        {\n                          \"element\": \"httpResponse\",\n                          \"attributes\": {\n                            \"statusCode\": \"204\"\n                          },\n                          \"content\": []\n                        }\n                      ]\n                    }\n                  ]\n                }\n              ]\n            }\n          ]\n        }\n      ]\n    },\n    {\n      \"element\": \"annotation\",\n      \"meta\": {\n        \"classes\": [\n          \"warning\"\n        ]\n      },\n      \"attributes\": {\n        \"code\": 3,\n        \"sourceMap\": [\n          {\n            \"element\": \"sourceMap\",\n            \"content\": [\n              [\n                18,\n                14\n              ]\n            ]\n          }\n        ]\n      },\n      \"content\": \"no parameters specified, expected a nested list of parameters, one parameter per list item\"\n    }\n  ]\n}"
        }

Run dredd against API where the expectation does not match (see below):

fail: POST (422) /transform duration: 6ms
fail: body: Real and expected data does not match.

request:
method: POST
uri: /transform
headers:
    Content-Type: application/json
    User-Agent: Dredd/9.0.0 (Darwin 18.2.0; x64)

body:
{
  "input_document": "FORMAT: 1A\n\n# Hello\n\n# Data Structures\n## A (A)\n",
  "input_type": "text/vnd.apiblueprint",
  "output_type": "application/vnd.refract.parse-result+json; version=1.0"
}


expected:
headers:
    Content-Type: application/hal+jason

body:
●{
  "output_type": "application/vnd.refract.parse-result+json; version=1.0",
  "output_document": "{\"element\":\"parseResult\",\"content\":[{\"element\":\"annotation\",\"meta\":{\"classes\":{\"element\":\"array\",\"content\":[{\"element\":\"string\",\"content\":\"error\"}]}},\"attributes\":{\"code\":{\"element\":\"number\",\"content\":4},\"sourceMap\":{\"element\":\"array\",\"content\":[{\"element\":\"sourceMap\",\"content\":[{\"element\":\"array\",\"content\":[{\"element\":\"number\",\"content\":39},{\"element\":\"number\",\"content\":9}]}]}]}},\"content\":\"base type 'A' circularly referencing itself\"}]}"
}●
statusCode: 422


actual:
statusCode: 422
headers:
    content-type: application/hal+jason
    access-control-allow-origin: *
    content-encoding: identity
    date: Wed, 10 Apr 2019 11:41:26 GMT
    connection: close
    transfer-encoding: chunked

bodyEncoding: utf-8
body:
●{
  "output_type": "application/vnd.refract.parse-result+json; version=1.0",
  "output_document": "{\"element\":\"parseResult\",\"content\":[{\"element\":\"annotation\",\"meta\":{\"classes\":{\"element\":\"array\",\"content\":[{\"element\":\"string\",\"content\":\"error\"}]}},\"attributes\":{\"code\":{\"element\":\"number\",\"content\":4},\"sourceMap\":{\"element\":\"array\",\"content\":[{\"element\":\"sourceMap\",\"content\":[{\"element\":\"array\",\"content\":[{\"element\":\"number\",\"attributes\":{\"line\":{\"element\":\"number\",\"content\":6},\"column\":{\"element\":\"number\",\"content\":1}},\"content\":39},{\"element\":\"number\",\"attributes\":{\"line\":{\"element\":\"number\",\"content\":6},\"column\":{\"element\":\"number\",\"content\":9}},\"content\":9}]}]}]}},\"content\":\"base type 'A' circularly referencing itself\"}]}"
}●

In my API Blueprint I have 20+ example request/response pairs for each transition and it is near imposible to tell which one caused the failure, especially without any source maps.

Expected behavior

When a response does not match the expectation, I am shown the transaction (request title).

What is in your dredd.yml?

Not relevant.

What's your dredd --version output?

$ dredd --version
dredd v9.0.0 (Darwin 18.2.0; x64)

Does dredd --loglevel=debug uncover something?

Not relevant

@artem-zakharchenko
Copy link
Contributor

I may be wrong, but it seems that named transaction should be stored in exampleName:

module.exports = function compileTransactionName(origin) {
const segments = [];
if (origin.apiName) { segments.push(origin.apiName); }
if (origin.resourceGroupName) { segments.push(origin.resourceGroupName); }
if (origin.resourceName) { segments.push(origin.resourceName); }
if (origin.actionName) { segments.push(origin.actionName); }
if (origin.exampleName) { segments.push(origin.exampleName); }
return segments.join(' > ');
};

Unfortunately, it never comes with a value, even if using an API blueprint from above. Here's a trace for that data:

apiDescriptions[i].annotations[i].origin

If origin.exampleName would be set to "Transform API Blueprint with a warning into JSON API Elements without version" it will appear in the reporter's output.

@kylef could you please check if that nested property contains expected exampleName in case of your reported scenario?

@kylef
Copy link
Member Author

kylef commented Aug 7, 2019

I don't know where exampleName comes from. In the parse result, it is the title of the httpRequest:

                    {
                      "element": "httpRequest",
                      "meta": {
                        "title": {
                          "element": "string",
                          "content": "Transform API Blueprint with a warning into JSON API Elements without version"
                        }
                      },
                      "attributes": {
                        "method": {
                          "element": "string",
                          "content": "GET"
                        },
                        "headers": {
                          "element": "httpHeaders",
                          "content": [
                            {
                              "element": "member",
                              "content": {
                                "key": {
                                  "element": "string",
                                  "content": "Content-Type"
                                },
                                "value": {
                                  "element": "string",
                                  "content": "application/json"
                                }
                              }
                            }
                          ]
                        }
                      },

# GET /

+ Request Transform API Blueprint with a warning into JSON API Elements without version (application/json)

        {}

+ Response 200 (application/hal+json)

        {}

@honzajavorek
Copy link
Contributor

Yes, this is #294 from another side, boiling down to #227. Current transaction names do not contain request names from API Blueprint. The example is added in case of multiple request-response pairs:

+ Request
+ Response

+ Request
+ Response

These would be Example 1 and Example 2. This peculiarity inherited from the very beginnings of Dredd and API Blueprint is the main reason why this file exists, backporting the example numbers even in Dredd versions which use API Elements where this concept doesn't exist at all anymore.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants