-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fairly significant refactor. aimed at supporting deepl
- Loading branch information
1 parent
2c762c2
commit e18380f
Showing
33 changed files
with
3,355 additions
and
890 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
run: | ||
cargo run | ||
|
||
test *ARGS: | ||
cargo test -- $(ARGS) | ||
|
||
build: | ||
cargo build | ||
|
||
install: | ||
cargo install --path . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,137 @@ | ||
use std::collections::HashMap; | ||
use std::sync::atomic::AtomicBool; | ||
use openapiv3::{OpenAPI, Operation, RequestBody, Response, Schema, SchemaKind, Type}; | ||
// pub trait ChildSchemas { | ||
// fn add_child_schemas<'a>(&'a self, acc: &mut HashMap<String, &'a Schema>); | ||
// } | ||
|
||
pub trait ChildSchemas { | ||
fn add_child_schemas<'a>(&'a self, acc: &mut HashMap<String, &'a Schema>); | ||
} | ||
// impl ChildSchemas for Schema { | ||
// fn add_child_schemas<'a>(&'a self, acc: &mut HashMap<String, &'a Schema>) { | ||
// match &self.kind { | ||
// SchemaKind::Type(Type::Array(a)) => { | ||
// let Some(items) = &a.items else { | ||
// return; | ||
// }; | ||
// let Some(item) = items.as_item() else { | ||
// return; | ||
// }; | ||
// if let Some(title) = &item.title { | ||
// let title = sanitize(title).to_string(); | ||
// acc.entry(title).or_insert(item); | ||
// } | ||
// item.add_child_schemas(acc); | ||
// } | ||
// SchemaKind::Type(Type::Object(o)) => { | ||
// if let Some(title) = &self.title { | ||
// let title = sanitize(title).to_string(); | ||
// acc.entry(title).or_insert(self); | ||
// } | ||
// for (_name, prop) in &o.properties { | ||
// let Some(prop) = prop.as_item() else { | ||
// continue; | ||
// }; | ||
// if let Some(title) = &prop.title { | ||
// let title = sanitize(title).to_string(); | ||
// acc.entry(title).or_insert(prop); | ||
// } | ||
// prop.add_child_schemas(acc); | ||
// } | ||
// } | ||
// SchemaKind::Type(_) => {} | ||
// SchemaKind::OneOf { one_of: schemas } | ||
// | SchemaKind::AllOf { all_of: schemas } | ||
// | SchemaKind::AnyOf { any_of: schemas } => { | ||
// for schema in schemas { | ||
// let Some(schema) = schema.as_item() else { | ||
// continue; | ||
// }; | ||
// if let Some(title) = &schema.title { | ||
// let title = sanitize(title).to_string(); | ||
// acc.entry(title).or_insert(schema); | ||
// } | ||
// schema.add_child_schemas(acc); | ||
// } | ||
// } | ||
// SchemaKind::Not { .. } => {} | ||
// SchemaKind::Any(_) => {} | ||
// } | ||
// } | ||
// } | ||
|
||
impl ChildSchemas for Schema { | ||
fn add_child_schemas<'a>(&'a self, acc: &mut HashMap<String, &'a Schema>) { | ||
match &self.kind { | ||
SchemaKind::Type(Type::Array(a)) => { | ||
let Some(items) = &a.items else { return; }; | ||
let Some(item) = items.as_item() else { return; }; | ||
if let Some(title) = &item.title { | ||
acc.entry(title.clone()).or_insert(item); | ||
} | ||
item.add_child_schemas(acc); | ||
} | ||
SchemaKind::Type(Type::Object(o)) => { | ||
if let Some(title) = &self.title { | ||
acc.entry(title.clone()).or_insert(self); | ||
} | ||
for (_name, prop) in &o.properties { | ||
let Some(prop) = prop.as_item() else { continue; }; | ||
if let Some(title) = &prop.title { | ||
acc.entry(title.clone()).or_insert(prop); | ||
} | ||
prop.add_child_schemas(acc); | ||
} | ||
} | ||
SchemaKind::Type(_) => {} | ||
| SchemaKind::OneOf { one_of: schemas } | ||
| SchemaKind::AllOf { all_of: schemas } | ||
| SchemaKind::AnyOf { any_of: schemas} => { | ||
for schema in schemas { | ||
let Some(schema) = schema.as_item() else { continue; }; | ||
if let Some(title) = &schema.title { | ||
acc.entry(title.clone()).or_insert(schema); | ||
} | ||
schema.add_child_schemas(acc); | ||
} | ||
} | ||
SchemaKind::Not { .. } => {} | ||
SchemaKind::Any(_) => {} | ||
} | ||
} | ||
} | ||
// impl ChildSchemas for Operation { | ||
// fn add_child_schemas<'a>(&'a self, acc: &mut HashMap<String, &'a Schema>) { | ||
// 'body: { | ||
// let Some(body) = &self.request_body else { | ||
// break 'body; | ||
// }; | ||
// let Some(body) = body.as_item() else { | ||
// break 'body; | ||
// }; | ||
// body.add_child_schemas(acc); | ||
// } | ||
// for par in &self.parameters { | ||
// let Some(par) = par.as_item() else { | ||
// continue; | ||
// }; | ||
// let Some(schema) = par.data.schema() else { | ||
// continue; | ||
// }; | ||
// let Some(schema) = schema.as_item() else { | ||
// continue; | ||
// }; | ||
// schema.add_child_schemas(acc); | ||
// } | ||
// for (_code, response) in &self.responses.responses { | ||
// let Some(response) = response.as_item() else { | ||
// continue; | ||
// }; | ||
// response.add_child_schemas(acc); | ||
// } | ||
// } | ||
// } | ||
|
||
impl ChildSchemas for Operation { | ||
fn add_child_schemas<'a>(&'a self, acc: &mut HashMap<String, &'a Schema>) { | ||
'body: { | ||
let Some(body) = &self.request_body else { break 'body; }; | ||
let Some(body) = body.as_item() else { break 'body; }; | ||
body.add_child_schemas(acc); | ||
} | ||
for par in &self.parameters { | ||
let Some(par) = par.as_item() else { continue; }; | ||
let Some(schema) = par.data.schema() else { continue; }; | ||
let Some(schema) = schema.as_item() else { continue; }; | ||
schema.add_child_schemas(acc); | ||
} | ||
for (_code, response) in &self.responses.responses { | ||
let Some(response) = response.as_item() else { continue; }; | ||
response.add_child_schemas(acc); | ||
} | ||
} | ||
} | ||
// impl ChildSchemas for RequestBody { | ||
// fn add_child_schemas<'a>(&'a self, acc: &mut HashMap<String, &'a Schema>) { | ||
// for (_key, content) in &self.content { | ||
// let Some(schema) = &content.schema else { | ||
// continue; | ||
// }; | ||
// let Some(schema) = schema.as_item() else { | ||
// continue; | ||
// }; | ||
// if let Some(title) = &schema.title { | ||
// acc.entry(title.clone()).or_insert(schema); | ||
// } | ||
// schema.add_child_schemas(acc); | ||
// } | ||
// } | ||
// } | ||
|
||
impl ChildSchemas for RequestBody { | ||
fn add_child_schemas<'a>(&'a self, acc: &mut HashMap<String, &'a Schema>) { | ||
for (_key, content) in &self.content { | ||
let Some(schema) = &content.schema else { continue; }; | ||
let Some(schema) = schema.as_item() else { continue; }; | ||
if let Some(title) = &schema.title { | ||
acc.entry(title.clone()).or_insert(schema); | ||
} | ||
schema.add_child_schemas(acc); | ||
} | ||
} | ||
} | ||
// impl ChildSchemas for Response { | ||
// fn add_child_schemas<'a>(&'a self, acc: &mut HashMap<String, &'a Schema>) { | ||
// for (k, content) in &self.content { | ||
// let Some(schema) = &content.schema else { | ||
// continue; | ||
// }; | ||
// let Some(schema) = schema.as_item() else { | ||
// continue; | ||
// }; | ||
// if let Some(title) = &schema.title { | ||
// acc.entry(title.clone()).or_insert(schema); | ||
// } | ||
// schema.add_child_schemas(acc); | ||
// } | ||
// } | ||
// } | ||
|
||
impl ChildSchemas for Response { | ||
fn add_child_schemas<'a>(&'a self, acc: &mut HashMap<String, &'a Schema>) { | ||
for (k, content) in &self.content { | ||
let Some(schema) = &content.schema else { continue; }; | ||
let Some(schema) = schema.as_item() else { continue; }; | ||
if let Some(title) = &schema.title { | ||
acc.entry(title.clone()).or_insert(schema); | ||
} | ||
schema.add_child_schemas(acc); | ||
} | ||
} | ||
} | ||
|
||
impl ChildSchemas for OpenAPI { | ||
fn add_child_schemas<'a>(&'a self, acc: &mut HashMap<String, &'a Schema>) { | ||
for (_path, _method, op, _item) in self.operations() { | ||
op.add_child_schemas(acc); | ||
} | ||
for (name, schema) in &self.schemas { | ||
let Some(schema) = schema.as_item() else { continue; }; | ||
acc.entry(name.clone()).or_insert(schema); | ||
schema.add_child_schemas(acc); | ||
} | ||
} | ||
} | ||
// impl ChildSchemas for OpenAPI { | ||
// fn add_child_schemas<'a>(&'a self, acc: &mut HashMap<String, &'a Schema>) { | ||
// for (_path, _method, op, _item) in self.operations() { | ||
// op.add_child_schemas(acc); | ||
// } | ||
// for (name, schema) in &self.schemas { | ||
// let Some(schema) = schema.as_item() else { | ||
// continue; | ||
// }; | ||
// acc.entry(name.clone()).or_insert(schema); | ||
// schema.add_child_schemas(acc); | ||
// } | ||
// } | ||
// } |
Oops, something went wrong.