Skip to content
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

ABI not generated when functions return a vector of objects or regular JSON #136

Open
corydickson opened this issue Mar 14, 2024 · 0 comments

Comments

@corydickson
Copy link

When running cargo near build --embed-abi as well as cargo near abi on the following contract sources:
https://github.com/archetype-org/attestation-registry/blob/main/src/lib.rs

I get the following error:

error[E0277]: the trait bound `Attestation: JsonSchema` is not satisfied
│    --> src/lib.rs:224:10
│     |
│ 224 |     ) -> Attestations {
│     |          ^^^^^^^^^^^^ the trait `JsonSchema` is not implemented for `Attestation`
│     |
│     = help: the following other types implement trait `JsonSchema`:
│               bool
│               char
│               isize
│               i8
│               i16
│               i32
│               i64
│               i128
│             and 165 others
│     = note: required for `std::vec::Vec<Attestation>` to implement `JsonSchema`
│ note: required by a bound in `SchemaGenerator::subschema_for`
│    --> /Users/c8r7/.cargo/registry/src/index.crates.io-6f17d22bba15001f/schemars-0.8.16/src/gen.rs:221:38
│     |
│ 221 |     pub fn subschema_for<T: ?Sized + JsonSchema>(&mut self) -> Schema {
│     |                                      ^^^^^^^^^^ required by this bound in `SchemaGenerator::subschema_for`
│ 
│ error[E0277]: the trait bound `Attestation: JsonSchema` is not satisfied
│    --> src/lib.rs:241:10
│     |
│ 241 |     ) -> Attestation {
│     |          ^^^^^^^^^^^ the trait `JsonSchema` is not implemented for `Attestation`
│     |
│     = help: the following other types implement trait `JsonSchema`:
│               bool
│               char
│               isize
│               i8
│               i16
│               i32
│               i64
│               i128
│             and 165 others
│ note: required by a bound in `SchemaGenerator::subschema_for`
│    --> /Users/c8r7/.cargo/registry/src/index.crates.io-6f17d22bba15001f/schemars-0.8.16/src/gen.rs:221:38
│     |
│ 221 |     pub fn subschema_for<T: ?Sized + JsonSchema>(&mut self) -> Schema {
│     |                                      ^^^^^^^^^^ required by this bound in `SchemaGenerator::subschema_for`
│ 
│ For more information about this error, try `rustc --explain E0277`.
│ error: could not compile `attestation-registry` (lib) due to 2 previous errors

Similar code also fails due to the same reason:
https://github.com/NEAR-DevHub/neardevhub-contract

error[E0277]: the trait bound `access_control::AccessControl: JsonSchema` is not satisfied
 │    --> src/access_control/mod.rs:22:46
 │     |
 │ 22  |     pub fn get_access_control_info(&self) -> &AccessControl {
 │     |                                              ^^^^^^^^^^^^^^ the trait `JsonSchema` is not implemented for `access_control::AccessControl`
 │     |
 │     = help: the following other types implement trait `JsonSchema`:
 │               &'a T
 │               &'a mut T
 │               ()
 │               (T0, T1)
 │               (T0, T1, T2)
 │               (T0, T1, T2, T3)
 │               (T0, T1, T2, T3, T4)
 │               (T0, T1, T2, T3, T4, T5)
 │             and 163 others
 │     = note: required for `&access_control::AccessControl` to implement `JsonSchema`
 │ note: required by a bound in `SchemaGenerator::subschema_for`
 │    --> /Users/ebraem/.cargo/registry/src/index.crates.io-6f17d22bba15001f/schemars-0.8.15/src/gen.rs:221:38
 │     |
 │ 221 |     pub fn subschema_for<T: ?Sized + JsonSchema>(&mut self) -> Schema {
 │     |                                      ^^^^^^^^^^ required by this bound in `SchemaGenerator::subschema_for`
 │
 │ error[E0277]: the trait bound `RulesList: JsonSchema` is not satisfied
 │    --> src/access_control/mod.rs:34:51
 │     |
 │ 34  |     pub fn set_restricted_rules(&mut self, rules: RulesList) {
 │     |                                                   ^^^^^^^^^ the trait `JsonSchema` is not implemented for `RulesList`
 │     |
 │     = help: the following other types implement trait `JsonSchema`:
 │               &'a T
 │               &'a mut T
 │               ()
 │               (T0, T1)
 │               (T0, T1, T2)
 │               (T0, T1, T2, T3)
 │               (T0, T1, T2, T3, T4)
 │               (T0, T1, T2, T3, T4, T5)
 │             and 163 others

I believe this is because the abigen does not support the same types of schema traits as borsh. Is this a limitation with the standard or will support be added in the future.

@corydickson corydickson changed the title ABI not generated when functions return a vector of objects or regular JSON. ABI not generated when functions return a vector of objects or regular JSON Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant