Remove id field

This commit is contained in:
Piotr Siuszko 2025-07-05 07:53:22 +02:00
parent 714d56e1ed
commit 492ad8be31
3 changed files with 13 additions and 33 deletions

View File

@ -1681,7 +1681,9 @@ mod tests {
use bevy_math::Vec3; use bevy_math::Vec3;
use bevy_reflect::Reflect; use bevy_reflect::Reflect;
use crate::schemas::{ReflectJsonSchemaForceAsArray, SchemaTypesMetadata}; use crate::schemas::{
reflect_info::TypeReferenceId, ReflectJsonSchemaForceAsArray, SchemaTypesMetadata,
};
use super::*; use super::*;
@ -1760,7 +1762,7 @@ mod tests {
assert_eq!(response.definitions.len(), 1); assert_eq!(response.definitions.len(), 1);
{ {
let first = response.definitions.iter().next().expect("Should have one"); let first = response.definitions.iter().next().expect("Should have one");
assert_eq!(first.1.id, "urn:glam-Vec3"); assert_eq!(first.0, &TypeReferenceId::from("glam-Vec3"));
} }
let response = export_registry_types_ext( let response = export_registry_types_ext(
BrpJsonSchemaQueryFilter { BrpJsonSchemaQueryFilter {

View File

@ -126,11 +126,6 @@ impl From<SchemaMarker> for Cow<'static, str> {
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Reflect)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Reflect)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct JsonSchemaBevyType { pub struct JsonSchemaBevyType {
/// JSON Schema specific field.
/// This keyword declares an identifier for the schema resource.
#[serde(skip_serializing_if = "str::is_empty", default)]
#[serde(rename = "$id")]
pub id: Cow<'static, str>,
/// Identifies the JSON Schema version used in the schema. /// Identifies the JSON Schema version used in the schema.
#[serde(rename = "$schema")] #[serde(rename = "$schema")]
#[serde(skip_serializing_if = "Option::is_none", default)] #[serde(skip_serializing_if = "Option::is_none", default)]
@ -722,7 +717,6 @@ mod tests {
let schema = export_type::<Foo>(); let schema = export_type::<Foo>();
let schema_as_value = serde_json::to_value(&schema).expect("Failed to serialize schema"); let schema_as_value = serde_json::to_value(&schema).expect("Failed to serialize schema");
let mut value = json!({ let mut value = json!({
"$id": "urn:bevy_remote-schemas-json_schema-tests-Foo",
"shortPath": "Foo", "shortPath": "Foo",
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"typePath": "bevy_remote::schemas::json_schema::tests::Foo", "typePath": "bevy_remote::schemas::json_schema::tests::Foo",

View File

@ -223,19 +223,13 @@ impl TypeInformation {
} }
} }
/// Builds a `TypeReferencePath` from the type identifier.
pub fn try_get_path_id(&self) -> Option<TypeReferencePath> {
self.try_get_type_reference_id()
.map(|id| TypeReferencePath::new_ref(ReferenceLocation::Urn, id))
}
/// Builds a `TypeReferenceId` from the type path. /// Builds a `TypeReferenceId` from the type path.
pub fn try_get_type_reference_id(&self) -> Option<TypeReferenceId> { pub fn try_get_type_reference_id(&self) -> Option<TypeReferenceId> {
if let Some(schema) = self.try_get_custom_schema() { if let Some(schema) = self.try_get_custom_schema() {
if schema.0.id.is_empty() { if schema.0.type_path.is_empty() {
None None
} else { } else {
Some(schema.0.id.trim().into()) Some(TypeReferenceId::from(&*schema.0.type_path))
} }
} else if self.is_primitive_type() { } else if self.is_primitive_type() {
None None
@ -1119,7 +1113,12 @@ impl SchemaTypeInfo {
pub fn to_ref_schema(&self) -> JsonSchemaBevyType { pub fn to_ref_schema(&self) -> JsonSchemaBevyType {
let range = self.get_range(); let range = self.get_range();
let description = self.get_docs(); let description = self.get_docs();
let (ref_type, schema_type) = (self.ty_info.try_get_path_id(), self.into()); let (ref_type, schema_type) = (
self.ty_info
.try_get_type_reference_id()
.map(TypeReferencePath::definition),
self.into(),
);
let mut schema = JsonSchemaBevyType { let mut schema = JsonSchemaBevyType {
description, description,
@ -1212,13 +1211,8 @@ impl SchemaTypeInfo {
} else { } else {
(Cow::default(), Cow::default(), None, None) (Cow::default(), Cow::default(), None, None)
}; };
let schema_id = self
.ty_info
.try_get_path_id()
.map(|id| Cow::Owned(id.to_string()))
.unwrap_or_default();
let mut schema = JsonSchemaBevyType { let mut schema = JsonSchemaBevyType {
id: schema_id,
description: self.ty_info.get_docs(), description: self.ty_info.get_docs(),
type_path, type_path,
short_path, short_path,
@ -1418,16 +1412,6 @@ impl SchemaTypeInfo {
(Cow::default(), Cow::default(), None, None) (Cow::default(), Cow::default(), None, None)
}; };
schema = JsonSchemaBevyType { schema = JsonSchemaBevyType {
id: self
.ty_info
.try_get_type_reference_id()
.map(|id| {
Cow::Owned(
TypeReferencePath::new_ref(ReferenceLocation::Urn, id)
.to_string(),
)
})
.unwrap_or_default(),
short_path, short_path,
type_path, type_path,
module_path, module_path,