# Demonstrates conditional assertions based on variable values plus schema guards.
$ REST_ORIGIN = https://lorem-api.com/api
schema EchoPayload {
username: string
role: string
}
---
Echo a request
$ USERNAME = [foo, bar]
POST {{ REST_ORIGIN }}/echo
~~~ application/json
{
"username" : "{{ USERNAME }}",
"role" : "user"
}
~~~
# Echo request succeeds
^ & status == 200
# Echoes the fixed role
^ & body.role == "user"
# Uses a schema guard before checking the mapped username
[ & body === EchoPayload ] ^ & body.username == USERNAME
# Echoes the username when USERNAME is foo
[ USERNAME == "foo" ] ^ & body.username == "foo"
# Echoes the username when USERNAME is bar
[ USERNAME == "bar" ] ^ & body.username == "bar"