-
Notifications
You must be signed in to change notification settings - Fork 111
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
New ModuleCallJsonSchema
macro to generate JSON Schemas via schemars
#517
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
neysofu
force-pushed
the
filippo/json-schemas
branch
from
July 18, 2023 13:42
6ce3baa
to
a330bd3
Compare
neysofu
changed the title
[WIP] New
New Jul 18, 2023
ModuleCallJsonSchema
macro to generate JSON Schemas via schemars
ModuleCallJsonSchema
macro to generate JSON Schemas via schemars
bkolad
reviewed
Jul 18, 2023
module-system/sov-modules-macros/src/module_call_json_schema.rs
Outdated
Show resolved
Hide resolved
bkolad
reviewed
Jul 18, 2023
bkolad
approved these changes
Jul 18, 2023
Codecov Report
|
citizen-stig
pushed a commit
that referenced
this pull request
Jul 20, 2023
…rs` (#517) * Introduce `ModuleCallJsonSchema` trait * Refactor `get_generics_type_param` * Add `ModuleInfo` test * Allow `#[derive(ModuleCallJsonSchema)]` * Impl `ModuleCallJsonSchema` for `Bank` * New crate `sov-module-schemas` * `#![deny(missing_docs)]` for `sov_modules_macros` * Improve macro hygiene * Clearer docs on module type generics * ci: run coverage on bigger machine
preston-evans98
pushed a commit
that referenced
this pull request
Sep 14, 2023
…rs` (#517) * Introduce `ModuleCallJsonSchema` trait * Refactor `get_generics_type_param` * Add `ModuleInfo` test * Allow `#[derive(ModuleCallJsonSchema)]` * Impl `ModuleCallJsonSchema` for `Bank` * New crate `sov-module-schemas` * `#![deny(missing_docs)]` for `sov_modules_macros` * Improve macro hygiene * Clearer docs on module type generics * ci: run coverage on bigger machine
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR defines a new trait
ModuleCallJsonSchema
, which is intended to be used by all modules that wish to expose a JSON Schema for their call messages. This trait can be either implemented manually or via the newderive
macro.As a proof of concept, the trait is derived for
sov_bank::Bank
. If this PR is approved, I'll instrument all other modules with the derive macros and macro attributes necessary for JSON Schema generation.How
#[derive(ModuleCallJsonSchema)]
worksThe derive for
ModuleCallJsonSchema)
is conceptually very simple, as it offloads the complexity of schema generation to theschemars
crate.schemars
itself exposes a derivable trait –JsonSchema
– which must be derived byCallMessage
and all its children types. Occasionally, we also need to pollute our types withschemars
–sepcific macro attributes, specifically to help it generate the right type bounds when dealing withsov_modules_api::Context
.The quality of the generated schema(s) seems, at a first glances, very good.
schemars
supports mostserde
attribute macros and has crate features to support well-known crates, so most bases are covered. It's possible we might need to patch the schemas in the future. We'll have to decide how to do that when the need arises. Custom macro attributes or hand-written implementations ofschemars::JsonSchema
could be viable options.Linked Issues
I don't think there are any? The team discussed this as part of the July roadmap, though.
Testing
There's a new "dummy" crate,
sov-module-schemas
, which generates JSON Schemas for all supported modules and stores them in a directory. These are tracked by git so it will be very easy to see if a code change results in a schema change. This way, breakages and changes to call interfaces can be tracked easily.Also, I refactored the
get_generics_type_param
utility function to generate a better error message when derivingModuleInfo
. This is unrelated to the work on JSON Schemas, but it's small and I figured it made sense to include it in the same PR.Docs
I added
#![deny(missing_docs)]
tosov_modules_macros
and I patched some of the doc tests to be runnable instead ofignore
'd by Cargo.