bevy_remote/schemas/
open_rpc.rs1use bevy_platform::collections::HashMap;
4use bevy_utils::default;
5use serde::{Deserialize, Serialize};
6
7use crate::RemoteMethods;
8
9use super::json_schema::JsonSchemaBevyType;
10
11#[derive(Debug, Serialize, Deserialize)]
13#[serde(rename_all = "camelCase")]
14pub struct OpenRpcDocument {
15 pub openrpc: String,
17 pub info: InfoObject,
19 pub methods: Vec<MethodObject>,
21 pub servers: Option<Vec<ServerObject>>,
23}
24
25#[derive(Serialize, Deserialize, Debug)]
27#[serde(rename_all = "camelCase")]
28pub struct InfoObject {
29 pub title: String,
31 pub version: String,
33 #[serde(skip_serializing_if = "Option::is_none")]
35 pub description: Option<String>,
36 #[serde(flatten)]
38 pub extensions: HashMap<String, serde_json::Value>,
39}
40
41impl Default for InfoObject {
42 fn default() -> Self {
43 Self {
44 title: "Bevy Remote Protocol".to_owned(),
45 version: env!("CARGO_PKG_VERSION").to_owned(),
46 description: None,
47 extensions: Default::default(),
48 }
49 }
50}
51
52#[derive(Serialize, Deserialize, Debug, Default)]
54#[serde(rename_all = "camelCase")]
55pub struct ServerObject {
56 pub name: String,
58 pub url: String,
60 #[serde(skip_serializing_if = "Option::is_none")]
62 pub description: Option<String>,
63 #[serde(flatten)]
65 pub extensions: HashMap<String, serde_json::Value>,
66}
67
68#[derive(Serialize, Deserialize, Debug, Default)]
70#[serde(rename_all = "camelCase")]
71pub struct MethodObject {
72 #[expect(
73 clippy::doc_markdown,
74 reason = "In this case, we are referring to a string, so using quotes instead of backticks makes sense."
75 )]
76 pub name: String,
78 #[serde(skip_serializing_if = "Option::is_none")]
80 pub summary: Option<String>,
81 #[serde(skip_serializing_if = "Option::is_none")]
83 pub description: Option<String>,
84 #[serde(default)]
86 pub params: Vec<Parameter>,
87 #[serde(flatten)]
92 pub extensions: HashMap<String, serde_json::Value>,
93}
94
95#[derive(Serialize, Deserialize, Debug)]
97#[serde(rename_all = "camelCase")]
98pub struct Parameter {
99 pub name: String,
101 #[serde(skip_serializing_if = "Option::is_none")]
103 pub description: Option<String>,
104 pub schema: JsonSchemaBevyType,
106 #[serde(flatten)]
108 pub extensions: HashMap<String, serde_json::Value>,
109}
110
111impl From<&RemoteMethods> for Vec<MethodObject> {
112 fn from(value: &RemoteMethods) -> Self {
113 value
114 .methods()
115 .iter()
116 .map(|e| MethodObject {
117 name: e.to_owned(),
118 ..default()
119 })
120 .collect()
121 }
122}