swagger-node icon indicating copy to clipboard operation
swagger-node copied to clipboard

Response validation, incorrect `originalResponse`

Open vadymhimself opened this issue 8 years ago • 6 comments

Failed response validation message contains the wrong type of the original response.

{
    "code": "SCHEMA_VALIDATION_FAILED",
    "message": "Response validation failed: failed schema validation",
    "failedValidation": true,
    "results": {
        "errors": [
            {
                "code": "OBJECT_MISSING_REQUIRED_PROPERTY",
                "message": "Missing required property: token",
                "path": []
            }
        ],
        "warnings": []
    },
    "originalResponse": {
        "type": "Buffer",
        "data": [
            123,
            34,
            119,
            116,
            102,
            34,
            58,
            116,
            114,
            117,
            101,
            125
        ]
    }
}

Even though I send a simple string.

vadymhimself avatar Oct 21 '17 06:10 vadymhimself

Seems like your string comes in as a buffer in your response ...

Is this "intended" application-wise (configured so in your controller)?

Is this "allowed" schema-wise (declared so by in your swagger.yaml by schema and type for your response)?

arne-at-daten-und-bass avatar Oct 21 '17 11:10 arne-at-daten-und-bass

Controller:

res.json({notToken: '123'})

Response schema:

  Session:
    required:
      - token
    properties:
      token:
        type: string

vadymhimself avatar Oct 21 '17 16:10 vadymhimself

Controller:

The required property key is token (notToken is what causes:

"Missing required property: token"

unless of course it was manually adapted for copy pasting here).

So this should be the correct format: res.json({'token': '123'})

(For testing purposes you could also drop the required constraint in your response schema so that it passes the validation).

Schema:

You could try some of the following in your response definition:

Session:
  type: object
  <...>

And in your route defitnition (in the swagger.yaml):

<url>:
  x-swagger-router-controller: <...>
    <METHOD>:
      <...>
      operationId: <...>
        produces:
	  - application/json

arne-at-daten-und-bass avatar Oct 22 '17 08:10 arne-at-daten-und-bass

@arne-at-daten-und-bass when the response is correct, there is no issue. The issue is that the validation error shows originalResponse as a byte buffer

vadymhimself avatar Oct 22 '17 16:10 vadymhimself

Sorry ... could not reproduce that here ... I am afraid I can't help any further.

arne-at-daten-und-bass avatar Oct 23 '17 12:10 arne-at-daten-und-bass

@arne-at-daten-und-bass thank you, but I'm not asking for help, I'm reporting a bug

vadymhimself avatar Oct 23 '17 13:10 vadymhimself