Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including express-openapi-validate with all npm packages installed. Try it out:

const jsYaml = require("js-yaml"); const { OpenApiValidator, ValidationError, } = require("express-openapi-validate"); const openApiDocument = jsYaml.safeLoad(` openapi: 3.0.1 info: title: Test API version: 1.0.0 paths: /echo: post: requestBody: content: application/json: schema: type: object properties: input: type: string required: - input required: true responses: 200: description: Echoed input `); const validator = new OpenApiValidator(openApiDocument); // This is the express middleware that does the validation const validate = validator.validate("post", "/echo"); const fakeRequest = { body: {}, query: {}, headers: {}, cookies: {}, params: {}, }; const fakeResponse = {}; const nextFunction = (err) => { console.log("Error passed to next:", err); }; validate(fakeRequest, fakeResponse, nextFunction); const requestWithBody = Object.assign({}, fakeRequest, { body: { input: "Hello!" }, }); validate(requestWithBody, fakeResponse, nextFunction);

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

express-openapi-validate v0.6.1

Express middleware to validate request based on an OpenAPI 3 document

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free