Allow mutable Visitors
This commit is contained in:
parent
475a751b70
commit
656a70e02c
2 changed files with 15 additions and 15 deletions
|
@ -236,7 +236,7 @@ impl SchemaGenerator {
|
||||||
schema,
|
schema,
|
||||||
};
|
};
|
||||||
|
|
||||||
for visitor in &self.settings.visitors.0 {
|
for visitor in &mut self.settings.visitors.0 {
|
||||||
visitor.visit_root_schema(&mut root)
|
visitor.visit_root_schema(&mut root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ impl SchemaGenerator {
|
||||||
schema,
|
schema,
|
||||||
};
|
};
|
||||||
|
|
||||||
for visitor in &self.settings.visitors.0 {
|
for visitor in &mut self.settings.visitors.0 {
|
||||||
visitor.visit_root_schema(&mut root)
|
visitor.visit_root_schema(&mut root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,7 +330,7 @@ pub struct ReplaceBoolSchemas {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Visitor for ReplaceBoolSchemas {
|
impl Visitor for ReplaceBoolSchemas {
|
||||||
fn visit_schema(&self, schema: &mut Schema) {
|
fn visit_schema(&mut self, schema: &mut Schema) {
|
||||||
if let Schema::Bool(b) = *schema {
|
if let Schema::Bool(b) = *schema {
|
||||||
*schema = Schema::Bool(b).into_object().into()
|
*schema = Schema::Bool(b).into_object().into()
|
||||||
}
|
}
|
||||||
|
@ -338,7 +338,7 @@ impl Visitor for ReplaceBoolSchemas {
|
||||||
visit_schema(self, schema)
|
visit_schema(self, schema)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_schema_object(&self, schema: &mut SchemaObject) {
|
fn visit_schema_object(&mut self, schema: &mut SchemaObject) {
|
||||||
if self.skip_additional_properties {
|
if self.skip_additional_properties {
|
||||||
let mut additional_properties = None;
|
let mut additional_properties = None;
|
||||||
if let Some(obj) = &mut schema.object {
|
if let Some(obj) = &mut schema.object {
|
||||||
|
@ -365,7 +365,7 @@ impl Visitor for ReplaceBoolSchemas {
|
||||||
pub struct RemoveRefSiblings;
|
pub struct RemoveRefSiblings;
|
||||||
|
|
||||||
impl Visitor for RemoveRefSiblings {
|
impl Visitor for RemoveRefSiblings {
|
||||||
fn visit_schema_object(&self, schema: &mut SchemaObject) {
|
fn visit_schema_object(&mut self, schema: &mut SchemaObject) {
|
||||||
visit_schema_object(self, schema);
|
visit_schema_object(self, schema);
|
||||||
|
|
||||||
if let Some(reference) = schema.reference.take() {
|
if let Some(reference) = schema.reference.take() {
|
||||||
|
|
|
@ -3,33 +3,33 @@ use dyn_clone::DynClone;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
pub trait Visitor: Debug + DynClone {
|
pub trait Visitor: Debug + DynClone {
|
||||||
fn visit_root_schema(&self, root: &mut RootSchema) {
|
fn visit_root_schema(&mut self, root: &mut RootSchema) {
|
||||||
visit_root_schema(self, root)
|
visit_root_schema(self, root)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_schema(&self, schema: &mut Schema) {
|
fn visit_schema(&mut self, schema: &mut Schema) {
|
||||||
visit_schema(self, schema)
|
visit_schema(self, schema)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_schema_object(&self, schema: &mut SchemaObject) {
|
fn visit_schema_object(&mut self, schema: &mut SchemaObject) {
|
||||||
visit_schema_object(self, schema)
|
visit_schema_object(self, schema)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dyn_clone::clone_trait_object!(Visitor);
|
dyn_clone::clone_trait_object!(Visitor);
|
||||||
|
|
||||||
pub fn visit_root_schema<V: Visitor + ?Sized>(v: &V, root: &mut RootSchema) {
|
pub fn visit_root_schema<V: Visitor + ?Sized>(v: &mut V, root: &mut RootSchema) {
|
||||||
v.visit_schema_object(&mut root.schema);
|
v.visit_schema_object(&mut root.schema);
|
||||||
visit_map_values(v, &mut root.definitions);
|
visit_map_values(v, &mut root.definitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visit_schema<V: Visitor + ?Sized>(v: &V, schema: &mut Schema) {
|
pub fn visit_schema<V: Visitor + ?Sized>(v: &mut V, schema: &mut Schema) {
|
||||||
if let Schema::Object(schema) = schema {
|
if let Schema::Object(schema) = schema {
|
||||||
v.visit_schema_object(schema)
|
v.visit_schema_object(schema)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visit_schema_object<V: Visitor + ?Sized>(v: &V, schema: &mut SchemaObject) {
|
pub fn visit_schema_object<V: Visitor + ?Sized>(v: &mut V, schema: &mut SchemaObject) {
|
||||||
if let Some(sub) = &mut schema.subschemas {
|
if let Some(sub) = &mut schema.subschemas {
|
||||||
visit_vec(v, &mut sub.all_of);
|
visit_vec(v, &mut sub.all_of);
|
||||||
visit_vec(v, &mut sub.any_of);
|
visit_vec(v, &mut sub.any_of);
|
||||||
|
@ -54,13 +54,13 @@ pub fn visit_schema_object<V: Visitor + ?Sized>(v: &V, schema: &mut SchemaObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_box<V: Visitor + ?Sized>(v: &V, target: &mut Option<Box<Schema>>) {
|
fn visit_box<V: Visitor + ?Sized>(v: &mut V, target: &mut Option<Box<Schema>>) {
|
||||||
if let Some(s) = target {
|
if let Some(s) = target {
|
||||||
v.visit_schema(s)
|
v.visit_schema(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_vec<V: Visitor + ?Sized>(v: &V, target: &mut Option<Vec<Schema>>) {
|
fn visit_vec<V: Visitor + ?Sized>(v: &mut V, target: &mut Option<Vec<Schema>>) {
|
||||||
if let Some(vec) = target {
|
if let Some(vec) = target {
|
||||||
for s in vec {
|
for s in vec {
|
||||||
v.visit_schema(s)
|
v.visit_schema(s)
|
||||||
|
@ -68,13 +68,13 @@ fn visit_vec<V: Visitor + ?Sized>(v: &V, target: &mut Option<Vec<Schema>>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_map_values<V: Visitor + ?Sized>(v: &V, target: &mut crate::Map<String, Schema>) {
|
fn visit_map_values<V: Visitor + ?Sized>(v: &mut V, target: &mut crate::Map<String, Schema>) {
|
||||||
for s in target.values_mut() {
|
for s in target.values_mut() {
|
||||||
v.visit_schema(s)
|
v.visit_schema(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_single_or_vec<V: Visitor + ?Sized>(v: &V, target: &mut Option<SingleOrVec<Schema>>) {
|
fn visit_single_or_vec<V: Visitor + ?Sized>(v: &mut V, target: &mut Option<SingleOrVec<Schema>>) {
|
||||||
match target {
|
match target {
|
||||||
None => {}
|
None => {}
|
||||||
Some(SingleOrVec::Single(s)) => v.visit_schema(s),
|
Some(SingleOrVec::Single(s)) => v.visit_schema(s),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue