update typify and nexus.json (#323)
This commit is contained in:
parent
8a09b98645
commit
88ff3cf1e0
|
@ -2025,7 +2025,7 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
|
|||
[[package]]
|
||||
name = "typify"
|
||||
version = "0.0.11-dev"
|
||||
source = "git+https://github.com/oxidecomputer/typify#cd1f95b66b0d0fbb33537d66043f26512ee3268b"
|
||||
source = "git+https://github.com/oxidecomputer/typify#b745a238675ef5c9ee2466029fc8804db292eb51"
|
||||
dependencies = [
|
||||
"typify-impl",
|
||||
"typify-macro",
|
||||
|
@ -2034,7 +2034,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "typify-impl"
|
||||
version = "0.0.11-dev"
|
||||
source = "git+https://github.com/oxidecomputer/typify#cd1f95b66b0d0fbb33537d66043f26512ee3268b"
|
||||
source = "git+https://github.com/oxidecomputer/typify#b745a238675ef5c9ee2466029fc8804db292eb51"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"log",
|
||||
|
@ -2052,7 +2052,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "typify-macro"
|
||||
version = "0.0.11-dev"
|
||||
source = "git+https://github.com/oxidecomputer/typify#cd1f95b66b0d0fbb33537d66043f26512ee3268b"
|
||||
source = "git+https://github.com/oxidecomputer/typify#b745a238675ef5c9ee2466029fc8804db292eb51"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2022 Oxide Computer Company
|
||||
// Copyright 2023 Oxide Computer Company
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
|
@ -11,6 +11,7 @@ use typify::{TypeSpace, TypeSpaceSettings};
|
|||
|
||||
use crate::to_schema::ToSchema;
|
||||
|
||||
pub use typify::TypeSpaceImpl as TypeImpl;
|
||||
pub use typify::TypeSpacePatch as TypePatch;
|
||||
|
||||
mod method;
|
||||
|
@ -53,8 +54,8 @@ pub struct GenerationSettings {
|
|||
extra_derives: Vec<String>,
|
||||
|
||||
patch: HashMap<String, TypePatch>,
|
||||
replace: HashMap<String, (String, Vec<String>)>,
|
||||
convert: Vec<(schemars::schema::SchemaObject, String, Vec<String>)>,
|
||||
replace: HashMap<String, (String, Vec<TypeImpl>)>,
|
||||
convert: Vec<(schemars::schema::SchemaObject, String, Vec<TypeImpl>)>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, PartialEq, Eq)]
|
||||
|
@ -129,7 +130,7 @@ impl GenerationSettings {
|
|||
pub fn with_replacement<
|
||||
TS: ToString,
|
||||
RS: ToString,
|
||||
I: Iterator<Item = impl ToString>,
|
||||
I: Iterator<Item = TypeImpl>,
|
||||
>(
|
||||
&mut self,
|
||||
type_name: TS,
|
||||
|
@ -138,25 +139,19 @@ impl GenerationSettings {
|
|||
) -> &mut Self {
|
||||
self.replace.insert(
|
||||
type_name.to_string(),
|
||||
(
|
||||
replace_name.to_string(),
|
||||
impls.map(|x| x.to_string()).collect(),
|
||||
),
|
||||
(replace_name.to_string(), impls.collect()),
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_conversion<S: ToString, I: Iterator<Item = impl ToString>>(
|
||||
pub fn with_conversion<S: ToString, I: Iterator<Item = TypeImpl>>(
|
||||
&mut self,
|
||||
schema: schemars::schema::SchemaObject,
|
||||
type_name: S,
|
||||
impls: I,
|
||||
) -> &mut Self {
|
||||
self.convert.push((
|
||||
schema,
|
||||
type_name.to_string(),
|
||||
impls.map(|x| x.to_string()).collect(),
|
||||
));
|
||||
self.convert
|
||||
.push((schema, type_name.to_string(), impls.collect()));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
@ -191,7 +186,7 @@ impl Generator {
|
|||
type_settings.with_replacement(
|
||||
type_name,
|
||||
replace_name,
|
||||
impls.iter(),
|
||||
impls.iter().cloned(),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
@ -202,7 +197,7 @@ impl Generator {
|
|||
type_settings.with_conversion(
|
||||
schema.clone(),
|
||||
type_name,
|
||||
impls.iter(),
|
||||
impls.iter().cloned(),
|
||||
);
|
||||
});
|
||||
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::{
|
||||
GenerationSettings, Generator, InterfaceStyle, TagStyle, TypePatch,
|
||||
GenerationSettings, Generator, InterfaceStyle, TagStyle, TypeImpl,
|
||||
TypePatch,
|
||||
};
|
||||
|
||||
use openapiv3::OpenAPI;
|
||||
|
@ -19,7 +20,7 @@ where
|
|||
match serde_json::from_reader(f) {
|
||||
Ok(json_value) => json_value,
|
||||
_ => {
|
||||
f = File::open(p.clone()).unwrap();
|
||||
f = File::open(p).unwrap();
|
||||
serde_yaml::from_reader(f).unwrap()
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +56,7 @@ fn verify_apis(openapi_file: &str) {
|
|||
..Default::default()
|
||||
},
|
||||
"usize",
|
||||
["Display"].into_iter(),
|
||||
[TypeImpl::Display].into_iter(),
|
||||
),
|
||||
);
|
||||
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)| {
|
||||
let type_name = type_name.to_token_stream();
|
||||
let type_and_impls = type_and_impls.into_inner();
|
||||
let replace_name = type_and_impls.type_name.to_token_stream();
|
||||
let impls = type_and_impls
|
||||
.impls
|
||||
.into_iter()
|
||||
.map(|x| x.to_token_stream());
|
||||
let (replace_name, impls) =
|
||||
type_and_impls.into_inner().into_name_and_impls();
|
||||
settings.with_replacement(type_name, replace_name, impls);
|
||||
});
|
||||
convert.into_iter().for_each(|(schema, type_and_impls)| {
|
||||
let type_and_impls = type_and_impls.into_inner();
|
||||
let type_name = type_and_impls.type_name.to_token_stream();
|
||||
let impls = type_and_impls
|
||||
.impls
|
||||
.into_iter()
|
||||
.map(|x| x.to_token_stream());
|
||||
let (type_name, impls) =
|
||||
type_and_impls.into_inner().into_name_and_impls();
|
||||
settings.with_conversion(schema, type_name, impls);
|
||||
});
|
||||
(spec.into_inner(), settings)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
// Copyright 2023 Oxide Computer Company
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use quote::ToTokens;
|
||||
use syn::{
|
||||
parse::Parse,
|
||||
|
@ -8,6 +10,8 @@ use syn::{
|
|||
Ident, Path, Token, TraitBoundModifier,
|
||||
};
|
||||
|
||||
use progenitor_impl::TypeImpl;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TypeAndImpls {
|
||||
pub type_name: Path,
|
||||
|
@ -15,6 +19,41 @@ pub struct TypeAndImpls {
|
|||
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 {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
let type_name: Path = input.parse()?;
|
||||
|
@ -52,16 +91,19 @@ impl ToTokens for TypeAndImpls {
|
|||
#[derive(Debug)]
|
||||
pub struct ImplTrait {
|
||||
pub modifier: TraitBoundModifier,
|
||||
pub impl_name: Ident,
|
||||
pub impl_ident: Ident,
|
||||
pub impl_name: Option<TypeImpl>,
|
||||
}
|
||||
|
||||
impl Parse for ImplTrait {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
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 {
|
||||
modifier,
|
||||
impl_ident,
|
||||
impl_name,
|
||||
})
|
||||
}
|
||||
|
@ -70,7 +112,7 @@ impl Parse for ImplTrait {
|
|||
impl ToTokens for ImplTrait {
|
||||
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
||||
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