Skip to content

Schema types metadata #19524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 20, 2025
Merged

Conversation

Leinnan
Copy link
Contributor

@Leinnan Leinnan commented Jun 7, 2025

Objective

  • Currently there is predefinied list of supported DataTypes that can be detected on Bevy JSON Schema generation and mapped as reflect_types array elements.
  • Make it possible to register custom reflectTypes mappings for Bevy JSON Schema.

Solution

  • Create a SchemaTypesMetadata Resource that will hold mappings for TypeId of TypeData. List is bigger from beggining and it is possible to expand it without forking package.

Testing

  • I use it for quite a while in my game, I have a fork of bevy_remote with more changes that later I want to merge to main as well.

@Leinnan
Copy link
Contributor Author

Leinnan commented Jun 7, 2025

@mweatherley @splo Could be interested in this :) It is a first step towards bigger refactor- namely proper JSON Schema support. But that is a much bigger change and I want to clean up my code from here a lot more: https://github.com/Leinnan/bevy_remote_ext

Comment on lines 18 to 19
/// Holds mapping of reflect data types to strings,
/// later on used in Bevy Json Schema.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of "strings"? Are these the schemas themselves? Type paths? Might be worth clarifying.

Same goes for other mentions of "string" in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have idea how to make it more clear ATM. If you have, please suggest 😅

let t = reg.type_info();
let binding = t.type_path_table();

let short_path = binding.short_path();
let type_path = binding.path();
let mut typed_schema = JsonSchemaBevyType {
reflect_types: get_registered_reflect_types(reg),
reflect_types: metadata.get_registered_reflect_types(reg),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, didn't realize this field was just called reflect_types when it really just holds simplified names of type data. I wonder if it should be renamed to reflect_type_data or type_data or something? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to change the structure of schema a bit, so that if possible I would leave for next PR 😅

Leinnan and others added 2 commits June 7, 2025 19:37
Co-authored-by: Gino Valente <[email protected]>
Co-authored-by: Gino Valente <[email protected]>
@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Dev-Tools Tools used to debug Bevy applications. S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 7, 2025
@Leinnan Leinnan requested a review from MrGVSV June 8, 2025 08:48
@Leinnan
Copy link
Contributor Author

Leinnan commented Jun 8, 2025

@MrGVSV Updated with almost all feedback applied.

Copy link
Member

@MrGVSV MrGVSV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too versed in bevy_remote, but the changes make sense to me :)

Comment on lines +1268 to 1270
Some((id.to_string(), schema))
})
.collect::<HashMap<String, JsonSchemaBevyType>>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Unfortunate we have to allocate (to_string) here since we made export_types return Cow. Would converting this to HashMap<Cow<'static, str>, JsonSchemaBevyType> be too difficult/involved here? If so, we can address this another time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to put it into the next PR and have this one merged 😅

(reg.type_info().type_path().into(), (reg, metadata).into())
}

impl From<(&TypeRegistration, &SchemaTypesMetadata)> for JsonSchemaBevyType {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Might be worth keeping a From impl for just &TypeRegistration which just uses the SchemaTypesMetadata::default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to put it into the next PR and have this one merged 😅

@Leinnan
Copy link
Contributor Author

Leinnan commented Jun 16, 2025

@mweatherley @splo I could use second approve if you find that useful

@splo
Copy link
Contributor

splo commented Jun 17, 2025

Looks good to me. 👍

I'm especially excited to see future PRs for proper JSON Schema support.

@Leinnan
Copy link
Contributor Author

Leinnan commented Jun 20, 2025

@alice-i-cecile can it be merged?

@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jun 20, 2025
@alice-i-cecile
Copy link
Member

I don't have experience with this sort of thing; let me wrangle up some reviews :)

Copy link

@jbuehler23 jbuehler23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not too familiar with the details/implementation here, but I think we should have some proper examples of serialising/deserialising with these schema changes. I’m happy that @splo is happy with these changes too :)

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 20, 2025
@alice-i-cecile
Copy link
Member

Ah, I missed splo's approval :) I'm content to merge this, but I would really love more tests and examples for BRP in the future.

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 20, 2025
Merged via the queue into bevyengine:main with commit 84f21f7 Jun 20, 2025
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Dev-Tools Tools used to debug Bevy applications. C-Feature A new feature, making something new possible S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants