Add methods for generating request and response types.
This commit is contained in:
parent
27349e57ab
commit
a3c855835a
45
src/lib.rs
45
src/lib.rs
@ -36,13 +36,16 @@ struct Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Api {
|
impl Api {
|
||||||
fn output(self) -> Tokens {
|
fn output(&self) -> Tokens {
|
||||||
let description = self.metadata.description;
|
let description = &self.metadata.description;
|
||||||
let method = self.metadata.method;
|
let method = &self.metadata.method;
|
||||||
let name = self.metadata.name;
|
let name = &self.metadata.name;
|
||||||
let path = self.metadata.path;
|
let path = &self.metadata.path;
|
||||||
let rate_limited = self.metadata.rate_limited;
|
let rate_limited = &self.metadata.rate_limited;
|
||||||
let requires_authentication = self.metadata.requires_authentication;
|
let requires_authentication = &self.metadata.requires_authentication;
|
||||||
|
|
||||||
|
let request_types = self.generate_request_types();
|
||||||
|
let response_types = self.generate_response_types();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
@ -51,9 +54,7 @@ impl Api {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Endpoint;
|
pub struct Endpoint;
|
||||||
|
|
||||||
/// Data for a request to this API endpoint.
|
#request_types
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Request;
|
|
||||||
|
|
||||||
impl TryFrom<Request> for ::hyper::Request {
|
impl TryFrom<Request> for ::hyper::Request {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
@ -68,9 +69,7 @@ impl Api {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Data in the response from this API endpoint.
|
#response_types
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Response;
|
|
||||||
|
|
||||||
impl TryFrom<::hyper::Response> for Response {
|
impl TryFrom<::hyper::Response> for Response {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
@ -95,6 +94,26 @@ impl Api {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn generate_request_types(&self) -> Tokens {
|
||||||
|
let mut tokens = quote! {
|
||||||
|
/// Data for a request to this API endpoint.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Request;
|
||||||
|
};
|
||||||
|
|
||||||
|
tokens
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generate_response_types(&self) -> Tokens {
|
||||||
|
let mut tokens = quote! {
|
||||||
|
/// Data in the response from this API endpoint.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Response;
|
||||||
|
};
|
||||||
|
|
||||||
|
tokens
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Vec<Entry>> for Api {
|
impl From<Vec<Entry>> for Api {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user