Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/base/json_schema.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::schema;
use schemars::schema::{
ArrayValidation, InstanceType, ObjectValidation, Schema, SchemaObject, SingleOrVec,
ArrayValidation, InstanceType, Metadata, ObjectValidation, Schema, SchemaObject, SingleOrVec,
};

pub trait ToJsonSchema {
Expand Down Expand Up @@ -70,6 +70,10 @@ impl ToJsonSchema for schema::BasicValueType {
impl ToJsonSchema for schema::StructSchema {
fn to_json_schema(&self) -> SchemaObject {
SchemaObject {
metadata: Some(Box::new(Metadata {
description: self.description.as_ref().map(|s| s.to_string()),
..Default::default()
})),
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::Object))),
object: Some(Box::new(ObjectValidation {
properties: self
Expand Down
11 changes: 10 additions & 1 deletion src/base/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,16 @@ impl std::fmt::Display for BasicValueType {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct StructSchema {
pub fields: Arc<Vec<FieldSchema>>,

#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<Arc<str>>,
}

impl StructSchema {
pub fn without_attrs(&self) -> Self {
Self {
fields: Arc::new(self.fields.iter().map(|f| f.without_attrs()).collect()),
description: None,
}
}
}
Expand Down Expand Up @@ -168,11 +172,16 @@ impl std::fmt::Display for CollectionSchema {
}

impl CollectionSchema {
pub fn new(kind: CollectionKind, fields: Vec<FieldSchema>) -> Self {
pub fn new(
kind: CollectionKind,
fields: Vec<FieldSchema>,
description: Option<Arc<str>>,
) -> Self {
Self {
kind,
row: StructSchema {
fields: Arc::new(fields),
description,
},
collectors: Default::default(),
}
Expand Down
9 changes: 9 additions & 0 deletions src/builder/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl TryInto<ValueType> for &ValueTypeBuilder {
pub(super) struct StructSchemaBuilder {
fields: Vec<FieldSchema<ValueTypeBuilder>>,
field_name_idx: HashMap<FieldName, u32>,
description: Option<Arc<str>>,
}

impl StructSchemaBuilder {
Expand Down Expand Up @@ -91,6 +92,7 @@ impl TryFrom<&StructSchema> for StructSchemaBuilder {
let mut result = StructSchemaBuilder {
fields: Vec::with_capacity(schema.fields.len()),
field_name_idx: HashMap::with_capacity(schema.fields.len()),
description: schema.description.clone(),
};
for field in schema.fields.iter() {
result.add_field(FieldSchema::<ValueTypeBuilder>::from_alternative(field)?)?;
Expand All @@ -110,6 +112,7 @@ impl TryInto<StructSchema> for &StructSchemaBuilder {
.map(FieldSchema::<ValueType>::from_alternative)
.collect::<Result<Vec<_>>>()?,
),
description: self.description.clone(),
})
}
}
Expand Down Expand Up @@ -284,6 +287,10 @@ fn try_make_common_struct_schemas(
}
Ok(StructSchema {
fields: Arc::new(result_fields),
description: schema1
.description
.clone()
.or_else(|| schema2.description.clone()),
})
}

Expand Down Expand Up @@ -484,6 +491,7 @@ fn analyze_struct_mapping(
},
StructSchema {
fields: Arc::new(field_schemas),
description: None,
},
))
}
Expand Down Expand Up @@ -829,6 +837,7 @@ impl AnalyzerContext<'_> {
} else {
ValueType::Struct(StructSchema {
fields: Arc::from(key_fields_schema.clone()),
description: None,
})
};
let mut value_fields_schema: Vec<FieldSchema> = vec![];
Expand Down
1 change: 1 addition & 0 deletions src/builder/flow_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ impl FlowBuilder {
})
.collect(),
),
description: None,
};

{
Expand Down
1 change: 1 addition & 0 deletions src/ops/functions/split_recursively.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ impl SimpleFunctionFactoryBase for Factory {
FieldSchema::new("location", make_output_type(BasicValueType::Range)),
FieldSchema::new("text", make_output_type(BasicValueType::Str)),
],
None,
))
.with_attr(
field_attrs::CHUNK_BASE_TEXT,
Expand Down
1 change: 1 addition & 0 deletions src/ops/sources/google_drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ impl SourceFactoryBase for Factory {
}),
),
],
None,
)))
}

Expand Down
1 change: 1 addition & 0 deletions src/ops/sources/local_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ impl SourceFactoryBase for Factory {
}),
),
],
None,
)))
}

Expand Down