boxdot / openapi-schema

Apache License 2.0
4 stars 1 forks source link

Integration with Actix #9

Open antoine-de opened 5 years ago

antoine-de commented 5 years ago

I've seen that you want to have an integration with Actix to be able to describe the different routes.

Have you started working of this ? Can I help you with this ?

Note: The problem I see for this work is the current changes in Actix-web. It does not seems very efficient to implement this for Actix-web 0.7, and the 1.0 is not officially released yet.

boxdot commented 5 years ago

I had a proof of concept working, however as you said I decided to wait for 1.0. 1.0 is already in beta, so it might be worth it already to start implementing something.

boxdot commented 5 years ago

So, I started to expand my proof of concept and hit a wall. The problem is the following: If we want to extend actix-web without breaking the public API, we have to extract the information from the types from handlers. Actix-web 1.0 requires that each handler returns a type that implements Resolver trait. E.g. Json<T> implements Resolver trait if T implements serde::Serialize. And here we get the problem. We can't require that T implements OpenapiSchema without breaking the API of clients. What we would need is a generic default implementation of OpenapiSchema for each type T which implements serde::Serialize, however without template specialization there is no way to overwrite this default implementation.

antoine-de commented 5 years ago

arf, I see the problem :cry: maybe you can reply on the actix's issue https://github.com/actix/actix-web/issues/310 to ask if anyone see another way to model this ?

boxdot commented 5 years ago

As proof of concept, I enabled #![feature(specialization)] in my fork of actix-web and started to implemenet spec and schema generation: https://github.com/actix/actix-web/compare/master...boxdot:openapi-schema

I have a very basic generation for app and endpoints (no scopes), and at the same some generation of Response and schemas for Json<T>. So, I am coming from both sides: from app spec and individual static handler spec. I hope I will meet soon in the middle and give an example for generation.

Hopefully, this gives us an inspiration how to work around the nightly specialization feature.

clearydude commented 5 years ago

Keeping my fingers crossed that you are unblocked on this soon, this feature would be super useful!