-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a quickcheck generator for aeson Values that match a swagger schema #162
Conversation
Thank you for the contribution! I can see that Can you please add tests for types that are valid under I suspect some types (e.g. |
Since Checking that a This supports the opposite (and equally common) case: a server that is expecting request bodies in a certain format or a client that is expecting responses. I develop an iOS app, so it's critical that the request/response structures continue to match what the app is expecting as I make changes to the server. I'm using Can you clarify why you think
|
Sure I see the intent here. But a similar effect can also be achieved with
You may notice that
I forgot that
However that's only because nothing useful is generated for these tests:
Swagger cannot put any constraints on its keys, so that at least in these cases your property won't hold. @benweitzman I don't want to discourage you from working on this! Generating values based on |
No, this is actually not correct, for a few reasons:
This behavior is actually incorrect for the above reasons and I'll be submitting a PR soon, but this is unrelated to this PR.
Right this is true. I haven't tried to use the I submit that it's actually the |
I find it very useful for logging, Haskell clients and integration tests.
This is indeed a serious argument in favour of your solution. I'm convinced 😄
Well, you still need schemas for these types in real world, right?
My position on this is that Swagger is far from perfect and you can't really use it for a strong guarantee that your implementation is correct anyway. Although it makes sense to try getting better at it nonetheless 😄 |
I added a generation of additional properties to help pick up some more issues. The format section of the swagger spec is just not specific enough about what can go in that field and what it does, so I think there's nothing that can be done there. There are a few standardish formats that we could try and work off of but I think it's a challenge for another day. Any type that is expecting some text to be in a certain format ( This will take some consideration on how to add to |
Can this be merged? |
@fizruk is there anything that is blocking this from being merged? Please let me know if there is so I can work on fixing it. |
Apart from missing documentation I think I am okay with this. @phadej can you review this please? |
Ok. I think this is good. We can iterate this based on feedback, if needed. Before releasing this, however, I'd like to drop |
We can validate
ToJSON
instances by checking that an arbitrary value of a datatype matches against its swagger schema given byToSchema
when serialized using aeson.This PR begins to add a way to validate
FromJSON
instances. In order to do so, we have to generate an arbitrary json value that matches we some swagger schema. We can use the schema to help guide the generator.One we have a json value, we can then try and parse it to the haskell datatype using aeson. If the
FromJSON
instance does not match theToSchema
instance, then we will expect to see a parse error occasionally.