Skip to main content

openstack_keystone_api_types/
version.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5//     http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12//
13// SPDX-License-Identifier: Apache-2.0
14//! Keystone version API types
15use axum::{
16    Json,
17    http::StatusCode,
18    response::{IntoResponse, Response},
19};
20use chrono::{DateTime, Utc};
21use serde::{Deserialize, Serialize};
22use utoipa::ToSchema;
23use validator::Validate;
24
25use crate::Link;
26
27/// List of the supported API versions as [Values].
28#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema, Validate)]
29pub struct Versions {
30    /// List of the versions.
31    #[validate(nested)]
32    pub versions: Values,
33}
34
35impl IntoResponse for Versions {
36    fn into_response(self) -> Response {
37        (StatusCode::OK, Json(self)).into_response()
38    }
39}
40
41/// A container with the [Version] list.
42#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema, Validate)]
43pub struct Values {
44    #[validate(nested)]
45    pub values: Vec<Version>,
46}
47
48/// Single API version container.
49#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema, Validate)]
50pub struct SingleVersion {
51    /// The version.
52    #[validate(nested)]
53    pub version: Version,
54}
55
56impl IntoResponse for SingleVersion {
57    fn into_response(self) -> Response {
58        (StatusCode::OK, Json(self)).into_response()
59    }
60}
61
62/// Single API version.
63#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema, Validate)]
64pub struct Version {
65    /// Version id.
66    #[validate(length(max = 5))]
67    pub id: String,
68    /// Version status.
69    pub status: VersionStatus,
70    /// Date of the version update.
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub updated: Option<DateTime<Utc>>,
73    /// Links to the API version.
74    #[serde(skip_serializing_if = "Option::is_none")]
75    #[validate(nested)]
76    pub links: Option<Vec<Link>>,
77    /// Supported media types.
78    #[serde(skip_serializing_if = "Option::is_none")]
79    #[validate(nested)]
80    pub media_types: Option<Vec<MediaType>>,
81}
82
83/// Version status.
84#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema)]
85pub enum VersionStatus {
86    /// Stable.
87    #[default]
88    #[serde(rename = "stable")]
89    Stable,
90    /// Experimental.
91    #[serde(rename = "experimental")]
92    Experimental,
93}
94
95#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, ToSchema, Validate)]
96pub struct MediaType {
97    pub base: String,
98    pub r#type: String,
99}
100
101impl Default for MediaType {
102    fn default() -> Self {
103        Self {
104            base: "application/json".into(),
105            r#type: "application/vnd.openstack.identity-v3+json".into(),
106        }
107    }
108}