kanidmd_core/https/apidocs/
response_schema.rs

1//! This file contains the default response schemas for the API.
2//!
3//! These are used to generate the OpenAPI schema definitions.
4//!
5use kanidm_proto::constants::APPLICATION_JSON;
6use std::collections::BTreeMap;
7use utoipa::{
8    openapi::{Content, RefOr, Response, ResponseBuilder, ResponsesBuilder},
9    IntoResponses, ToSchema,
10};
11
12#[allow(dead_code)] // because this is used for the OpenAPI schema gen
13/// An empty response with `application/json` content type - use [ApiResponseWithout200] if you want to do everything but a 200
14pub(crate) enum DefaultApiResponse {
15    Ok,
16    InvalidRequest,
17    NeedsAuthorization,
18    NotAuthorized,
19}
20
21impl IntoResponses for DefaultApiResponse {
22    fn responses() -> BTreeMap<String, RefOr<Response>> {
23        ResponsesBuilder::new()
24            .response(
25                "200",
26                ResponseBuilder::new()
27                    .content(APPLICATION_JSON, Content::default())
28                    .description("Ok"),
29            )
30            .response("400", ResponseBuilder::new().description("Invalid Request"))
31            .response(
32                "401",
33                ResponseBuilder::new().description("Authorization required"),
34            )
35            .response("403", ResponseBuilder::new().description("Not Authorized"))
36            .build()
37            .into()
38    }
39}
40
41#[allow(dead_code)] // because this is used for the OpenAPI schema gen
42/// A response set without the 200 status so the "defaults" can be handled.
43pub(crate) enum ApiResponseWithout200 {
44    InvalidRequest,
45    NeedsAuthorization,
46    NotAuthorized,
47}
48
49impl IntoResponses for ApiResponseWithout200 {
50    fn responses() -> BTreeMap<String, RefOr<Response>> {
51        ResponsesBuilder::new()
52            .response("400", ResponseBuilder::new().description("Invalid Request"))
53            .response(
54                "401",
55                ResponseBuilder::new().description("Authorization required"),
56            )
57            .response("403", ResponseBuilder::new().description("Not Authorized"))
58            .build()
59            .into()
60    }
61}
62
63#[derive(Debug, Clone, ToSchema)]
64// TODO: this should be `webauthn_rs_proto::auth::PublicKeyCredential``, but ... I don't know how to make it possible in utoipa
65pub(crate) struct PublicKeyCredential {}
66
67#[derive(Debug, Clone, ToSchema)]
68// TODO: this should be `webauthn_rs_proto::auth::RequestChallengeResponse``, but ... I don't know how to make it possible in utoipa
69pub(crate) struct RequestChallengeResponse {}
70
71#[derive(Debug, Clone, ToSchema)]
72// TODO: this should be `webauthn_rs_proto::auth::CreationChallengeResponse``, but ... I don't know how to make it possible in utoipa
73pub(crate) struct CreationChallengeResponse {}
74
75#[derive(Debug, Clone, ToSchema)]
76// TODO: this should be `Base64UrlSafeData`, but ... I don't know how to make it possible in utoipa
77pub(crate) struct Base64UrlSafeData {}
78
79#[derive(Debug, Clone, ToSchema)]
80// TODO: this should be handled elsewhere, but ... I don't know how to make it possible in utoipa
81pub(crate) struct BTreeSet {}
82
83#[derive(Debug, Clone, ToSchema)]
84// TODO: this should be handled elsewhere, but ... I don't know how to make it possible in utoipa
85pub(crate) struct Result {}
86
87#[derive(Debug, Clone, ToSchema)]
88// TODO: this should be handled elsewhere, but ... I don't know how to make it possible in utoipa
89pub(crate) struct ScimEntry {}
90
91#[derive(Debug, Clone, ToSchema)]
92///  workaround for the fact that BTreeSet can't be represented in JSON
93pub(crate) struct ProtoEntry {
94    #[allow(dead_code, clippy::disallowed_types)] // because it's a schema definition
95    attrs: BTreeMap<String, Vec<String>>,
96}
97
98#[derive(Debug, Clone, ToSchema)]
99pub(crate) struct Jwk {}
100
101#[derive(Debug, Clone, ToSchema)]
102pub(crate) struct ScimComplexAttr {}