restify_openapi/models/
server.rs

1use indexmap::IndexMap;
2use serde::Serialize;
3use serde_json::Value;
4use std::collections::BTreeMap;
5
6/// An object representing a Server.
7#[derive(Serialize, Clone, Debug, Default)]
8#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
9#[serde(rename_all = "camelCase")]
10pub struct Server {
11  /// A URL to the target host. This URL supports Server Variables and MAY be relative, to indicate that the host location is relative to the location where the OpenAPI document is being served. Variable substitutions will be made when a variable is named in `{`brackets`}`.
12  pub url: String,
13  /// An optional string describing the host designated by the URL. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
14  #[serde(skip_serializing_if = "Option::is_none")]
15  pub description: Option<String>,
16  /// A map between a variable name and its value. The value is used for substitution in the server's URL template.
17  #[serde(skip_serializing_if = "BTreeMap::is_empty", default)]
18  pub variables: BTreeMap<String, ServerVariable>,
19  /// This object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions).
20  #[serde(flatten, skip_serializing_if = "IndexMap::is_empty", skip_deserializing)]
21  pub extensions: IndexMap<String, Value>,
22}
23
24/// An object representing a Server Variable for server URL template substitution.
25#[derive(Serialize, Clone, Debug, Default)]
26#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
27#[serde(rename_all = "camelCase")]
28pub struct ServerVariable {
29  /// An enumeration of string values to be used if the substitution options are from a limited set. The array SHOULD NOT be empty.
30  #[serde(rename = "enum")]
31  pub _enum: Vec<String>,
32  /// The default value to use for substitution, which SHALL be sent if an alternate value is not supplied. Note this behavior is different than the [Schema Object's](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object) treatment of default values, because in those cases parameter values are optional. If the [`enum`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverVariableEnum) is defined, the value SHOULD exist in the enum's values.
33  pub default: String,
34  /// An optional description for the server variable. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
35  #[serde(skip_serializing_if = "Option::is_none")]
36  pub description: Option<String>,
37}