update typify and nexus.json (#323)
This commit is contained in:
parent
8a09b98645
commit
88ff3cf1e0
|
@ -2025,7 +2025,7 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typify"
|
name = "typify"
|
||||||
version = "0.0.11-dev"
|
version = "0.0.11-dev"
|
||||||
source = "git+https://github.com/oxidecomputer/typify#cd1f95b66b0d0fbb33537d66043f26512ee3268b"
|
source = "git+https://github.com/oxidecomputer/typify#b745a238675ef5c9ee2466029fc8804db292eb51"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"typify-impl",
|
"typify-impl",
|
||||||
"typify-macro",
|
"typify-macro",
|
||||||
|
@ -2034,7 +2034,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typify-impl"
|
name = "typify-impl"
|
||||||
version = "0.0.11-dev"
|
version = "0.0.11-dev"
|
||||||
source = "git+https://github.com/oxidecomputer/typify#cd1f95b66b0d0fbb33537d66043f26512ee3268b"
|
source = "git+https://github.com/oxidecomputer/typify#b745a238675ef5c9ee2466029fc8804db292eb51"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck",
|
"heck",
|
||||||
"log",
|
"log",
|
||||||
|
@ -2052,7 +2052,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typify-macro"
|
name = "typify-macro"
|
||||||
version = "0.0.11-dev"
|
version = "0.0.11-dev"
|
||||||
source = "git+https://github.com/oxidecomputer/typify#cd1f95b66b0d0fbb33537d66043f26512ee3268b"
|
source = "git+https://github.com/oxidecomputer/typify#b745a238675ef5c9ee2466029fc8804db292eb51"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2022 Oxide Computer Company
|
// Copyright 2023 Oxide Computer Company
|
||||||
|
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ use typify::{TypeSpace, TypeSpaceSettings};
|
||||||
|
|
||||||
use crate::to_schema::ToSchema;
|
use crate::to_schema::ToSchema;
|
||||||
|
|
||||||
|
pub use typify::TypeSpaceImpl as TypeImpl;
|
||||||
pub use typify::TypeSpacePatch as TypePatch;
|
pub use typify::TypeSpacePatch as TypePatch;
|
||||||
|
|
||||||
mod method;
|
mod method;
|
||||||
|
@ -53,8 +54,8 @@ pub struct GenerationSettings {
|
||||||
extra_derives: Vec<String>,
|
extra_derives: Vec<String>,
|
||||||
|
|
||||||
patch: HashMap<String, TypePatch>,
|
patch: HashMap<String, TypePatch>,
|
||||||
replace: HashMap<String, (String, Vec<String>)>,
|
replace: HashMap<String, (String, Vec<TypeImpl>)>,
|
||||||
convert: Vec<(schemars::schema::SchemaObject, String, Vec<String>)>,
|
convert: Vec<(schemars::schema::SchemaObject, String, Vec<TypeImpl>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, PartialEq, Eq)]
|
#[derive(Clone, Deserialize, PartialEq, Eq)]
|
||||||
|
@ -129,7 +130,7 @@ impl GenerationSettings {
|
||||||
pub fn with_replacement<
|
pub fn with_replacement<
|
||||||
TS: ToString,
|
TS: ToString,
|
||||||
RS: ToString,
|
RS: ToString,
|
||||||
I: Iterator<Item = impl ToString>,
|
I: Iterator<Item = TypeImpl>,
|
||||||
>(
|
>(
|
||||||
&mut self,
|
&mut self,
|
||||||
type_name: TS,
|
type_name: TS,
|
||||||
|
@ -138,25 +139,19 @@ impl GenerationSettings {
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.replace.insert(
|
self.replace.insert(
|
||||||
type_name.to_string(),
|
type_name.to_string(),
|
||||||
(
|
(replace_name.to_string(), impls.collect()),
|
||||||
replace_name.to_string(),
|
|
||||||
impls.map(|x| x.to_string()).collect(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_conversion<S: ToString, I: Iterator<Item = impl ToString>>(
|
pub fn with_conversion<S: ToString, I: Iterator<Item = TypeImpl>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
schema: schemars::schema::SchemaObject,
|
schema: schemars::schema::SchemaObject,
|
||||||
type_name: S,
|
type_name: S,
|
||||||
impls: I,
|
impls: I,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.convert.push((
|
self.convert
|
||||||
schema,
|
.push((schema, type_name.to_string(), impls.collect()));
|
||||||
type_name.to_string(),
|
|
||||||
impls.map(|x| x.to_string()).collect(),
|
|
||||||
));
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,7 +186,7 @@ impl Generator {
|
||||||
type_settings.with_replacement(
|
type_settings.with_replacement(
|
||||||
type_name,
|
type_name,
|
||||||
replace_name,
|
replace_name,
|
||||||
impls.iter(),
|
impls.iter().cloned(),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -202,7 +197,7 @@ impl Generator {
|
||||||
type_settings.with_conversion(
|
type_settings.with_conversion(
|
||||||
schema.clone(),
|
schema.clone(),
|
||||||
type_name,
|
type_name,
|
||||||
impls.iter(),
|
impls.iter().cloned(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
Self {
|
Self {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -6,7 +6,8 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use progenitor_impl::{
|
use progenitor_impl::{
|
||||||
GenerationSettings, Generator, InterfaceStyle, TagStyle, TypePatch,
|
GenerationSettings, Generator, InterfaceStyle, TagStyle, TypeImpl,
|
||||||
|
TypePatch,
|
||||||
};
|
};
|
||||||
|
|
||||||
use openapiv3::OpenAPI;
|
use openapiv3::OpenAPI;
|
||||||
|
@ -19,7 +20,7 @@ where
|
||||||
match serde_json::from_reader(f) {
|
match serde_json::from_reader(f) {
|
||||||
Ok(json_value) => json_value,
|
Ok(json_value) => json_value,
|
||||||
_ => {
|
_ => {
|
||||||
f = File::open(p.clone()).unwrap();
|
f = File::open(p).unwrap();
|
||||||
serde_yaml::from_reader(f).unwrap()
|
serde_yaml::from_reader(f).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +56,7 @@ fn verify_apis(openapi_file: &str) {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
"usize",
|
"usize",
|
||||||
["Display"].into_iter(),
|
[TypeImpl::Display].into_iter(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
let output = generator.generate_text_normalize_comments(&spec).unwrap();
|
let output = generator.generate_text_normalize_comments(&spec).unwrap();
|
||||||
|
|
|
@ -217,21 +217,13 @@ fn do_generate_api(item: TokenStream) -> Result<TokenStream, syn::Error> {
|
||||||
});
|
});
|
||||||
replace.into_iter().for_each(|(type_name, type_and_impls)| {
|
replace.into_iter().for_each(|(type_name, type_and_impls)| {
|
||||||
let type_name = type_name.to_token_stream();
|
let type_name = type_name.to_token_stream();
|
||||||
let type_and_impls = type_and_impls.into_inner();
|
let (replace_name, impls) =
|
||||||
let replace_name = type_and_impls.type_name.to_token_stream();
|
type_and_impls.into_inner().into_name_and_impls();
|
||||||
let impls = type_and_impls
|
|
||||||
.impls
|
|
||||||
.into_iter()
|
|
||||||
.map(|x| x.to_token_stream());
|
|
||||||
settings.with_replacement(type_name, replace_name, impls);
|
settings.with_replacement(type_name, replace_name, impls);
|
||||||
});
|
});
|
||||||
convert.into_iter().for_each(|(schema, type_and_impls)| {
|
convert.into_iter().for_each(|(schema, type_and_impls)| {
|
||||||
let type_and_impls = type_and_impls.into_inner();
|
let (type_name, impls) =
|
||||||
let type_name = type_and_impls.type_name.to_token_stream();
|
type_and_impls.into_inner().into_name_and_impls();
|
||||||
let impls = type_and_impls
|
|
||||||
.impls
|
|
||||||
.into_iter()
|
|
||||||
.map(|x| x.to_token_stream());
|
|
||||||
settings.with_conversion(schema, type_name, impls);
|
settings.with_conversion(schema, type_name, impls);
|
||||||
});
|
});
|
||||||
(spec.into_inner(), settings)
|
(spec.into_inner(), settings)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
// Copyright 2023 Oxide Computer Company
|
// Copyright 2023 Oxide Computer Company
|
||||||
|
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use quote::ToTokens;
|
use quote::ToTokens;
|
||||||
use syn::{
|
use syn::{
|
||||||
parse::Parse,
|
parse::Parse,
|
||||||
|
@ -8,6 +10,8 @@ use syn::{
|
||||||
Ident, Path, Token, TraitBoundModifier,
|
Ident, Path, Token, TraitBoundModifier,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use progenitor_impl::TypeImpl;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TypeAndImpls {
|
pub struct TypeAndImpls {
|
||||||
pub type_name: Path,
|
pub type_name: Path,
|
||||||
|
@ -15,6 +19,41 @@ pub struct TypeAndImpls {
|
||||||
pub impls: Punctuated<ImplTrait, Add>,
|
pub impls: Punctuated<ImplTrait, Add>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TypeAndImpls {
|
||||||
|
pub(crate) fn into_name_and_impls(
|
||||||
|
self,
|
||||||
|
) -> (String, impl Iterator<Item = TypeImpl>) {
|
||||||
|
// If there are no traits specified, these are assumed to be
|
||||||
|
// implemented. A user would use the `?FromStr` syntax to remove one of
|
||||||
|
// these defaults;
|
||||||
|
const DEFAULT_IMPLS: [TypeImpl; 2] =
|
||||||
|
[TypeImpl::FromStr, TypeImpl::Display];
|
||||||
|
|
||||||
|
let name = self.type_name.to_token_stream().to_string();
|
||||||
|
let mut impls = DEFAULT_IMPLS.into_iter().collect::<HashSet<_>>();
|
||||||
|
self.impls.into_iter().for_each(
|
||||||
|
|ImplTrait {
|
||||||
|
modifier,
|
||||||
|
impl_name,
|
||||||
|
..
|
||||||
|
}| {
|
||||||
|
// TODO should this be an error rather than silently ignored?
|
||||||
|
if let Some(impl_name) = impl_name {
|
||||||
|
match modifier {
|
||||||
|
syn::TraitBoundModifier::None => {
|
||||||
|
impls.insert(impl_name)
|
||||||
|
}
|
||||||
|
syn::TraitBoundModifier::Maybe(_) => {
|
||||||
|
impls.remove(&impl_name)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
(name, impls.into_iter())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Parse for TypeAndImpls {
|
impl Parse for TypeAndImpls {
|
||||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||||
let type_name: Path = input.parse()?;
|
let type_name: Path = input.parse()?;
|
||||||
|
@ -52,16 +91,19 @@ impl ToTokens for TypeAndImpls {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ImplTrait {
|
pub struct ImplTrait {
|
||||||
pub modifier: TraitBoundModifier,
|
pub modifier: TraitBoundModifier,
|
||||||
pub impl_name: Ident,
|
pub impl_ident: Ident,
|
||||||
|
pub impl_name: Option<TypeImpl>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for ImplTrait {
|
impl Parse for ImplTrait {
|
||||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||||
let modifier: TraitBoundModifier = input.parse()?;
|
let modifier: TraitBoundModifier = input.parse()?;
|
||||||
let impl_name: Ident = input.parse()?;
|
let impl_ident: Ident = input.parse()?;
|
||||||
|
let impl_name = impl_ident.to_string().parse().ok();
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
modifier,
|
modifier,
|
||||||
|
impl_ident,
|
||||||
impl_name,
|
impl_name,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -70,7 +112,7 @@ impl Parse for ImplTrait {
|
||||||
impl ToTokens for ImplTrait {
|
impl ToTokens for ImplTrait {
|
||||||
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
||||||
self.modifier.to_tokens(tokens);
|
self.modifier.to_tokens(tokens);
|
||||||
self.impl_name.to_tokens(tokens);
|
self.impl_ident.to_tokens(tokens);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue