Skip to main content

reinhardt_rest/metadata/
response.rs

1//! Metadata response structures
2
3use super::fields::FieldInfo;
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7/// Action metadata (for POST, PUT, etc.)
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct ActionMetadata {
10	/// The HTTP method for this action (e.g., `"POST"`, `"PUT"`).
11	pub method: String,
12	/// Field metadata keyed by field name.
13	pub fields: HashMap<String, FieldInfo>,
14}
15
16/// Complete metadata response
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct MetadataResponse {
19	/// The display name of the view.
20	pub name: String,
21	/// A description of the view.
22	pub description: String,
23	/// Content types the view can render.
24	#[serde(skip_serializing_if = "Option::is_none")]
25	pub renders: Option<Vec<String>>,
26	/// Content types the view can parse.
27	#[serde(skip_serializing_if = "Option::is_none")]
28	pub parses: Option<Vec<String>>,
29	/// Action metadata keyed by HTTP method, containing field info.
30	#[serde(skip_serializing_if = "Option::is_none")]
31	pub actions: Option<HashMap<String, HashMap<String, FieldInfo>>>,
32}
33
34#[cfg(test)]
35mod tests {
36	use super::*;
37
38	#[test]
39	fn test_metadata_serialization() {
40		let response = MetadataResponse {
41			name: "Test View".to_string(),
42			description: "Test description".to_string(),
43			renders: Some(vec!["application/json".to_string()]),
44			parses: Some(vec!["application/json".to_string()]),
45			actions: None,
46		};
47
48		let json = serde_json::to_string(&response).unwrap();
49		assert!(json.contains("Test View"));
50		assert!(json.contains("application/json"));
51	}
52}