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

Add a note about cookie-parser to Documentation #847

Closed
yutak23 opened this issue May 19, 2023 · 2 comments
Closed

Add a note about cookie-parser to Documentation #847

yutak23 opened this issue May 19, 2023 · 2 comments

Comments

@yutak23
Copy link
Contributor

yutak23 commented May 19, 2023

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
...
@yutak23
Copy link
Contributor Author

yutak23 commented May 19, 2023

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

@cdimascio
Copy link
Owner

#891

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

2 participants