wme_models/content.rs
1//! Content types for the Wikimedia Enterprise API.
2//!
3//! This module provides types for article content including the body
4//! (HTML and wikitext), images, and license information.
5//!
6//! # Article Body
7//!
8//! The [`ArticleBody`] struct contains both HTML and wikitext representations
9//! of article content. Not all API endpoints return both - some may return
10//! only HTML or only wikitext depending on the fields requested.
11//!
12//! # Images
13//!
14//! [`Image`] provides metadata about images including dimensions and
15//! accessibility information (caption, alternative text).
16//!
17//! # Licenses
18//!
19//! Articles are typically licensed under Creative Commons licenses.
20//! The [`License`] type captures this information.
21
22use serde::{Deserialize, Serialize};
23
24/// Article body content.
25///
26/// Contains both HTML and wikitext representations of the article.
27/// Depending on the API endpoint and fields requested, one or both
28/// may be present.
29///
30/// # Example
31///
32/// ```
33/// use wme_models::ArticleBody;
34///
35/// let body = ArticleBody {
36/// html: Some("<p>Article content</p>".to_string()),
37/// wikitext: Some("Article content".to_string()),
38/// };
39/// ```
40#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
41pub struct ArticleBody {
42 /// HTML content (parsed from wikitext)
43 pub html: Option<String>,
44 /// Wikitext content (raw markup)
45 pub wikitext: Option<String>,
46}
47
48/// Image metadata.
49///
50/// Describes an image associated with an article. Includes
51/// dimensions and accessibility information.
52///
53/// # Example
54///
55/// ```
56/// use wme_models::Image;
57///
58/// let image = Image {
59/// content_url: "https://upload.wikimedia.org/...".to_string(),
60/// width: Some(800),
61/// height: Some(600),
62/// caption: Some("A squirrel in a tree".to_string()),
63/// alternative_text: Some("Gray squirrel sitting on branch".to_string()),
64/// };
65/// ```
66#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
67pub struct Image {
68 /// Content URL (direct link to image file)
69 pub content_url: String,
70 /// Image width in pixels
71 pub width: Option<u64>,
72 /// Image height in pixels
73 pub height: Option<u64>,
74 /// Image caption (displayed below image)
75 pub caption: Option<String>,
76 /// Alternative text for accessibility (screen readers)
77 pub alternative_text: Option<String>,
78}
79
80/// License information.
81///
82/// Describes the license under which article content is published.
83/// Most Wikimedia content is CC-BY-SA licensed.
84///
85/// # Example
86///
87/// ```
88/// use wme_models::License;
89///
90/// let license = License {
91/// identifier: Some("CC-BY-SA-4.0".to_string()),
92/// name: "Creative Commons Attribution Share Alike 4.0".to_string(),
93/// url: "https://creativecommons.org/licenses/by-sa/4.0/".to_string(),
94/// };
95/// ```
96#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
97pub struct License {
98 /// License identifier (e.g., "CC-BY-SA-4.0")
99 pub identifier: Option<String>,
100 /// License name
101 pub name: String,
102 /// License URL
103 pub url: String,
104}
105
106#[cfg(test)]
107mod tests {
108 use super::*;
109
110 #[test]
111 fn test_article_body() {
112 let body = ArticleBody {
113 html: Some("<p>Test content</p>".to_string()),
114 wikitext: Some("Test content".to_string()),
115 };
116
117 assert!(body.html.is_some());
118 assert!(body.wikitext.is_some());
119 }
120
121 #[test]
122 fn test_image() {
123 let image = Image {
124 content_url: "https://example.com/image.jpg".to_string(),
125 width: Some(800),
126 height: Some(600),
127 caption: Some("Test image".to_string()),
128 alternative_text: Some("Alt text".to_string()),
129 };
130
131 assert_eq!(image.width, Some(800));
132 assert_eq!(image.height, Some(600));
133 }
134
135 #[test]
136 fn test_license() {
137 let license = License {
138 identifier: Some("CC-BY-SA-4.0".to_string()),
139 name: "Creative Commons Attribution Share Alike 4.0".to_string(),
140 url: "https://creativecommons.org/licenses/by-sa/4.0/".to_string(),
141 };
142
143 assert_eq!(license.identifier, Some("CC-BY-SA-4.0".to_string()));
144 }
145}