Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
evforde committed Nov 5, 2024
1 parent f543323 commit 55926f3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions core/src/v3/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ impl From<v2::DefaultSchemaRaw> for openapiv3::ReferenceOr<openapiv3::Schema> {
&v2.properties,
&v2.required,
)
} else if !v2.any_of.is_empty() {
let any_of = (v2.any_of)
.into_iter()
.map(|v2| openapiv3::ReferenceOr::<openapiv3::Schema>::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(),
Expand All @@ -55,6 +75,8 @@ impl From<v2::DefaultSchemaRaw> for openapiv3::ReferenceOr<openapiv3::Schema> {
}
}

// 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(
Expand Down
1 change: 1 addition & 0 deletions macros/src/actix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions macros/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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();
}
}
}
}
Expand Down

0 comments on commit 55926f3

Please sign in to comment.