根据 Java 中的 Swagger 定义验证 JSON 消息

Validating JSON messages against Swagger definition in Java(根据 Java 中的 Swagger 定义验证 JSON 消息)

本文介绍了根据 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 消息

基础教程推荐