cdimascio / express-openapi-validator

🦋 Auto-validates api requests, responses, and securities using ExpressJS and an OpenAPI 3.x specification

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a note about cookie-parser to Documentation

yutak23 opened this issue · comments

Is your feature request related to a problem? Please describe.
OpenAPI has Cookie Authentication and from this issue and code, I believe express-openapi-validator also supports it.
However, it needs to be able to access the req.cookies property for it to work, and for that we need to add cookie-parser middleware.

The documentation doesn't list that, and I had to go to the code when I got an error, which was time consuming.

Describe the solution you'd like
How about the following sample code from the Example Express API Server section of the documentation?

const express = require('express');
const path = require('path');
const http = require('http');
const cookieParser = require('cookie-parser'); // <- add this
const app = express();

...

// 2. Set up body parsers for the request body types you expect
//    Must be specified prior to endpoints in 5.
app.use(express.json());
app.use(express.text());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser()); // If you want to Cookie Authentication, we can access req.cookies property  // <- add this

// 3. (optionally) Serve the OpenAPI spec
...

In the past, the following PR seems to have removed the cookie-parser description, but I thought this might cause a little trouble for the users.

#339