Skip to main content

rewrit_model/
contract.rs

1use crate::ids::CaseId;
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5use std::collections::BTreeMap;
6
7#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
8pub struct Contract {
9    pub schema_version: String,
10    pub id: CaseId,
11    pub kind: String,
12    #[serde(default)]
13    pub input: ContractInput,
14    #[serde(default)]
15    pub expect: ContractExpectation,
16    pub policy: Option<String>,
17    #[serde(default)]
18    pub metadata: BTreeMap<String, String>,
19}
20
21#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
22pub struct ContractInput {
23    pub method: Option<String>,
24    pub path: Option<String>,
25    #[serde(default)]
26    pub headers: BTreeMap<String, String>,
27    pub json: Option<Value>,
28    pub body: Option<String>,
29}
30
31#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
32pub struct ContractExpectation {
33    pub status: Option<u16>,
34    #[serde(default)]
35    pub headers: BTreeMap<String, String>,
36    pub json: Option<Value>,
37    pub json_schema: Option<Value>,
38    #[serde(default)]
39    pub effects: Vec<Value>,
40}