use dropshot::{
endpoint, ApiDescription, HttpError, HttpResponseOk, RequestContext,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, JsonSchema)]
#[schemars(example = "foo_example")]
struct Foo {
id: u32,
bar: Bar,
}
#[derive(Deserialize, Serialize, JsonSchema)]
#[schemars(example = "bar_example")]
struct Bar {
id: u32,
}
fn foo_example() -> Foo {
Foo { id: 1, bar: bar_example() }
}
fn bar_example() -> Bar {
Bar { id: 2 }
}
fn main() -> Result<(), String> {
let mut api = ApiDescription::new();
api.register(get_foo).unwrap();
api.openapi("Examples", semver::Version::new(0, 0, 0))
.write(&mut std::io::stdout())
.map_err(|e| e.to_string())?;
Ok(())
}
#[endpoint {
method = GET,
path = "/foo",
tags = [ "foo" ],
}]
async fn get_foo(
_rqctx: RequestContext<()>,
) -> Result<HttpResponseOk<Foo>, HttpError> {
let ret = foo_example();
Ok(HttpResponseOk(ret))
}