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};
1112#[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 {
15Ok,
16 InvalidRequest,
17 NeedsAuthorization,
18 NotAuthorized,
19}
2021impl IntoResponses for DefaultApiResponse {
22fn 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}
4041#[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}
4849impl IntoResponses for ApiResponseWithout200 {
50fn 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}
6263#[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 {}
6667#[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 {}
7071#[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 {}
7475#[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 {}
7879#[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 {}
8283#[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 {}
8687#[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 {}
9091#[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
95attrs: BTreeMap<String, Vec<String>>,
96}
9798#[derive(Debug, Clone, ToSchema)]
99pub(crate) struct Jwk {}
100101#[derive(Debug, Clone, ToSchema)]
102pub(crate) struct ScimComplexAttr {}