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

Handle maps to structs in schema #37

Merged
merged 7 commits into from
Mar 2, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
extend gathering to also analyze excessively nested properties
Signed-off-by: clux <sszynrae@gmail.com>
  • Loading branch information
clux committed Mar 1, 2022
commit 80b36f779303ec07d386f7ded3f8f1928d8fc1bd
37 changes: 25 additions & 12 deletions src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,35 @@ pub fn analyze(
if let Some(JSONSchemaPropsOrBool::Schema(s)) = schema.additional_properties.as_ref() {
let dict_type = s.type_.clone().unwrap_or_default();
// It's possible to specify the properties inside a nested additionalProperties.properties
// so cancel here only if there's no dict type AND no properties
if !dict_type.is_empty() && !s.properties.is_some() {
if let Some(extra_props) = &s.properties {
// in this case we need to run analysis on these nested types
debug!("Generating nested struct for {} (under {})", current, stack);
let new_result = analyze_object_properties(
&extra_props,
stack,
&mut array_recurse_level,
level,
&schema,
)?;
results.extend(new_result);
}
else if !dict_type.is_empty() {
warn!("not generating type {} - using {} map", current, dict_type);
return Ok(()); // no members here - it'll be inlined
}
}
debug!("Generating struct for {} (under {})", current, stack);
// initial analysis of properties (we do not recurse here, we need to find members first)
let new_result = analyze_object_properties(
&props,
stack,
&mut array_recurse_level,
level,
&schema,
)?;
results.extend(new_result);
else { // else, regular properties only
debug!("Generating struct for {} (under {})", current, stack);
// initial analysis of properties (we do not recurse here, we need to find members first)
let new_result = analyze_object_properties(
&props,
stack,
&mut array_recurse_level,
level,
&schema,
)?;
results.extend(new_result);
}
}

// Start recursion for properties
Expand Down