mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 03:55:07 +08:00
move the components to the top level and fix the auth
This commit is contained in:
parent
53ef84f4dc
commit
074de661b4
@ -6,7 +6,6 @@ use std::str::FromStr;
|
|||||||
use deserr::{DeserializeError, Deserr, MergeWithError, ValueKind};
|
use deserr::{DeserializeError, Deserr, MergeWithError, ValueKind};
|
||||||
use serde::de::Visitor;
|
use serde::de::Visitor;
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use utoipa::{IntoParams, ToSchema};
|
|
||||||
|
|
||||||
use crate::deserr::query_params::FromQueryParameter;
|
use crate::deserr::query_params::FromQueryParameter;
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ use milli::Object;
|
|||||||
use roaring::RoaringBitmap;
|
use roaring::RoaringBitmap;
|
||||||
use serde::{Deserialize, Serialize, Serializer};
|
use serde::{Deserialize, Serialize, Serializer};
|
||||||
use time::{Duration, OffsetDateTime};
|
use time::{Duration, OffsetDateTime};
|
||||||
use utoipa::{IntoParams, ToSchema};
|
use utoipa::ToSchema;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::error::ResponseError;
|
use crate::error::ResponseError;
|
||||||
|
@ -24,7 +24,6 @@ use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
|
|||||||
use tracing::level_filters::LevelFilter;
|
use tracing::level_filters::LevelFilter;
|
||||||
use tracing_subscriber::layer::SubscriberExt as _;
|
use tracing_subscriber::layer::SubscriberExt as _;
|
||||||
use tracing_subscriber::Layer;
|
use tracing_subscriber::Layer;
|
||||||
use utoipa::OpenApi;
|
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOC: MiMalloc = MiMalloc;
|
static ALLOC: MiMalloc = MiMalloc;
|
||||||
|
@ -8,8 +8,16 @@ use actix_web::web::Data;
|
|||||||
use actix_web::{web, HttpRequest, HttpResponse};
|
use actix_web::{web, HttpRequest, HttpResponse};
|
||||||
use index_scheduler::IndexScheduler;
|
use index_scheduler::IndexScheduler;
|
||||||
use meilisearch_auth::AuthController;
|
use meilisearch_auth::AuthController;
|
||||||
|
use meilisearch_types::error::ErrorType;
|
||||||
use meilisearch_types::error::{Code, ResponseError};
|
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::settings::{Settings, Unchecked};
|
||||||
|
use meilisearch_types::task_view::DetailsView;
|
||||||
|
use meilisearch_types::task_view::TaskView;
|
||||||
use meilisearch_types::tasks::{Kind, Status, Task, TaskId};
|
use meilisearch_types::tasks::{Kind, Status, Task, TaskId};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
@ -19,6 +27,9 @@ use utoipa::ToSchema;
|
|||||||
use utoipa_rapidoc::RapiDoc;
|
use utoipa_rapidoc::RapiDoc;
|
||||||
use utoipa_scalar::{Scalar, Servable as ScalarServable};
|
use utoipa_scalar::{Scalar, Servable as ScalarServable};
|
||||||
|
|
||||||
|
use self::open_api_utils::OpenApiAuth;
|
||||||
|
use self::tasks::AllTasks;
|
||||||
|
|
||||||
const PAGINATION_DEFAULT_LIMIT: usize = 20;
|
const PAGINATION_DEFAULT_LIMIT: usize = 20;
|
||||||
|
|
||||||
mod api_key;
|
mod api_key;
|
||||||
@ -35,7 +46,9 @@ pub mod tasks;
|
|||||||
|
|
||||||
#[derive(OpenApi)]
|
#[derive(OpenApi)]
|
||||||
#[openapi(
|
#[openapi(
|
||||||
nest((path = "/tasks", api = tasks::TaskApi) ),
|
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;
|
pub struct MeilisearchApi;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ use serde::Serialize;
|
|||||||
use utoipa::openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme};
|
use utoipa::openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme};
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub(super) struct OpenApiAuth;
|
pub struct OpenApiAuth;
|
||||||
|
|
||||||
impl utoipa::Modify for OpenApiAuth {
|
impl utoipa::Modify for OpenApiAuth {
|
||||||
fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
|
fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
|
||||||
|
@ -5,15 +5,11 @@ use deserr::Deserr;
|
|||||||
use index_scheduler::{IndexScheduler, Query, TaskId};
|
use index_scheduler::{IndexScheduler, Query, TaskId};
|
||||||
use meilisearch_types::deserr::query_params::Param;
|
use meilisearch_types::deserr::query_params::Param;
|
||||||
use meilisearch_types::deserr::DeserrQueryParamError;
|
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::error::{InvalidTaskDateError, ResponseError};
|
||||||
use meilisearch_types::index_uid::IndexUid;
|
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::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 meilisearch_types::tasks::{Kind, KindWithContent, Status};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
@ -23,7 +19,7 @@ use time::{Date, Duration, OffsetDateTime, Time};
|
|||||||
use tokio::task;
|
use tokio::task;
|
||||||
use utoipa::{IntoParams, OpenApi, ToSchema};
|
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 super::{get_task_id, is_dry_run, SummarizedTaskView};
|
||||||
use crate::analytics::Analytics;
|
use crate::analytics::Analytics;
|
||||||
use crate::extractors::authentication::policies::*;
|
use crate::extractors::authentication::policies::*;
|
||||||
@ -33,6 +29,29 @@ use crate::Opt;
|
|||||||
|
|
||||||
const DEFAULT_LIMIT: u32 = 20;
|
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)]
|
#[derive(OpenApi)]
|
||||||
#[openapi(
|
#[openapi(
|
||||||
paths(get_tasks, delete_tasks, cancel_tasks, get_task),
|
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"),
|
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;
|
pub struct TaskApi;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user