Validating REST messages against Swagger definitio

2019-03-04 07:21发布

问题:

I'm working within IBM Integration Bus and I found myslef in need of validation of the messages that I recive. Since IIB does not support any kind of validation in this regard, I was wondering if there are any external libraries that could validate those messages for me.

So far, I found this https://github.com/swagger-api/swagger-inflector/blob/master/README.md#payload-validation But I was wondering if there are alternatives that might fit my needs a little better.

Thanks for any suggestions.

回答1:

One option is the swagger-request-validator. It lets you validate requests/responses against a Swagger / OpenAPI definition.

There are modules available for integrating with WireMock, Rest Assured, Pact etc., or you can use the validator directly.

Take a look at the example usages for code samples on how to use it.



回答2:

I came across the below link in which JSON equivelent XML modeling was used to enable graphical mapping of a JSON message here. In the same manner, you can create an equivelent XML model and switch from JSON to XML domain then run validation using ResetContentDescriptor node. But, I am not sure about the performance. If were you, I would test and compare this solution to yours.