Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix maps in v2->v3 schema conversion #529

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading