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

#[serde(flatten)] may not be supported (yet) #120

Closed
bhoudebert opened this issue Apr 28, 2022 · 2 comments
Closed

#[serde(flatten)] may not be supported (yet) #120

bhoudebert opened this issue Apr 28, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@bhoudebert
Copy link

If we design a struct with the special instruction flatten of serde it is not flatten during schema creation.

#[derive(Serialize, Deserialize, Debug, Clone, Component)]
pub struct SomePayload {
  some_id: String,
  
  #[serde(flatten)]
  extras: ExtraContent,
}

So would it be possible to tackle that point, maybe like the example, format, write_only?

#[derive(Serialize, Deserialize, Debug, Clone, Component)]
pub struct SomePayload {
  some_id: String,

  #[serde(flatten)]
  #[component(nested = true)]
  extras: ExtraContent,
}
@juhaku
Copy link
Owner

juhaku commented Apr 28, 2022

Yes flatten is not supported at least yet. To support this there is actually couple of things could be done and there is no need to have #[component(nested = true)] necessarily.

a) If component have #[serde(flatten)] attribute the component could be transformed to AllOf type which then contains the own schema inlined and the references to the other schemas. But then it means that the ExtraContent need to be Component as well.

b) If component will have the #[serde(flatten)] then propably runtime ther should be custom modifier which does handle this nested mangling of types by copying the properties from nested type to the actual type etc. And similarly the ExtraContent should be a Component as well.

I would prefer the a) since its simplier solution and works well with the compile time design. b) at the other hand needs some hacks and takes a toll with performing some schema mangling at runtime, but would not use AllOf composite type and all properties would be directly under the SomePayload itself.

@bhoudebert
Copy link
Author

I would be ok with anything solving this but sure a) detection would be really great and for the side note I already deal with ExtraContent as a Component which to me is not an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Released
Development

No branches or pull requests

2 participants