diff --git a/core/src/v3/schema.rs b/core/src/v3/schema.rs index c88a15cbf..283488847 100644 --- a/core/src/v3/schema.rs +++ b/core/src/v3/schema.rs @@ -42,6 +42,26 @@ impl From for openapiv3::ReferenceOr { &v2.properties, &v2.required, ) + } else if !v2.any_of.is_empty() { + let any_of = (v2.any_of) + .into_iter() + .map(|v2| openapiv3::ReferenceOr::::from(*v2)) + .collect(); + openapiv3::SchemaKind::AnyOf { + any_of, + } + } else if let Some(c) = v2.const_ { + match c { + serde_json::Value::String(s) => openapiv3::SchemaKind::Type( + openapiv3::Type::String(openapiv3::StringType { + enumeration: vec![Some(s)], + ..Default::default() + }), + ), + _ => openapiv3::SchemaKind::Type(openapiv3::Type::Object( + openapiv3::ObjectType::default(), + )), + } } else { openapiv3::SchemaKind::Type(openapiv3::Type::Object( openapiv3::ObjectType::default(), @@ -55,6 +75,8 @@ impl From for openapiv3::ReferenceOr { } } +// TODO I don't think we're properly translating the open api v2 to v3 spec for the schema + // helper function to convert a v2 DataType to v3, with explicit types making it more // rust-analyzer friendly as the DefaultSchemaRaw is autogenerated by a macro fn v2_data_type_to_v3( diff --git a/macros/src/actix.rs b/macros/src/actix.rs index 143bdcd4b..886de24ac 100644 --- a/macros/src/actix.rs +++ b/macros/src/actix.rs @@ -1851,6 +1851,7 @@ fn handle_enum( handle_field_struct(f, &[], serde, &mut inner_gen); } Fields::Unnamed(ref f) => { + // TODO need to actually do unnamed here // Fix this once handle_unnamed_field_struct does actually create arrays emit_warning!(f.span().unwrap(), "skipping tuple enum variant in schema."); continue; diff --git a/macros/src/core.rs b/macros/src/core.rs index b67587c16..d7ff4047b 100644 --- a/macros/src/core.rs +++ b/macros/src/core.rs @@ -63,6 +63,9 @@ pub fn emit_v2_schema_struct(input: TokenStream) -> TokenStream { self.properties.values_mut().for_each(|s| s.remove_refs()); self.items.as_mut().map(|s| s.remove_refs()); self.extra_props.as_mut().and_then(|s| s.right_mut()).map(|s| s.remove_refs()); + for s in &mut self.any_of { + s.remove_refs(); + } self.reference = None; } @@ -77,6 +80,9 @@ pub fn emit_v2_schema_struct(input: TokenStream) -> TokenStream { self.properties.values_mut().for_each(|s| s.retain_ref()); self.items.as_mut().map(|s| s.retain_ref()); self.extra_props.as_mut().and_then(|s| s.right_mut()).map(|s| s.retain_ref()); + for s in &mut self.any_of { + s.retain_ref(); + } } } }