MIT License

项目介绍

cdimascio/express-openapi-validator 是一个托管在 GitHub 上的开源项目,主要使用 TypeScript 编写,采用 MIT License 许可证,目前获得 1.0k 个 Star、239 次 Fork。

仓库全名
cdimascio/express-openapi-validator
开源许可证
MIT License
Star 数
1.0k
Fork 数
239
未关闭 Issue
266

README 摘要

🦋 express-openapi-validator An OpenApi validator for ExpressJS that automatically validates API requests and responses using an OpenAPI 3 specification. 🦋express-openapi-validator is an unopinionated library that integrates with new and existing API applications. express-openapi-validator lets you write code the way you want; it does not impose any coding convention or project layout. Simply, install the validator…

完整内容见 GitHub 原始 README 或本页 。

常见问题

express-openapi-validator 用什么语言开发?

主要使用 TypeScript 编写,采用 MIT License 许可证,目前有 1.0k 个 Star。

express-openapi-validator 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 express-openapi-validator 的源码?

可以直接克隆仓库:git clone https://github.com/cdimascio/express-openapi-validator.git,默认分支为 master;安装与运行步骤见仓库 README。

express-openapi-validator 最近还在维护吗?

仓库最近一次更新为 6 天前,当前有 266 个未关闭 Issue;Star 数为 1.0k,可作为社区活跃度的参考。

语言占比

JavaScript
Shell
TypeScript

Release

README

🦋 express-openapi-validator

build workflow All Contributors Coverage Status Codacy Badge Gitpod Ready-to-Code

An OpenApi validator for ExpressJS that automatically validates API requests and responses using an OpenAPI 3 specification.

🦋express-openapi-validator is an unopinionated library that integrates with new and existing API applications. express-openapi-validator lets you write code the way you want; it does not impose any coding convention or project layout. Simply, install the validator onto your express app, point it to your OpenAPI 3.0.x or 3.1.x specification, then define and implement routes the way you prefer. See an example.

Features:

  • ✔️ request validation
  • ✔️ response validation (json only)
  • 👮 security validation / custom security functions
  • 👽 3rd party / custom formats / custom data serialization-deserialization
  • 🧵 optionally auto-map OpenAPI endpoints to Express handler functions
  • ✂️ $ref support; split specs over multiple files
  • 🎈 file upload
  • ✏️ OpenAPI 3.0.x and 3.1.x spec support
  • ✨ Express 4 and 5 support

Docs:

GitHub stars Twitter URL

Express 5 support available in >=v5.5.0!

OAS 3.1 support available in >=v5.4.0!

NestJS Koa and Fastify now available! 🚀

Install

npm install express-openapi-validator

Usage

  1. Require/import the openapi validator
const OpenApiValidator = require('express-openapi-validator');

or

import * as OpenApiValidator from 'express-openapi-validator';
  1. Install the middleware
app.use(
  OpenApiValidator.middleware({
    apiSpec: './openapi.yaml',
    validateRequests: true, // (default)
    validateResponses: true, // false by default
  }),
);
  1. Register an error handler
app.use((err, req, res, next) => {
  // format error
  res.status(err.status || 500).json({
    message: err.message,
    errors: err.errors,
  });
});

Important: Ensure express is configured with all relevant body parsers. Body parser middleware functions must be specified prior to any validated routes. See an example.

Documentation

See the doc for complete documenation

deprecated legacy doc

License

MIT

Buy Me A Coffee

评论

暂无评论