Validating JSON messages against Swagger definition in Java(根据 Java 中的 Swagger 定义验证 JSON 消息)
问题描述
我使用 Swagger 定义创建了一个 REST API,现在我需要使用该 swagger 模式来验证传入消息.我找到了几种解决方案,但是它们都依赖于一些特定的用例.最接近我需要的是 this 和真实的描述它适用于提供的 json 模式,但是当我提供更复杂的招摇定义时,它只是将所有内容标记为有效.我的问题是.是否有任何更好、更完整或更称职的解决方案(也许是库)可以根据 Swagger 定义本地验证给定的 JSON 消息?我需要这个,因为我正在实施 WSO2 API REST 解决方案,这将有很大帮助.
I created a REST API using a Swagger definition, now I need to validate incoming messages using that swagger schema. I found several solutions however all of them rely on some specific use case. The closest to what I need is this and true to it's description it works well with provided json schema, however when I deliver much more complex swagger definition, it just marks everything as valid. My question is. Is there any better, more complete or competent solution, library perhaps, that would natively validate given JSON messages against Swagger definition? I need this because I'm implementing WSO2 API REST solution and this would greatly help.
推荐答案
有 swagger-request-validator 有多个适用于各种框架的适配器,例如:Spring Web MVC
There is the swagger-request-validator having several adapters for various frameworks, e.g.: Spring Web MVC
它能够验证针对 Swagger/OpenAPI 2 或 OpenAPI 3 方案的请求和/或响应.
It is capable of validating requests and / or responses against Swagger / OpenAPI 2 or OpenAPI 3 schemes.
它不只是验证定义的 JSON 主体.它也会验证请求的其余部分,例如路径(变量)、标头等.
It doesn't simply validate the defined JSON body. It validates the rest of the request, too, like path (variables), headers, etc.
验证器能够 i18n.
The validator is capable of i18n.
到目前为止,Java 中针对 Swagger 和 OpenAPI 的最完整验证.
Up until now the most complete validation against Swagger and OpenAPI in Java.
这篇关于根据 Java 中的 Swagger 定义验证 JSON 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:根据 Java 中的 Swagger 定义验证 JSON 消息


- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 转换 ldap 日期 2022-01-01
- 获取数字的最后一位 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01