Macro pact_consumer::json_pattern[][src]

macro_rules! json_pattern {
    ($($json : tt) +) => { ... };
}
Expand description

Construct a JsonPattern object using a convenient syntax.

use pact_consumer::*;

json_pattern!({
    "message": "Hello, world!",
    "location": { "x": 1, "y": 2 },
    "tags": ["interesting"]
});

The json_pattern! macro supports nested Rust expressions:

use pact_consumer::*;
use serde_json::*;

#[derive(serde::Serialize)]
struct Point {
   x: f32,
   y: f32,
}

json_pattern!({
    // You can use Rust expressions, as long as they support
    // `Into<JsonPattern>`.
    "message": format!("Hello, {}!", "world"),

    // You can also nest the `json!` macro to embed types which
    // support `Serialize`.
    "location": json!(Point { x: 1.0, y: 2.0 }),

    // You can use `something_like` to match by type only.
    "comment": like!("A comment goes here"),

    // You can use `array_like` to match an array of values which
    // look like the example.
    "tags": each_like!("tag"),
});