kittycad_modeling_cmds_macros_impl/
ok_modeling_cmd_response_enum.rs1use proc_macro2::TokenStream;
2use quote::quote_spanned;
3use syn::{spanned::Spanned, ItemMod};
4
5pub fn generate(input: ItemMod) -> TokenStream {
6 let span = input.span();
7
8 let items = &input.content.as_ref().unwrap().1;
11 let variants = items
12 .iter()
13 .filter_map(|item| {
14 match item {
16 syn::Item::Struct(item) if matches!(item.vis, syn::Visibility::Public(_)) => Some(&item.ident),
17 _ => None,
18 }
19 })
20 .collect::<Vec<_>>();
21
22 quote_spanned! {span=>
24 #input
26 #[derive(Debug, Clone, Serialize, Deserialize)]
29 #[cfg_attr(feature = "derive-jsonschema-on-enums", derive(schemars::JsonSchema))]
30 #[serde(rename_all = "snake_case", tag = "type", content = "data")]
31 #[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
32 pub enum OkModelingCmdResponse {
33 Empty,
36 #(#[doc = concat!("The response to the '", stringify!(#variants), "' endpoint.")] #variants(output::#variants),)*
37 }
38
39 #(
43 impl From<output::#variants> for OkModelingCmdResponse {
44 fn from(x: output::#variants) -> Self {
45 Self::#variants(x)
46 }
47 }
48 )*
49
50 impl From<()> for OkModelingCmdResponse {
53 fn from(_: ()) -> Self {
54 Self::Empty
55 }
56 }
57 }
58}