Skip to content
Closed
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
45 changes: 35 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ globset = { version = "0.4.16", features = ["serde1"] }
miette = { version = "7.6.0", features = ["fancy", "serde"] }
include_dir = "0.7.4"
tempfile = "3.23.0"
schemars = "0.8.22"
schemars = "1.0.0"
dirs = "6.0.0"
once_cell = "1.21.3"
opentelemetry = { version = "0.31.0", features = ["trace", "metrics", "logs"] }
Expand Down
36 changes: 17 additions & 19 deletions crates/weaver_semconv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use crate::Error::CompoundError;
use miette::{Diagnostic, NamedSource, SourceSpan};
use schemars::schema::{InstanceType, Schema};
use schemars::{JsonSchema, SchemaGenerator};
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
Expand Down Expand Up @@ -392,28 +391,27 @@ impl From<Error> for DiagnosticMessages {
pub struct YamlValue(pub serde_yaml::value::Value);

impl JsonSchema for YamlValue {
fn schema_name() -> String {
"YamlValue".to_owned()
fn schema_name() -> Cow<'static, str> {
Cow::Borrowed("YamlValue")
}

fn json_schema(_: &mut SchemaGenerator) -> Schema {
fn json_schema(_: &mut SchemaGenerator) -> schemars::Schema {
// Create a schema that accepts any type
let schema = schemars::schema::SchemaObject {
instance_type: Some(
vec![
InstanceType::Null,
InstanceType::Boolean,
InstanceType::Object,
InstanceType::Array,
InstanceType::Number,
InstanceType::String,
schemars::json_schema!({
"$ref": "#/definitions/Value",
"definitions": {
"Value": {
"type": [
"object",
"array",
"string",
"number",
"boolean",
"null"
]
.into(),
),
..Default::default()
};

Schema::Object(schema)
}
}
})
}
}

Expand Down
48 changes: 1 addition & 47 deletions crates/weaver_semconv/src/semconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum SemConvSpec {
}

/// A versioned semantic convention file.
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
#[serde(tag = "version")]
pub enum Versioned {
/// Version 1 of the semantic convention schema.
Expand All @@ -36,52 +36,6 @@ pub enum Versioned {
V2(SemConvSpecV2),
}

// Note: We automatically create the Schemars code and provide `allow(unused_qualifications)` to work around schemars limitations.
// You can use `cargo expand -p weaver_semconv` to find this code and generate it in the future.
const _: () = {
#[automatically_derived]
#[allow(unused_braces, unused_qualifications)]
impl schemars::JsonSchema for Versioned {
fn schema_name() -> std::string::String {
"Versioned".to_owned()
}
fn schema_id() -> std::borrow::Cow<'static, str> {
std::borrow::Cow::Borrowed("weaver_semconv::semconv::Versioned")
}
fn json_schema(generator: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
schemars::_private::metadata::add_description(
schemars::schema::Schema::Object(schemars::schema::SchemaObject {
subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
one_of: Some(<[_]>::into_vec(Box::new([
schemars::_private::metadata::add_description(
schemars::_private::new_internally_tagged_enum(
"version", "1", false,
),
"Version 1 of the semantic convention schema.",
)
.flatten(
<SemConvSpecV1 as schemars::JsonSchema>::json_schema(generator),
),
schemars::_private::metadata::add_description(
schemars::_private::new_internally_tagged_enum(
"version", "2", false,
),
"Version 2 of the semantic convention schema.",
)
.flatten(
<SemConvSpecV2 as schemars::JsonSchema>::json_schema(generator),
),
]))),
..Default::default()
})),
..Default::default()
}),
"A versioned semantic convention file.",
)
}
}
};

/// A semantic convention file as defined [here](/schemas/semconv.schema.json)
/// A semconv file is a collection of semantic convention groups (i.e. [`GroupSpec`]).
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema, PartialEq)]
Expand Down
50 changes: 1 addition & 49 deletions crates/weaver_semconv/src/v2/attribute_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct PublicAttributeGroup {
}

/// Attribute group definition.
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
#[serde(tag = "visibility")]
#[serde(rename_all = "snake_case")]
#[serde(deny_unknown_fields)]
Expand All @@ -56,54 +56,6 @@ pub enum AttributeGroup {
Public(PublicAttributeGroup),
}

// Note: We automatically create the Schemars code and provide `allow(unused_qualifications)` to work around schemars limitations.
// You can use `cargo expand -p weaver_semconv` to find this code and generate it in the future.
const _: () = {
#[automatically_derived]
#[allow(unused_braces)]
impl JsonSchema for AttributeGroup {
fn schema_name() -> String {
"AttributeGroup".to_owned()
}
fn schema_id() -> std::borrow::Cow<'static, str> {
std::borrow::Cow::Borrowed("weaver_semconv::v2::attribute_group::AttributeGroup")
}
fn json_schema(generator: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
schemars::_private::metadata::add_description(
schemars::schema::Schema::Object(schemars::schema::SchemaObject {
subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
one_of: Some(<[_]>::into_vec(Box::new([
schemars::_private::metadata::add_description(
schemars::_private::new_internally_tagged_enum(
"visibility",
"internal",
true,
),
"An internal attribute group",
)
.flatten(
<InternalAttributeGroup as JsonSchema>::json_schema(generator),
),
schemars::_private::metadata::add_description(
schemars::_private::new_internally_tagged_enum(
"visibility",
"public",
true,
),
"A public attribute group",
)
.flatten(<PublicAttributeGroup as JsonSchema>::json_schema(generator)),
]))),
..Default::default()
})),
..Default::default()
}),
"Attribute group definition.",
)
}
}
};

impl AttributeGroup {
/// Converts a v2 attribute group into a v1 GroupSpec.
#[must_use]
Expand Down
Loading
Loading