From 3fe0029f5de59db1da0d6a5afdeafc2f0af2a20e Mon Sep 17 00:00:00 2001 From: Adam Leventhal Date: Sat, 9 Oct 2021 08:38:01 -0700 Subject: [PATCH] minor cleanup (#8) --- .github/workflows/rust.yml | 34 ++++++++++ Cargo.lock | 15 ++++- Cargo.toml | 2 +- src/main.rs | 126 ------------------------------------- 4 files changed, 48 insertions(+), 129 deletions(-) create mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..9712afe --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,34 @@ +# +# Configuration for GitHub-based CI, based on the stock GitHub Rust config. +# +name: Build + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + check-style: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Report cargo version + run: cargo --version + - name: Report rustfmt version + run: cargo fmt -- --version + - name: Check style + run: cargo fmt -- --check + + build-and-test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-18.04, windows-2019, macos-10.15 ] + steps: + - uses: actions/checkout@v2 + - name: Build + run: cargo build --tests --verbose + - name: Run tests + run: cargo test --verbose diff --git a/Cargo.lock b/Cargo.lock index 03c3414..7050629 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -176,7 +176,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "rustfmt-wrapper", + "rustfmt-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "schemars", "serde", "serde_json", @@ -267,6 +267,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "rustfmt-wrapper" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7733577fb5b13c8b256232e7ca84aa424f915efae6ec980082d60a03f99da3f8" +dependencies = [ + "tempfile", + "thiserror", + "toolchain_find", +] + [[package]] name = "rustfmt-wrapper" version = "0.1.0" @@ -451,7 +462,7 @@ name = "typify" version = "0.0.1" source = "git+https://github.com/oxidecomputer/typify#b662d84d82feb20f81ff2cd62c1a0af8ed77515a" dependencies = [ - "rustfmt-wrapper", + "rustfmt-wrapper 0.1.0 (git+https://github.com/oxidecomputer/typify)", "typify-impl", "typify-macro", ] diff --git a/Cargo.toml b/Cargo.toml index 2f53f79..b526e05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ openapiv3 = "1.0.0-beta.2" proc-macro2 = "1.0.29" quote = "1.0.9" regex = "1.5.4" -rustfmt-wrapper = { git = "https://github.com/oxidecomputer/typify" } +rustfmt-wrapper = "0.1.0" schemars = "0.8.5" serde = { version = "1", features = [ "derive" ] } serde_json = "1.0.68" diff --git a/src/main.rs b/src/main.rs index 85ccc32..24bc29d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -171,7 +171,6 @@ where } trait ParameterDataExt { - fn render_type(&self) -> Result; fn schema(&self) -> Result<&openapiv3::ReferenceOr>; } @@ -182,83 +181,6 @@ impl ParameterDataExt for openapiv3::ParameterData { x => bail!("XXX param format {:#?}", x), } } - - fn render_type(&self) -> Result { - use openapiv3::{SchemaKind, Type}; - - Ok(match &self.format { - openapiv3::ParameterSchemaOrContent::Schema(s) => { - let s = s.item().context("parameter data render type")?; - match &s.schema_kind { - SchemaKind::Type(Type::String(st)) => { - if !st.format.is_empty() { - bail!("XXX format"); - } - if st.pattern.is_some() { - bail!("XXX pattern"); - } - if !st.enumeration.is_empty() { - bail!("XXX enumeration"); - } - if st.min_length.is_some() || st.max_length.is_some() { - bail!("XXX min/max length"); - } - "&str".to_string() - } - SchemaKind::Type(Type::Integer(it)) => { - let mut uint; - let width; - - use openapiv3::VariantOrUnknownOrEmpty::Unknown; - if let Unknown(f) = &it.format { - match f.as_str() { - "uint" | "uint32" => { - uint = true; - width = 32; - } - "uint64" => { - uint = true; - width = 32; - } - f => bail!("XXX unknown integer format {}", f), - } - } else { - bail!("XXX format {:?}", it.format); - } - - if it.multiple_of.is_some() { - bail!("XXX multiple_of"); - } - if it.exclusive_minimum || it.exclusive_maximum { - bail!("XXX exclusive"); - } - - if let Some(min) = it.minimum { - if min == 0 { - uint = true; - } else { - bail!("XXX invalid minimum: {}", min); - } - } - - if it.maximum.is_some() { - bail!("XXX maximum"); - } - if !it.enumeration.is_empty() { - bail!("XXX enumeration"); - } - if uint { - format!("u{}", width) - } else { - format!("i{}", width) - } - } - x => bail!("unexpected type {:#?}", x), - } - } - x => bail!("XXX param format {:#?}", x), - }) - } } trait ExtractJsonMediaType { @@ -443,54 +365,6 @@ impl ReferenceOrExt for openapiv3::ReferenceOr { } } -#[allow(dead_code)] -#[derive(Debug, PartialEq)] -enum TypeDetails { - Unknown, - Basic, - Array(TypeId), - Optional(TypeId), - /* - * Object property names are sorted lexicographically to ensure a stable - * order in the generated code. - */ - Object(BTreeMap), - NewType(TypeId), - Enumeration(Vec), - /* - * A map with string keys and values of a specific type: - */ - Dictionary(TypeId), -} - -#[derive(Debug)] -struct TypeEntry { - id: TypeId, - name: Option, - details: TypeDetails, -} - -#[derive(Debug, Eq, Clone)] -struct TypeId(u64); - -impl PartialOrd for TypeId { - fn partial_cmp(&self, other: &TypeId) -> Option { - Some(self.cmp(other)) - } -} - -impl Ord for TypeId { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.0.cmp(&other.0) - } -} - -impl PartialEq for TypeId { - fn eq(&self, other: &TypeId) -> bool { - self.0 == other.0 - } -} - enum ParamType { Path, Query,