Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No response if api sends a json String only. #50

Open
kanavarora opened this issue Sep 11, 2019 · 2 comments
Open

No response if api sends a json String only. #50

kanavarora opened this issue Sep 11, 2019 · 2 comments

Comments

@kanavarora
Copy link

Hi! First of all great library, and we have been using it extensively for validating our request/responses between our microservices. Works great with objects, but if my response is of type string, which is a valid json, the library misbehaves with that. Allow me to explain with an example:
If my schema looks something like this:

"/test": {
        "get": {
          "summary": "Test",
          "description": "Test",
          "produces": [
            "application/json"
          ],
          "parameters": [
          ],
          "responses": {
            "200": {
              "description": "successful operation",
              "schema": {
                "type": "string"
              }
            }
          }
        }
      }

And my api for this path looks like this:

router.get('/test', (req, res) => {
        res.json('result');
      });

Validation succeeds, but I lose the json-ness of the string. It just tries to return as a normal string in response even though content type is set to json.

I looked at the code and the issue seems to be that the response body is being parsed from JSON, but not being stringified in sendData.
I have a potential fix for this too, but wanted to run by the issue first and see if there is anything which I am doing wrong here.

@kanavarora
Copy link
Author

By the way works great, if I am sending a boolean or number only (or objects ofcourse). Just doesn't work in the case of a bare string like this.

@kanavarora
Copy link
Author

Created a pull request to solve this issue: #51

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

No branches or pull requests

1 participant