Created
July 26, 2020 09:34
-
-
Save yihuang/b6e1782b4fe90501ee50755c572bf372 to your computer and use it in GitHub Desktop.
test open rpc
This file contains hidden or 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
| [package] | |
| name = "open-rpc-test" | |
| version = "0.1.0" | |
| authors = ["yihuang <yi.codeplayer@gmail.com>"] | |
| edition = "2018" | |
| [dependencies] | |
| schemars = "0.7" | |
| serde = "1.0" | |
| serde_json = "1.0" |
This file contains hidden or 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
| use schemars::{schema::SchemaObject, schema_for, JsonSchema}; | |
| use serde::{Deserialize, Serialize}; | |
| #[derive(Serialize, Deserialize, JsonSchema)] | |
| struct ListPetRequest(u64); | |
| #[derive(Serialize, Deserialize, JsonSchema)] | |
| struct ListPetResponse { | |
| uuid: u64, | |
| name: String, | |
| breed: String, | |
| } | |
| #[derive(Serialize, Deserialize)] | |
| struct Descriptor { | |
| name: String, | |
| description: String, | |
| schema: SchemaObject, | |
| } | |
| #[derive(Serialize, Deserialize)] | |
| struct Method { | |
| name: String, | |
| description: String, | |
| params: Descriptor, | |
| result: Descriptor, | |
| } | |
| #[derive(Serialize, Deserialize)] | |
| struct Info { | |
| title: String, | |
| version: String, | |
| } | |
| #[derive(Serialize, Deserialize)] | |
| struct Project { | |
| openrpc: String, | |
| info: Info, | |
| methods: Vec<Method>, | |
| } | |
| fn main() { | |
| let proj = Project { | |
| openrpc: "1.2.1".to_owned(), | |
| info: Info { | |
| title: "Pet store".to_owned(), | |
| version: "1.0".to_owned(), | |
| }, | |
| methods: vec![Method { | |
| name: "listPets".to_owned(), | |
| description: "List all pets".to_owned(), | |
| params: Descriptor { | |
| name: "limit".to_owned(), | |
| description: "".to_owned(), | |
| schema: schema_for!(u64).schema, | |
| }, | |
| result: Descriptor { | |
| name: "response".to_owned(), | |
| description: "".to_owned(), | |
| schema: schema_for!(ListPetResponse).schema, | |
| }, | |
| }], | |
| }; | |
| println!("{}", serde_json::to_string(&proj).unwrap()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment