near / cargo-near

Cargo extension for building Rust smart contracts on NEAR
Apache License 2.0
33 stars 16 forks source link

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

Open corydickson opened 5 months ago

corydickson commented 5 months ago

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.