Is there a Java library for request/response validation that is framework agnostic?

1,946 views
Skip to first unread message

Tom Akehurst

unread,
Sep 20, 2016, 7:08:10 AM9/20/16
to Swagger
Hello!

I'm trying to find a good way to implement the following use case:
I'm building a WireMock-based mock of a 3rd party API my project depends on. I'd like to be able to write a suite of tests that can be run against either the real API or the mock, where each HTTP request/response is captured and validated against a Swagger spec.

I realise swagger-inflector is capable of validating exchanges, but it appears to be tied to a specific server-side stack (please correct me if I'm wrong!). I'd like a library with a similar architecture to this one for RAML, which works against its own HTTP model and has adapters for various HTTP clients: https://github.com/nidi3/raml-tester. That way I can run it client or server, pick my own client and adapt it to WireMock's request log API.

If such a library exists, please can somebody point me to it?

If it doesn't there's a good chance I'll end up writing it, so my next question (for core community members) is: Would this would be of interest for community adoption?

Thanks,
Tom

Max Goldstein

unread,
Sep 20, 2016, 10:38:03 AM9/20/16
to Swagger
Not only is the inflector tied to a specific stack, it seems to not be feature-complete. My best idea is to validate incoming requests (and outgoing responses) using this json schema validator, adding a custom pass to check for the discriminator, readOnly, and other properties that get added if you use them. That's what I'm planning to do for my project anyway, I haven't actually tried it, so take this with a grain of salt.

Tom Akehurst

unread,
Sep 20, 2016, 11:48:49 AM9/20/16
to Swagger
Is there a way to adapt a Swagger spec to JSON schema?

tony tam

unread,
Sep 20, 2016, 11:49:37 AM9/20/16
to swagger-sw...@googlegroups.com
What do you mean?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tom Akehurst

unread,
Sep 20, 2016, 11:54:34 AM9/20/16
to Swagger
Haha, showing my ignorance here. Hadn't realised that the definitions part of a Swagger doc was actually JSON schema.
What do you mean?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

tony tam

unread,
Sep 20, 2016, 12:23:50 PM9/20/16
to swagger-sw...@googlegroups.com
Yes, there is a JSON schema to describe the swagger specification, and also the definitions are a subset of JSON schema.  Please take a look here for all the gory details:


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Tom Akehurst

unread,
Sep 21, 2016, 5:39:20 AM9/21/16
to Swagger
Thanks, that's very useful.

I'm working on writing a validator now. Hopefully I should be able to open source it in the next few days.

James Navin

unread,
Sep 25, 2016, 8:03:57 PM9/25/16
to Swagger
I faced a similar situation and ended up writing my own. Its open source and available at https://bitbucket.org/atlassian/swagger-request-validator

Its framework agnostic and has adapters for WireMock (as well as Rest Assured and Pact).

Feel free to raise any issues you find on the issue tracker attached to the repo.

Tom Akehurst

unread,
Sep 26, 2016, 9:47:56 AM9/26/16
to Swagger
Thanks, this is exactly the kind of thing I'm looking for. Wish I'd found this a week ago, as I've nearly finished writing my own impl :-(

I've noticed that only the POMs are published on Maven central, not the full artifacts. Is this deliberate?

I also noticed there's some work left to do validating specific string formats. Would you be happy to accept a PR or two to add these?

Finally, any objection to me bumping up to the latest WireMock version while I'm at it?

Cheers,
Tom

James Navin

unread,
Sep 26, 2016, 6:52:08 PM9/26/16
to Swagger
Hi Tom - glad to hear it might be useful to you.


I've noticed that only the POMs are published on Maven central, not the full artifacts. Is this deliberate?

The full artifacts are there - they're just under the sub-modules (e.g. http://repo1.maven.org/maven2/com/atlassian/oai/swagger-request-validator-core/1.0.4/). I'll update the README so its a bit easier to find.


 I also noticed there's some work left to do validating specific string formats. Would you be happy to accept a PR or two to add these?
 
Please do - I would be more than happy to accept PRs (string format validation has been on my TODO list for a while). The only requirement is you'll need to sign a CLA (company policy) - details are in the project README. If that's not an option for you raise a ticket in the issue tracker and I'll try to find the time this week to look at it.


Finally, any objection to me bumping up to the latest WireMock version while I'm at it?

None at all.

Cheers,

James

Tom Akehurst

unread,
Sep 27, 2016, 3:34:39 AM9/27/16
to Swagger
Duh! Yeah, it would help if I looked in the right group!

Will take a look at the CLA, but I wouldn't have thought it'd be a problem.

Cheers,
Tom

Tom Akehurst

unread,
Oct 4, 2016, 1:44:07 PM10/4/16
to Swagger
Hey James,

I'm trying to raise a PR (from https://bitbucket.org/tom_akehurst/swagger-request-validator) to add the missing parameter constraints, but I'm getting 500s from Bitbucket. Any idea what's happening?

Cheers,
Tom
Reply all
Reply to author
Forward
0 new messages