Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: keep_unknown_fields support yml config #210

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions examples/src/unknown/thrift_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use std::net::SocketAddr;
pub struct S;

#[volo::async_trait]
impl volo_gen::volo_gen::echo_unknown::EchoService for S {
impl volo_gen::thrift_gen::echo_unknown::EchoService for S {
async fn hello(
&self,
req: volo_gen::volo_gen::echo_unknown::EchoRequest,
) -> Result<volo_gen::volo_gen::echo_unknown::EchoResponse, volo_thrift::AnyhowError> {
let resp = volo_gen::volo_gen::echo_unknown::EchoResponse {
req: volo_gen::thrift_gen::echo_unknown::EchoRequest,
) -> Result<volo_gen::thrift_gen::echo_unknown::EchoResponse, volo_thrift::AnyhowError> {
let resp = volo_gen::thrift_gen::echo_unknown::EchoResponse {
name: format!("{}", req.name).into(),
echo_union: req.echo_union,
_unknown_fields: req._unknown_fields,
Expand All @@ -25,7 +25,7 @@ async fn main() {
let addr: SocketAddr = "[::]:8081".parse().unwrap();
let addr = volo::net::Address::from(addr);

volo_gen::volo_gen::echo_unknown::EchoServiceServer::new(S)
volo_gen::thrift_gen::echo_unknown::EchoServiceServer::new(S)
.run(addr)
.await
.unwrap();
Expand Down
6 changes: 0 additions & 6 deletions examples/volo-gen/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
fn main() {
volo_build::ConfigBuilder::default().write().unwrap();

volo_build::Builder::thrift()
.add_service("../thrift_idl/echo_unknown.thrift")
.keep_unknown_fields(true)
.write()
.unwrap();
}
1 change: 0 additions & 1 deletion examples/volo-gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
mod gen {
volo::include_service!("thrift_gen.rs");
volo::include_service!("proto_gen.rs");
volo::include_service!("volo_gen.rs");
}

pub use gen::*;
3 changes: 3 additions & 0 deletions examples/volo-gen/volo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ entries:
path: ../thrift_idl/hello.thrift
- source: local
path: ../thrift_idl/echo.thrift
- source: local
path: ../thrift_idl/echo_unknown.thrift
keep_unknown_fields: true
21 changes: 19 additions & 2 deletions volo-build/src/config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ impl InnerBuilder {
InnerBuilder::Thrift(inner) => InnerBuilder::Thrift(inner.touch(items)),
}
}

pub fn keep_unknown_fields(self, keep: impl IntoIterator<Item = PathBuf>) -> Self {
match self {
InnerBuilder::Protobuf(inner) => {
InnerBuilder::Protobuf(inner.keep_unknown_fields(keep))
}
InnerBuilder::Thrift(inner) => InnerBuilder::Thrift(inner.keep_unknown_fields(keep)),
}
}
}

impl ConfigBuilder {
Expand Down Expand Up @@ -123,12 +132,16 @@ impl ConfigBuilder {
path,
includes,
touch,
keep_unknown_fields,
} = get_or_download_idl(idl, &*DEFAULT_DIR)?;

builder = builder
.add_service(path.clone())
.includes(includes)
.touch([(path, touch)])
.touch([(path.clone(), touch)]);
if keep_unknown_fields {
builder = builder.keep_unknown_fields([path])
}
}

builder.write()?;
Expand Down Expand Up @@ -166,12 +179,16 @@ impl InitBuilder {
path,
includes,
touch,
keep_unknown_fields,
} = get_or_download_idl(idl, &*DEFAULT_DIR)?;

builder = builder
.add_service(path.clone())
.includes(includes)
.touch([(path, touch)])
.touch([(path.clone(), touch)]);
if keep_unknown_fields {
builder = builder.keep_unknown_fields([path])
}
}

builder.init_service()
Expand Down
5 changes: 4 additions & 1 deletion volo-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ impl<MkB, Parser> Builder<MkB, Parser> {
self
}

pub fn keep_unknown_fields(mut self, keep_unknown_fields: bool) -> Self {
pub fn keep_unknown_fields(
mut self,
keep_unknown_fields: impl IntoIterator<Item = PathBuf>,
) -> Self {
self.pilota_builder = self.pilota_builder.keep_unknown_fields(keep_unknown_fields);
self
}
Expand Down
7 changes: 7 additions & 0 deletions volo-build/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ pub struct Idl {
pub includes: Option<Vec<PathBuf>>,
#[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")]
pub touch: Vec<String>,
#[serde(default = "default_keep_unknown_fields")]
pub keep_unknown_fields: bool,
}

fn default_keep_unknown_fields() -> bool {
false
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -74,6 +80,7 @@ impl Idl {
path: PathBuf::from(""),
includes: None,
touch: Vec::default(),
keep_unknown_fields: false,
}
}

Expand Down
2 changes: 2 additions & 0 deletions volo-build/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub struct LocalIdl {
pub path: PathBuf,
pub includes: Vec<PathBuf>,
pub touch: Vec<String>,
pub keep_unknown_fields: bool,
}

pub fn get_or_download_idl(idl: Idl, target_dir: impl AsRef<Path>) -> anyhow::Result<LocalIdl> {
Expand Down Expand Up @@ -108,6 +109,7 @@ pub fn get_or_download_idl(idl: Idl, target_dir: impl AsRef<Path>) -> anyhow::Re
path,
includes,
touch: idl.touch,
keep_unknown_fields: idl.keep_unknown_fields,
})
}

Expand Down
2 changes: 2 additions & 0 deletions volo-cli/src/idl/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ impl CliCommand for Add {
touch: vec![],
path: self.idl.clone(),
includes: self.includes.clone(),
keep_unknown_fields: false,
}
} else {
Idl {
source: Source::Local,
touch: vec![],
path: self.idl.clone(),
includes: self.includes.clone(),
keep_unknown_fields: false,
}
}
};
Expand Down
Loading