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.

Option to validate all responses

See original GitHub issue

I can’t find an option to validate all responses, it gets repetitive to keep doing.

const validationError = res.validateResponse(200, json);
if (validationError) {
    return next(validationError);
}

res.json(json);

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:35 (24 by maintainers)

github_iconTop GitHub Comments

1reaction
jsdevelcommented, Jan 10, 2019

I’m wondering if we can close this issue now, because I’m having a hard time thinking of an alternative that isn’t too prescriptive. Perhaps this could be documented in openapi-response-validator’s README? @maxwellb thoughts on submitting a PR to submit an example with your findings?

1reaction
Frizzledcommented, Jul 18, 2018

If you want to automatically validate responses with res.json() use this express middleware:

module.exports = function() {

    return async function(req, res, next) {
        let resJson = res.json;

        res.json = function() {
            let statusCode = res.statusCode || 200;
            let validationError = res.validateResponse(statusCode, arguments[0]);
            if (validationError) {
                console.error(validationError.errors);
                if (process.env.STRICT) {
                    return res.status(500).json('Unsupported implementation', validationError);
                }
            }
            resJson.apply(this, arguments);
        };

        next();
    };
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Add Response Validation to Google Forms - MakeUseOf
Response validation is a set of rules that restrict the type of responses that can be filled into a certain field based on...
Read more >
How to add response validation to a question in Google Forms?
To add a response validation, select a question in Google Forms, click on ⋮ More icon and select show Response validation. The response...
Read more >
How to Validate Responses in Google Forms - How-To Geek
To enable it, select one of those question types on the top right of the question box. Click the three dots on the...
Read more >
How to Set Up Response Validation in Google Forms
If you want to use paragraph response validation in Google Forms, just add a paragraph element to your form. Then select the three...
Read more >
Set rules for your form - Google Docs Editors Help
Open a form in Google Forms. · Add one of the following types of questions: Short answer; Paragraph; Checkboxes · Click More More...
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