kanidmd_core/https/apidocs/
response_schema.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//! This file contains the default response schemas for the API.
//!
//! These are used to generate the OpenAPI schema definitions.
//!
use kanidm_proto::constants::APPLICATION_JSON;
use std::collections::BTreeMap;
use utoipa::{
    openapi::{Content, RefOr, Response, ResponseBuilder, ResponsesBuilder},
    IntoResponses, ToSchema,
};

#[allow(dead_code)] // because this is used for the OpenAPI schema gen
/// An empty response with `application/json` content type - use [ApiResponseWithout200] if you want to do everything but a 200
pub(crate) enum DefaultApiResponse {
    Ok,
    InvalidRequest,
    NeedsAuthorization,
    NotAuthorized,
}

impl IntoResponses for DefaultApiResponse {
    fn responses() -> BTreeMap<String, RefOr<Response>> {
        ResponsesBuilder::new()
            .response(
                "200",
                ResponseBuilder::new()
                    .content(APPLICATION_JSON, Content::default())
                    .description("Ok"),
            )
            .response("400", ResponseBuilder::new().description("Invalid Request"))
            .response(
                "401",
                ResponseBuilder::new().description("Authorization required"),
            )
            .response("403", ResponseBuilder::new().description("Not Authorized"))
            .build()
            .into()
    }
}

#[allow(dead_code)] // because this is used for the OpenAPI schema gen
/// A response set without the 200 status so the "defaults" can be handled.
pub(crate) enum ApiResponseWithout200 {
    InvalidRequest,
    NeedsAuthorization,
    NotAuthorized,
}

impl IntoResponses for ApiResponseWithout200 {
    fn responses() -> BTreeMap<String, RefOr<Response>> {
        ResponsesBuilder::new()
            .response("400", ResponseBuilder::new().description("Invalid Request"))
            .response(
                "401",
                ResponseBuilder::new().description("Authorization required"),
            )
            .response("403", ResponseBuilder::new().description("Not Authorized"))
            .build()
            .into()
    }
}

#[derive(Debug, Clone, ToSchema)]
// TODO: this should be `webauthn_rs_proto::auth::PublicKeyCredential``, but ... I don't know how to make it possible in utoipa
pub(crate) struct PublicKeyCredential {}

#[derive(Debug, Clone, ToSchema)]
// TODO: this should be `webauthn_rs_proto::auth::RequestChallengeResponse``, but ... I don't know how to make it possible in utoipa
pub(crate) struct RequestChallengeResponse {}

#[derive(Debug, Clone, ToSchema)]
// TODO: this should be `webauthn_rs_proto::auth::CreationChallengeResponse``, but ... I don't know how to make it possible in utoipa
pub(crate) struct CreationChallengeResponse {}

#[derive(Debug, Clone, ToSchema)]
// TODO: this should be `Base64UrlSafeData`, but ... I don't know how to make it possible in utoipa
pub(crate) struct Base64UrlSafeData {}

#[derive(Debug, Clone, ToSchema)]
// TODO: this should be handled elsewhere, but ... I don't know how to make it possible in utoipa
pub(crate) struct BTreeSet {}

#[derive(Debug, Clone, ToSchema)]
// TODO: this should be handled elsewhere, but ... I don't know how to make it possible in utoipa
pub(crate) struct Result {}

#[derive(Debug, Clone, ToSchema)]
// TODO: this should be handled elsewhere, but ... I don't know how to make it possible in utoipa
pub(crate) struct ScimEntry {}

#[derive(Debug, Clone, ToSchema)]
///  workaround for the fact that BTreeSet can't be represented in JSON
pub(crate) struct ProtoEntry {
    #[allow(dead_code, clippy::disallowed_types)] // because it's a schema definition
    attrs: BTreeMap<String, Vec<String>>,
}

#[derive(Debug, Clone, ToSchema)]
pub(crate) struct Jwk {}

#[derive(Debug, Clone, ToSchema)]
pub(crate) struct ScimComplexAttr {}