update to openapiv3 1.0.0-beta.1 to get (and test) some useful new bits (#3)
This commit is contained in:
parent
01f184f8fe
commit
3548096bdd
|
@ -60,9 +60,9 @@ checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openapiv3"
|
name = "openapiv3"
|
||||||
version = "0.4.0"
|
version = "1.0.0-beta.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0b3c622a8249a19c1b9730e6b3127cf2b0d42f47fbdf2e5ba43c43cfd48eb5ee"
|
checksum = "abe6e1dfe8bc4931d6e90adbe2cec19e3fd67f7453d64e9a17cbf8dc16a67ec9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -11,4 +11,4 @@ anyhow = "1"
|
||||||
getopts = "0.2"
|
getopts = "0.2"
|
||||||
serde = { version = "1", features = [ "derive" ]}
|
serde = { version = "1", features = [ "derive" ]}
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
openapiv3 = "0.4"
|
openapiv3 = "1.0.0-beta.1"
|
||||||
|
|
51
src/main.rs
51
src/main.rs
|
@ -54,7 +54,7 @@ where
|
||||||
bail!("servers not presently supported");
|
bail!("servers not presently supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
if !api.security.is_empty() {
|
if api.security.is_some() {
|
||||||
bail!("security not presently supported");
|
bail!("security not presently supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ where
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let mut opids = HashSet::new();
|
let mut opids = HashSet::new();
|
||||||
for p in api.paths.iter() {
|
for p in api.paths.paths.iter() {
|
||||||
match p.1 {
|
match p.1 {
|
||||||
openapiv3::ReferenceOr::Reference { reference: _ } => {
|
openapiv3::ReferenceOr::Reference { reference: _ } => {
|
||||||
bail!("path {} uses reference, unsupported", p.0);
|
bail!("path {} uses reference, unsupported", p.0);
|
||||||
|
@ -113,8 +113,8 @@ where
|
||||||
* Make sure every operation has an operation ID, and that each
|
* Make sure every operation has an operation ID, and that each
|
||||||
* operation ID is only used once in the document.
|
* operation ID is only used once in the document.
|
||||||
*/
|
*/
|
||||||
let mut id = |o: Option<&openapiv3::Operation>| -> Result<()> {
|
|
||||||
if let Some(o) = o {
|
for o in item.iter() {
|
||||||
if let Some(oid) = o.operation_id.as_ref() {
|
if let Some(oid) = o.operation_id.as_ref() {
|
||||||
if !opids.insert(oid.to_string()) {
|
if !opids.insert(oid.to_string()) {
|
||||||
bail!("duplicate operation ID: {}", oid);
|
bail!("duplicate operation ID: {}", oid);
|
||||||
|
@ -128,7 +128,7 @@ where
|
||||||
bail!("op {}: servers, unsupported", oid);
|
bail!("op {}: servers, unsupported", oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !o.security.is_empty() {
|
if o.security.is_some() {
|
||||||
bail!("op {}: security, unsupported", oid);
|
bail!("op {}: security, unsupported", oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,18 +140,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
};
|
|
||||||
|
|
||||||
id(item.get.as_ref())?;
|
|
||||||
id(item.put.as_ref())?;
|
|
||||||
id(item.post.as_ref())?;
|
|
||||||
id(item.delete.as_ref())?;
|
|
||||||
id(item.options.as_ref())?;
|
|
||||||
id(item.head.as_ref())?;
|
|
||||||
id(item.patch.as_ref())?;
|
|
||||||
id(item.trace.as_ref())?;
|
|
||||||
|
|
||||||
if !item.servers.is_empty() {
|
if !item.servers.is_empty() {
|
||||||
bail!("path {} has servers; unsupported", p.0);
|
bail!("path {} has servers; unsupported", p.0);
|
||||||
}
|
}
|
||||||
|
@ -740,10 +728,14 @@ impl TypeSpace {
|
||||||
let (name, details) = match &s.schema_kind {
|
let (name, details) = match &s.schema_kind {
|
||||||
openapiv3::SchemaKind::Type(t) => match t {
|
openapiv3::SchemaKind::Type(t) => match t {
|
||||||
openapiv3::Type::Array(at) => {
|
openapiv3::Type::Array(at) => {
|
||||||
|
if at.items.is_none() {
|
||||||
|
bail!("array items can't be none");
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Determine the type of item that will be in this array:
|
* Determine the type of item that will be in this array:
|
||||||
*/
|
*/
|
||||||
let itid = self.select_box(None, &at.items)?;
|
let itid =
|
||||||
|
self.select_box(None, at.items.as_ref().unwrap())?;
|
||||||
(None, TypeDetails::Array(itid))
|
(None, TypeDetails::Array(itid))
|
||||||
}
|
}
|
||||||
openapiv3::Type::Object(o) => {
|
openapiv3::Type::Object(o) => {
|
||||||
|
@ -793,19 +785,28 @@ impl TypeSpace {
|
||||||
}
|
}
|
||||||
Unknown(x) if x.as_str() == "uuid" => {
|
Unknown(x) if x.as_str() == "uuid" => {
|
||||||
self.import_uuid = true;
|
self.import_uuid = true;
|
||||||
(
|
(Some("Uuid".to_string()), TypeDetails::Basic)
|
||||||
Some("Uuid".to_string()),
|
|
||||||
TypeDetails::Basic,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Empty => {
|
Empty => {
|
||||||
use TypeDetails::{Enumeration, NewType};
|
use TypeDetails::{Enumeration, NewType};
|
||||||
|
|
||||||
if !st.enumeration.is_empty() {
|
if !st.enumeration.is_empty() {
|
||||||
if let Some(name) = name {
|
if let Some(name) = name {
|
||||||
|
if st.enumeration.contains(&None) {
|
||||||
|
bail!(
|
||||||
|
"null found in enumeration values"
|
||||||
|
);
|
||||||
|
}
|
||||||
(
|
(
|
||||||
Some(name.to_string()),
|
Some(name.to_string()),
|
||||||
Enumeration(st.enumeration.clone()),
|
Enumeration(
|
||||||
|
st.enumeration
|
||||||
|
.iter()
|
||||||
|
.map(|value| {
|
||||||
|
value.clone().unwrap()
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
bail!("enumeration without name: {:?}", st);
|
bail!("enumeration without name: {:?}", st);
|
||||||
|
@ -1125,7 +1126,7 @@ fn gen(api: &OpenAPI, ts: &mut TypeSpace) -> Result<String> {
|
||||||
* these, which can link in to the type space, instead of doing this inline
|
* these, which can link in to the type space, instead of doing this inline
|
||||||
* here.
|
* here.
|
||||||
*/
|
*/
|
||||||
for (pn, p) in api.paths.iter() {
|
for (pn, p) in api.paths.paths.iter() {
|
||||||
let op = p.item()?;
|
let op = p.item()?;
|
||||||
|
|
||||||
let mut gen = |p: &str,
|
let mut gen = |p: &str,
|
||||||
|
@ -1462,7 +1463,7 @@ fn main() -> Result<()> {
|
||||||
* In addition to types defined in schemas, types may be defined inline in
|
* In addition to types defined in schemas, types may be defined inline in
|
||||||
* request and response bodies.
|
* request and response bodies.
|
||||||
*/
|
*/
|
||||||
for (pn, p) in api.paths.iter() {
|
for (pn, p) in api.paths.paths.iter() {
|
||||||
let op = p.item()?;
|
let op = p.item()?;
|
||||||
|
|
||||||
let grab = |pn: &str,
|
let grab = |pn: &str,
|
||||||
|
|
Loading…
Reference in New Issue