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

Not found path not work with express router #310

Closed
sergebesson opened this issue May 29, 2020 · 4 comments
Closed

Not found path not work with express router #310

sergebesson opened this issue May 29, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@sergebesson
Copy link

Describe the bug
if using an express router instead of app express, a path not defined does not return the Not Found error

Examples and context
example with code bug_openapi.js

const express = require("express");
const { OpenApiValidator } = require("express-openapi-validator");

async function execute() {

	const router = express.Router();
	await new OpenApiValidator({
		apiSpec: {
			openapi: "3.0.0",
			info: { version: "1.0.0", title: "test bug OpenApiValidator" },
			servers: [{ url: "http://localhost:8080/api/" }],
			paths: {
				"/": {get: {responses: {200: {description: "home api"}}}}
			},
		},
	}).install(router);

	router.get("/", (req, res) => res.status(200).send("home api\n"));
	router.get("/notDefined", (req, res) => res.status(200).send("url api not defined\n"));

	const app = express();
	app.get('/', (req, res) => res.status(200).send("home\n"));
	app.use("/api", router);

	app.listen(3000);
	console.log("server start port 3000");

}

execute().catch((error) => console.error(error.stack));

node bug_openapi.js to start server
curl http://localhost:3000/api/notDefined return 200 - url api not defined.
however, a path is not defined in apiSpec. The return should have been 404 Not Found

@cdimascio cdimascio added the bug Something isn't working label Jun 13, 2020
@cdimascio
Copy link
Owner

@sergebesson thanks for the issue. will get this fixed

@cdimascio
Copy link
Owner

@sergebesson this is fixed in v3.16.1

@cdimascio
Copy link
Owner

thank you for the reproducible code snippet. i used it as the test here

@sergebesson
Copy link
Author

thank you for fix :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants