Feature Request: Ability to validate an endpoint
Opened this issue · 1 comments
simontabor commented
I want to be really lazy and validate an entire endpoint (including parameters, which I don't think are supported at the moment).
Usage could look something like this:
const oas2joi = require('oas2joi');
const validator = oas2joi('./open-api.yml');
const { error } = validator('/my-endpoint', { params, body });
JoeScho commented
Hey @simontabor , thanks for raising this.
I started looking into this, and before long realised that the function would require additional information such as the request method, and potentially content type, going from an OAS such as
/demo:
post:
summary: Demo
description: Demo
tags:
- Demo
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/request'
Would it meet your requirements if this functionality were to be added as a middleware, like so:
const validator = require('oas2joi/validator');
// express app
app.use(validator('open-api.yml'));
So in each request, it validates using the request path, method, content-type (if present, default to application/json
probably), body/params/query