Placeholder (or similar concept) with generic matching
See original GitHub issueSometimes, I don’t know the exact value my API would return, but I know that it has to return a value, and maybe I know that the value has to have a specific shape (e.g. an UUID or a Date).
Currently, I can use body.path("id").isPresent
to assert that a value is there at all. This is somewhat fine, but doesn’t have a nice reading flow, e.g.:
And assert body.whiteListing.is(
"""
{
"firstName": "Foo",
"lastName": "Bar",
"isAwesome": true
}
""")
And assert body.path("id").isPresent
The reading flow is better if the "id"
presence is checked within the body-assertion.
And assert body.whiteListing.is(
"""
{
"id": <is-present>,
"firstName": "Foo",
"lastName": "Bar",
"isAwesome": true
}
""")
It would be even better if we can define matchers for the shape of the fields, e.g.:
And assert body.whiteListing.is(
"""
{
"id": "<any-uuid>",
"firstName": "Foo",
"lastName": "Bar",
"isAwesome": <any-boolean>,
"createdAt": "<any-iso-date>"
}
""")
I used the <>
syntax from placeholders in the examples. It would also be completely valid to introduce another syntax for it, as it’s a different concept (e.g. []
).
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:11 (11 by maintainers)
Top Results From Across the Web
swift - What's a placeholder? Why do we need to define ...
Your question is really "What is a generic?", which is kind of broad for Stack Overflow. Would it help you to read a...
Read more >Generics: How They Work and Why They Are Important - Oracle
Generics can be applied at the method level to solve such situations. Method arguments can contain generic types, and methods can also contain...
Read more >Generics — The Swift Programming Language (Swift 5.7)
Type parameters specify and name a placeholder type, and are written immediately after the function's name, between a pair of matching angle brackets...
Read more >How To Use Generics in TypeScript - DigitalOcean
Generics are a fundamental feature of statically-typed languages, allowing developers to pass types as parameters to a type, function, ...
Read more >Using Generic Types in Rust - Matt Oswalt
A syntax that allows the developer to use generic terms as placeholders for more concrete types to be passed in elsewhere; An underlying ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks really good, thank you for the input! I can definitely see how this could improve the user experience.
However it does require a non-trivial modification of the current model so no promises 😄
I have done the predicate change, the code is much cleaner. https://github.com/agourlay/cornichon/commit/9c9733e5f7d58e2576b1f3d607ec81b0a02e4812
I also added a description field to help our dear users :bowtie: