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

Implementing Serialization and OpenAPI typing for structs from external libraries #588

Open
UnknownError55 opened this issue Jun 19, 2023 · 0 comments
Labels
question Further information is requested

Comments

@UnknownError55
Copy link

I am using a library with hundreds of auto-generated structs. All json-serializable with serde. However, the library does not implement the necessary traits for poem-openapi.

The rather tedious solution is to create a tandem pair for the structs I want to serialize via the poem library. But seeing as I would need to manually recreate hundreds of near-identical structs from a library... This can be done, but is tedious and error-prone. I would much rather link to the actual struct I am trying to use instead writing conversion functions back and fourth between the two.

So, my current thought is to use a bit of a proxy object? Something like the following:

#[derive(Object)]
#[oai(concrete(name = "Vector2", params(glam::Vec2)))]
#[oai(concrete(name = "Vector3", params(glam::Vec3)))]
pub struct Jsonified<T> {
    #[serde(flatten)]
    pub inner: T
}

Note that the above does not compile. And secondary to that, poem, to the best of my knowledge, does not really use serde. So attempting to use #[serde(flatten)] would likely be a useless gesture. The idea to use concreate have a named reference to each proxy reference. I got this idea while looking though the issues. Specifically this issue that references this practice. Where the issue focused on allowing named generics. If I could do something like this, where I can easily name each concrete type for the proxy, that would be a much easier method to include structs maintained by another library if no other method is currently present to do the same.

@UnknownError55 UnknownError55 added the question Further information is requested label Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant