-
Notifications
You must be signed in to change notification settings - Fork 230
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 model constraints #961
Comments
This looks like a great feature. Tons of value in being able to add and check these constraints. Bosque is also working on tools to use them to do structured input fuzzing, semantic diffing for versioning, and auto-generating mocks of services. Would be great to expose a hook for using other languages (e.g. Bosque) for writing these logical constraints. I opened issue #505 in the Bosque repo to track things on the Bosque side. |
Think we'd need to make sure we can do this for
this feels like partially related to this prospal #602 but we have this constraint as cadl language |
That's a good point. @mrkmarron is that something Bosque can express, say an integer type with values between 32 and 64? |
Yeah, definitely possible. In fact Bosque has special support for doing
We are basically using the special name |
I wonder if we can express similar kinds of constraints for operations? For example, asserting that casing / values are identical across a request and response, or asserting conditional response values based on request values. This strikes me a s useful in service testing. |
I spent a bit of time on a proof-of-concept implementation of this feature last week. The fork is here. I took the example @bterlson had and tweaked it a bit to try out some various things, including pre/post constraints like @markcowl mentioned.
The From this spec we can (of course) generate executable bosque code to validate the pre/post/invariant conditions at runtime. In addition Bosque also is also designed explicitly with solver support so we there are (at least) 3 scenarios that this would also light up -- fuzz input generation, auto service test mock generation, and API delta generation. I have implemented the first 2 of these and can explain the third. Fuzzing: Given just the specs we can solve for valid inputs, e.g., for Auto-Mocking: From the specs we can solve for a valid output given a concrete input. So, if you want to test against a service you use, instead of writing mocks by hand, you can auto generate them on demand as your test runs and makes calls to various service interface endpoints. In this example you might call I have a little animation of these scenarios working here: In the third scenario you can imagine semantic changes to a model occurring, like allowing new account ids say where they may have more digits or allow an optional prefix. In this case we can use the same underlying solver to generate inputs (or outputs) that are not valid in version A but are now valid in version B to help test for regressions when updating dependecies. |
Here's a scenario that might fall under this category too. Given: {
"properties": {
"auth": {
"cert": { },
"aad": { }
}
}
} I want to be able to require at least one properly specified: either |
A feature that Bosque has that I covet is the ability to describe constraints on the values of a model in order to e.g. generate code to construct a model that ensures that the data inside the model is correct. We have decorators for simple scenarios but there are many cases where the validations are more complex than the decorators can handle.
Imagine syntax like the following:
Syntax wise I think we leverage what we've already done for projections. Semantically, I think these clauses are validated but not run in Cadl. Emitters can access the AST and convert these expressions into target languages.
There are various constraints that don't necessarily apply to projections to keep in mind, i.e. these expressions must be pure in the sense that they should not make modifications to the cadl program at all.
The text was updated successfully, but these errors were encountered: