- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 297
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
Add support for remote
on fields
#323
Comments
Do you want the code below to work?
mod remote {
#[derive(Debug, Eq, PartialEq)]
pub struct InternalMyObj {
pub a: i32,
pub b: String,
}
}
#[derive(Debug, Object, Eq, PartialEq)]
#[oai(remote = "remote::InternalMyObj")]
struct MyObj {
a: i32,
} |
Hmm not quite, what I really want is something like this: #322. This code explains what I want better: mod remote {
#[derive(Debug, Eq, PartialEq)]
pub struct Address(pub String);
}
#[derive(Debug, Eq, PartialEq, NewType)]
struct AddressHelper(pub String);
impl From<remote::Address> for AddressHelper {
fn from(address: remote::Address) -> Self {
Self(address.0)
}
}
impl Into<remote::Address> for AddressHelper {
fn into(self) -> remote::Address {
remote::Address(self.0)
}
}
#[derive(Debug, Object, Eq, PartialEq)]
struct MyObj {
#[oai(serializer_type = AddressHelper)]
address: Address,
value: u32,
} For this The purpose of this is I can now use This is pretty much a clearer description of #322, so let me know if you want me to close this issue and we migrate to that one. |
There is a problem with ownership here, when calling |
I think that's an acceptable bound to have if you want to use this feature. I'll look at the traits some more to make sure I understand what you're talking about though. |
Maybe you can use #[derive(Debug, Object, Eq, PartialEq)]
struct MyObj {
address: AddressHelper,
value: u32,
} |
The problem is I have like 100 places where I use the original |
Although there are many places to add |
Yeah one time job lol, probably not worth your effort to add right now hahah. A nice feature for the future perhaps. |
Okay more than a one time job, wrapping everything is becoming a bit painful. It's okay for now though. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
This issue was closed because it has been stalled for 5 days with no activity. |
Hey, I just took a look at modifying
poem-openapi-derive/src/object.rs
but I couldn't quite figure out what to do.What I'd love to be able to do is something like this:
This is just an example, in reality the type I use in remote would be a local version of a remote type, so I can impl the Poem stuff on it.
I want this because today if I wanted to do this, I would have to add remote to the whole struct instead and define a whole new wrapper struct, even though I only want this for one field.
I suppose in some ways this is similar to #322. My ultimate goal is I have a newtype in a remote crate that I don't want to have to wrap, since I use it in many places.
The text was updated successfully, but these errors were encountered: