Skip to content

Commit

Permalink
fix: maps in v2->v3 schema conversion (#529)
Browse files Browse the repository at this point in the history
Maps were previously appearing as fieldname: object with no schema definitions added for the value types in the map. This PR adds the map value type as an additional property on the relevant V3 schema for the parent struct field.
  • Loading branch information
formlogic-kirk authored Sep 7, 2024
1 parent 110823c commit d87cd7c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core/src/v3/schema.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::v2::models::Either;

use super::{invalid_referenceor, v2};
use std::ops::Deref;

Expand Down Expand Up @@ -40,6 +42,7 @@ impl From<v2::DefaultSchemaRaw> for openapiv3::ReferenceOr<openapiv3::Schema> {
&v2.enum_,
&v2.items,
&v2.properties,
&v2.extra_props,
&v2.required,
)
} else {
Expand All @@ -63,6 +66,7 @@ fn v2_data_type_to_v3(
enum_: &[serde_json::Value],
items: &Option<Box<v2::DefaultSchemaRaw>>,
properties: &std::collections::BTreeMap<String, Box<v2::DefaultSchemaRaw>>,
extra_properties: &Option<Either<bool, Box<v2::DefaultSchemaRaw>>>,
required: &std::collections::BTreeSet<String>,
) -> openapiv3::SchemaKind {
match data_type {
Expand Down Expand Up @@ -181,7 +185,12 @@ fn v2_data_type_to_v3(
})
},
required: required.iter().cloned().collect::<Vec<_>>(),
additional_properties: None,
additional_properties: extra_properties.as_ref().map(|e| match e {
Either::Right(box_schema) => openapiv3::AdditionalProperties::Schema(Box::new(
box_schema.deref().clone().into(),
)),
Either::Left(v) => openapiv3::AdditionalProperties::Any(*v),
}),
min_properties: None,
max_properties: None,
}))
Expand Down
1 change: 1 addition & 0 deletions tests/test_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4672,6 +4672,7 @@ where
ret
}

#[track_caller]
fn check_json(resp: reqwest::blocking::Response, expected: serde_json::Value) {
assert_eq!(resp.status().as_u16(), 200);
let json = resp.json::<serde_json::Value>().expect("json error");
Expand Down

0 comments on commit d87cd7c

Please sign in to comment.