oas3/spec/server.rs
1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4
5/// An object representing a Server.
6///
7/// See <https://spec.openapis.org/oas/v3.1.1#server-object>.
8#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
9pub struct Server {
10 /// A URL to the target host.
11 ///
12 /// This URL supports Server Variables and MAY be relative, to indicate that the host location
13 /// is relative to the location where the OpenAPI document is being served. Variable
14 /// substitutions will be made when a variable is named in {brackets}.
15 pub url: String,
16
17 /// An optional string describing the host designated by the URL.
18 ///
19 /// CommonMark syntax MAY be used for rich text representation.
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub description: Option<String>,
22
23 /// A map between a variable name and its value.
24 ///
25 /// The value is used for substitution in the server's URL template.
26 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
27 pub variables: BTreeMap<String, ServerVariable>,
28}
29
30/// An object representing a Server Variable for server URL template substitution.
31///
32/// See <https://spec.openapis.org/oas/v3.1.1#server-variable-object>.
33#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
34pub struct ServerVariable {
35 /// The default value to use for substitution, and to send, if an alternate value is not
36 /// supplied.
37 ///
38 /// Unlike the Schema Object's default, this value MUST be provided by the consumer.
39 pub default: String,
40
41 /// An enumeration of string values to be used if the substitution options are from a limited
42 /// set.
43 #[serde(rename = "enum", default, skip_serializing_if = "Vec::is_empty")]
44 pub substitutions_enum: Vec<String>,
45
46 /// An optional description for the server variable. [CommonMark] syntax MAY be used for rich
47 /// text representation.
48 ///
49 /// [CommonMark]: https://spec.commonmark.org/
50 #[serde(skip_serializing_if = "Option::is_none")]
51 pub description: Option<String>,
52}