|
| 1 | +// Copyright 2022 The Matrix.org Foundation C.I.C. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#![forbid(unsafe_code)] |
| 16 | +#![deny( |
| 17 | + clippy::all, |
| 18 | + clippy::str_to_string, |
| 19 | + rustdoc::broken_intra_doc_links, |
| 20 | + clippy::future_not_send |
| 21 | +)] |
| 22 | +#![warn(clippy::pedantic)] |
| 23 | + |
| 24 | +use std::io::Write; |
| 25 | + |
| 26 | +/// This is a dummy state, it should never be used. |
| 27 | +/// |
| 28 | +/// We use it to generate the API schema, which doesn't execute any request. |
| 29 | +#[derive(Clone)] |
| 30 | +struct DummyState; |
| 31 | + |
| 32 | +macro_rules! impl_from_request_parts { |
| 33 | + ($type:ty) => { |
| 34 | + #[axum::async_trait] |
| 35 | + impl axum::extract::FromRequestParts<DummyState> for $type { |
| 36 | + type Rejection = std::convert::Infallible; |
| 37 | + |
| 38 | + async fn from_request_parts( |
| 39 | + _parts: &mut axum::http::request::Parts, |
| 40 | + _state: &DummyState, |
| 41 | + ) -> Result<Self, Self::Rejection> { |
| 42 | + unimplemented!("This is a dummy state, it should never be used") |
| 43 | + } |
| 44 | + } |
| 45 | + }; |
| 46 | +} |
| 47 | + |
| 48 | +macro_rules! impl_from_ref { |
| 49 | + ($type:ty) => { |
| 50 | + impl axum::extract::FromRef<DummyState> for $type { |
| 51 | + fn from_ref(_input: &DummyState) -> Self { |
| 52 | + unimplemented!("This is a dummy state, it should never be used") |
| 53 | + } |
| 54 | + } |
| 55 | + }; |
| 56 | +} |
| 57 | + |
| 58 | +impl_from_request_parts!(mas_storage::BoxRepository); |
| 59 | +impl_from_request_parts!(mas_storage::BoxClock); |
| 60 | +impl_from_request_parts!(mas_handlers::BoundActivityTracker); |
| 61 | +impl_from_ref!(mas_keystore::Keystore); |
| 62 | + |
| 63 | +fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 64 | + let (api, _) = mas_handlers::admin_api_router::<DummyState>(); |
| 65 | + let mut stdout = std::io::stdout(); |
| 66 | + serde_json::to_writer_pretty(&mut stdout, &api)?; |
| 67 | + |
| 68 | + // Make sure we end with a newline |
| 69 | + stdout.write_all(b"\n")?; |
| 70 | + |
| 71 | + Ok(()) |
| 72 | +} |
0 commit comments