json-everything icon indicating copy to clipboard operation
json-everything copied to clipboard

Json Schema Generation in Native AoT

Open ThomasNieto opened this issue 7 months ago • 3 comments

Documentation

  • [x] I have consulted the documentation, and my question isn't answered there.

Nuget Package

JsonSchema.Net.Generation

Package Version

5.0.3

How can I help? Please provide as much context as possible.

I've been using .NET GetJsonSchemaAsNode() method in AOT context however it doesn't have attributes to specify other validation attributes. I came across this library and wanted to use it since it seemed to have the extra validation and JSON schema metadata.

In the docs it mentions that JSON schema generation does not work in the AOT context. However, I ran across some older PRs in the repo which mention AOT support so was wondering if JSON schema is also supported in that context.

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

ThomasNieto avatar Jun 12 '25 02:06 ThomasNieto

Most of the libraries in this project are AOT compatible, but the schema generation library is not. It uses a lot of reflection to do its job.

I currently have no plans to update it to include AOT support since it would be a pretty much a complete rewrite.

gregsdennis avatar Jun 12 '25 02:06 gregsdennis

Thanks for the info. I'm still quite new to AOT and Json Schemas as a whole. Is it possible to generate the JSON schema in a build step and then embed the JSON schema string inside the AOT application to be used by the Evaluate() method?

ThomasNieto avatar Jun 12 '25 04:06 ThomasNieto

Yeah, I'm not fully up on AOT either. I was fortunate to have some very smart people at .Net help.

Absolutely you can create the schema in an initial build step. You'd then just load the schema at runtime using the static .FromText() method.

gregsdennis avatar Jun 12 '25 09:06 gregsdennis