move the components to the top level and fix the auth

This commit is contained in:
Tamo 2024-10-07 15:25:49 +02:00
parent 53ef84f4dc
commit 074de661b4
6 changed files with 42 additions and 14 deletions

View File

@ -6,7 +6,6 @@ use std::str::FromStr;
use deserr::{DeserializeError, Deserr, MergeWithError, ValueKind};
use serde::de::Visitor;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use utoipa::{IntoParams, ToSchema};
use crate::deserr::query_params::FromQueryParameter;

View File

@ -9,7 +9,7 @@ use milli::Object;
use roaring::RoaringBitmap;
use serde::{Deserialize, Serialize, Serializer};
use time::{Duration, OffsetDateTime};
use utoipa::{IntoParams, ToSchema};
use utoipa::ToSchema;
use uuid::Uuid;
use crate::error::ResponseError;

View File

@ -24,7 +24,6 @@ use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
use tracing::level_filters::LevelFilter;
use tracing_subscriber::layer::SubscriberExt as _;
use tracing_subscriber::Layer;
use utoipa::OpenApi;
#[global_allocator]
static ALLOC: MiMalloc = MiMalloc;

View File

@ -8,8 +8,16 @@ use actix_web::web::Data;
use actix_web::{web, HttpRequest, HttpResponse};
use index_scheduler::IndexScheduler;
use meilisearch_auth::AuthController;
use meilisearch_types::error::ErrorType;
use meilisearch_types::error::{Code, ResponseError};
use meilisearch_types::settings::Checked;
use meilisearch_types::settings::FacetingSettings;
use meilisearch_types::settings::MinWordSizeTyposSetting;
use meilisearch_types::settings::PaginationSettings;
use meilisearch_types::settings::TypoSettings;
use meilisearch_types::settings::{Settings, Unchecked};
use meilisearch_types::task_view::DetailsView;
use meilisearch_types::task_view::TaskView;
use meilisearch_types::tasks::{Kind, Status, Task, TaskId};
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
@ -19,6 +27,9 @@ use utoipa::ToSchema;
use utoipa_rapidoc::RapiDoc;
use utoipa_scalar::{Scalar, Servable as ScalarServable};
use self::open_api_utils::OpenApiAuth;
use self::tasks::AllTasks;
const PAGINATION_DEFAULT_LIMIT: usize = 20;
mod api_key;
@ -36,6 +47,8 @@ pub mod tasks;
#[derive(OpenApi)]
#[openapi(
nest((path = "/tasks", api = tasks::TaskApi) ),
modifiers(&OpenApiAuth),
components(schemas(Code, ErrorType, AllTasks, TaskView, Status, DetailsView, ResponseError, Settings<Unchecked>, Settings<Checked>, TypoSettings, MinWordSizeTyposSetting, FacetingSettings, PaginationSettings, SummarizedTaskView, Kind))
)]
pub struct MeilisearchApi;

View File

@ -2,7 +2,7 @@ use serde::Serialize;
use utoipa::openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme};
#[derive(Debug, Serialize)]
pub(super) struct OpenApiAuth;
pub struct OpenApiAuth;
impl utoipa::Modify for OpenApiAuth {
fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {

View File

@ -5,15 +5,11 @@ use deserr::Deserr;
use index_scheduler::{IndexScheduler, Query, TaskId};
use meilisearch_types::deserr::query_params::Param;
use meilisearch_types::deserr::DeserrQueryParamError;
use meilisearch_types::error::{deserr_codes::*, Code, ErrorType};
use meilisearch_types::error::deserr_codes::*;
use meilisearch_types::error::{InvalidTaskDateError, ResponseError};
use meilisearch_types::index_uid::IndexUid;
use meilisearch_types::settings::{
Checked, FacetingSettings, MinWordSizeTyposSetting, PaginationSettings, Settings, TypoSettings,
Unchecked,
};
use meilisearch_types::star_or::{OptionStarOr, OptionStarOrList};
use meilisearch_types::task_view::{DetailsView, TaskView};
use meilisearch_types::task_view::TaskView;
use meilisearch_types::tasks::{Kind, KindWithContent, Status};
use serde::Serialize;
use serde_json::json;
@ -23,7 +19,7 @@ use time::{Date, Duration, OffsetDateTime, Time};
use tokio::task;
use utoipa::{IntoParams, OpenApi, ToSchema};
use super::open_api_utils::OpenApiAuth;
// use super::open_api_utils::OpenApiAuth;
use super::{get_task_id, is_dry_run, SummarizedTaskView};
use crate::analytics::Analytics;
use crate::extractors::authentication::policies::*;
@ -33,6 +29,29 @@ use crate::Opt;
const DEFAULT_LIMIT: u32 = 20;
#[derive(Debug, Serialize)]
pub struct OpenApiAuth;
impl utoipa::Modify for OpenApiAuth {
fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
if let Some(schema) = openapi.components.as_mut() {
schema.add_security_scheme(
"Bearer",
utoipa::openapi::security::SecurityScheme::Http(
utoipa::openapi::security::HttpBuilder::new()
.scheme(utoipa::openapi::security::HttpAuthScheme::Bearer)
.bearer_format("Uuidv4, string or JWT")
.description(Some(
"An API key is a token that you provide when making API calls. Include the token in a header parameter called `Authorization`.
Example: `Authorization: Bearer 8fece4405662dd830e4cb265e7e047aab2e79672a760a12712d2a263c9003509`"))
.build(),
),
);
}
}
}
#[derive(OpenApi)]
#[openapi(
paths(get_tasks, delete_tasks, cancel_tasks, get_task),
@ -42,8 +61,6 @@ const DEFAULT_LIMIT: u32 = 20;
external_docs(url = "https://www.meilisearch.com/docs/reference/api/tasks"),
)),
modifiers(&OpenApiAuth),
components(schemas(Code, ErrorType, AllTasks, TaskView, Status, DetailsView, ResponseError, Settings<Unchecked>, Settings<Checked>, TypoSettings, MinWordSizeTyposSetting, FacetingSettings, PaginationSettings, SummarizedTaskView, Kind))
)]
pub struct TaskApi;