openstack_keystone_api_types/
version.rs1use 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#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema, Validate)]
29pub struct Versions {
30 #[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#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema, Validate)]
43pub struct Values {
44 #[validate(nested)]
45 pub values: Vec<Version>,
46}
47
48#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema, Validate)]
50pub struct SingleVersion {
51 #[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#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema, Validate)]
64pub struct Version {
65 #[validate(length(max = 5))]
67 pub id: String,
68 pub status: VersionStatus,
70 #[serde(skip_serializing_if = "Option::is_none")]
72 pub updated: Option<DateTime<Utc>>,
73 #[serde(skip_serializing_if = "Option::is_none")]
75 #[validate(nested)]
76 pub links: Option<Vec<Link>>,
77 #[serde(skip_serializing_if = "Option::is_none")]
79 #[validate(nested)]
80 pub media_types: Option<Vec<MediaType>>,
81}
82
83#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema)]
85pub enum VersionStatus {
86 #[default]
88 #[serde(rename = "stable")]
89 Stable,
90 #[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}