
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
extract-openapi-req
Advanced tools
A lightweight TypeScript library for extracting OpenAPI metadata from HTTP requests. This package helps you easily extract and validate request metadata against your OpenAPI specifications.
npm install extract-openapi-req
import { OpenApiExtractor } from "extract-openapi-req";
// Initialize the extractor
const extractor = new OpenApiExtractor();
// Load spec from URL
await extractor.loadSpec("https://api.example.com/openapi.json");
// Or load from object
await extractor.loadSpec(require("./openapi.json"));
// Extract metadata from a request
const metadata = extractor.extract("/v1/users/123", "GET");
if (metadata) {
console.log("Operation ID:", metadata.schema.operationId);
console.log("Path Parameters:", metadata.params);
console.log("Full Operation Schema:", metadata.schema);
}
import { Hono } from "hono";
import { OpenApiExtractor } from "extract-openapi-req";
import {
createHonoMiddleware,
HonoOpenApiVariables,
} from "extract-openapi-req/frameworks/hono";
const app = new Hono<{ Variables: HonoOpenApiVariables }>();
const extractor = new OpenApiExtractor();
// Load OpenAPI spec
await extractor.loadSpec(openApiSpec);
// Add the middleware
const middleware = createHonoMiddleware(extractor);
app.use("*", middleware);
// Access OpenAPI metadata in your handlers
app.get("/users/:id", (c) => {
const metadata = c.get("openapi");
// Use the metadata...
});
import express from "express";
import { OpenApiExtractor } from "extract-openapi-req";
const app = express();
const extractor = new OpenApiExtractor();
await extractor.loadSpec("./openapi.json");
app.use((req, res, next) => {
const metadata = extractor.extract(req.path, req.method);
if (metadata) {
req.openapi = metadata;
}
next();
});
OpenApiExtractorloadSpec(specOrUrl: string | object): Promise<void>
Load an OpenAPI specification from a URL or object.
getSpec(): object | null
Get the currently loaded OpenAPI specification.
extract(path: string, method: string): OpenApiRequestMetadata | null
Extract OpenAPI metadata from a request path and method.
createHonoMiddleware(extractor: OpenApiExtractor): MiddlewareHandlerinterface OpenApiRequestMetadata {
schema: OpenAPIV3.OperationObject; // Full OpenAPI operation object
params: Record<string, string>; // Extracted path parameters
}
type HonoOpenApiVariables = {
openapi: OpenApiRequestMetadata;
};
Check out our roadmap for upcoming features:
Contributions are welcome! Please feel free to submit a Pull Request.
MIT © ahmedrowaihi
FAQs
Extract OpenAPI metadata from HTTP requests
We found that extract-openapi-req demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.