minor cleanup (#8)
This commit is contained in:
parent
273120683b
commit
3fe0029f5d
|
@ -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
|
|
@ -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",
|
||||
]
|
||||
|
|
|
@ -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"
|
||||
|
|
126
src/main.rs
126
src/main.rs
|
@ -171,7 +171,6 @@ where
|
|||
}
|
||||
|
||||
trait ParameterDataExt {
|
||||
fn render_type(&self) -> Result<String>;
|
||||
fn schema(&self) -> Result<&openapiv3::ReferenceOr<openapiv3::Schema>>;
|
||||
}
|
||||
|
||||
|
@ -182,83 +181,6 @@ impl ParameterDataExt for openapiv3::ParameterData {
|
|||
x => bail!("XXX param format {:#?}", x),
|
||||
}
|
||||
}
|
||||
|
||||
fn render_type(&self) -> Result<String> {
|
||||
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<T> ReferenceOrExt<T> for openapiv3::ReferenceOr<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[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<String, TypeId>),
|
||||
NewType(TypeId),
|
||||
Enumeration(Vec<String>),
|
||||
/*
|
||||
* A map with string keys and values of a specific type:
|
||||
*/
|
||||
Dictionary(TypeId),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct TypeEntry {
|
||||
id: TypeId,
|
||||
name: Option<String>,
|
||||
details: TypeDetails,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, Clone)]
|
||||
struct TypeId(u64);
|
||||
|
||||
impl PartialOrd for TypeId {
|
||||
fn partial_cmp(&self, other: &TypeId) -> Option<std::cmp::Ordering> {
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue