Skip to main content

openapi_contract_macros/
lib.rs

1mod codegen;
2mod spec;
3mod types;
4
5use proc_macro::TokenStream;
6
7/// Generate Rust types from an OpenAPI spec file.
8///
9/// ```rust,ignore
10/// openapi_contract::generate_types!("openapi-spec.json");
11/// ```
12#[proc_macro]
13pub fn generate_types(input: TokenStream) -> TokenStream {
14    codegen::generate_types_impl(input.into())
15        .unwrap_or_else(|e| e.into_compile_error())
16        .into()
17}
18
19/// Build a type-safe, compile-time validated API request.
20///
21/// ```rust,ignore
22/// let profile = api!(GET "/api/auth/profile")
23///     .fetch(&client).await?;
24///
25/// let members = api!(GET "/api/teams/{id}/members", id = &team_id)
26///     .fetch(&client).await?;
27///
28/// let result = api!(POST "/api/teams/{id}/invite", id = &tid, body = &data)
29///     .fetch(&client).await?;
30/// ```
31#[proc_macro]
32pub fn api(input: TokenStream) -> TokenStream {
33    codegen::api_impl(input.into())
34        .unwrap_or_else(|e| e.into_compile_error())
35        .into()
36}