Schema endpoint

This commit is contained in:
2026-03-26 20:04:33 -07:00
parent fac300431a
commit 256af68382
4 changed files with 49 additions and 4 deletions

View File

@@ -23,10 +23,13 @@ pub use field::*;
mod items;
pub use items::*;
mod schema;
pub use schema::*;
#[derive(OpenApi)]
#[openapi(
tags(),
paths(lookup, item_get, get_extract, items_list, get_field),
paths(lookup, item_get, get_extract, items_list, get_field, get_schema),
components(schemas(
LookupRequest,
LookupResponse,
@@ -55,6 +58,7 @@ impl Datasets {
.route("/extract", get(get_extract))
.route("/field", get(get_field))
.route("/items", get(items_list))
.route("/schema", get(get_schema))
.with_state(self.clone());
if let Some(prefix) = prefix {

View 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()
}