Skip to content

Add a note about cookie-parser to Documentation #847

Closed
@yutak23

Description

@yutak23

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
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions