Schema endpoint
This commit is contained in:
31
crates/pile-dataset/src/serve/schema.rs
Normal file
31
crates/pile-dataset/src/serve/schema.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use axum::{
|
||||
Json,
|
||||
extract::State,
|
||||
http::StatusCode,
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
pub use pile_config::FieldSpec;
|
||||
|
||||
use crate::Datasets;
|
||||
|
||||
pub type FieldsResponse = HashMap<String, FieldSpec>;
|
||||
|
||||
/// Retrieve this dataset's schema.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/schema",
|
||||
responses(
|
||||
(status = 200, description = "This dataset's schema"),
|
||||
)
|
||||
)]
|
||||
pub async fn get_schema(State(state): State<Arc<Datasets>>) -> Response {
|
||||
let fields: FieldsResponse = state
|
||||
.config
|
||||
.schema
|
||||
.iter()
|
||||
.map(|(k, v)| (k.as_str().to_owned(), v.clone()))
|
||||
.collect();
|
||||
(StatusCode::OK, Json(fields)).into_response()
|
||||
}
|
||||
Reference in New Issue
Block a user