-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Generate API documentation #310
Comments
I guess would kinda useful Currently the only facilities for this currently is HttpRequest::url_for or HttpRequest::url_for_static But I imagine something that could generate help information from App would be quite. But things like generating full fledged |
@spacekookie I think it would be extremely useful feature! If we could describe api we could export it as swagger spec, which would be awesome. |
I think generating swagger documentation would be my preferred auto documentation format because all the existing tooling. |
So what would actually have to happen to make this happen? Aka, how many versions do I have to wait for it? 😬 |
I want to try to work on it when I have some free time, but I'm very busy. The biggest hurdle has been solved when I found this stackoverflow question, which, when modified, should allow access to the extractor information of each route. |
Has something progress? |
I have some progress on one for Rocket, but not for actix-web, sorry. |
@DJMcNab How is that one implemented? Is there a crate that generates swagger or something like it? Because that work wouldn't need to be copied for actix-web |
It's slightly awkward because it's for a qualification - I can't give too much detail until about October :(, and especially not release any code until then. |
Oh :( That's very unfortuante. That's very teasing then 😅 |
I started working on |
I don't have anything to show from my experimenting but I have mostly been exploring the OpenAPI or something OpenAPI like to an Actix server so basically the opposite of what this is about. That said in my research I think something that would be essential to have for any framework would be a simple way to generate the OpenAPI schema definition based on serde annotations. I think that is one of the bigger pieces of this story. After that for actix-web in particular building extractors in such a way that they can be easily documented. I have some custom extractors I have built and I don't think we can support OpenAPI documentation generation from a custom extractor without someone to annotate the extractor directly to explain what parameters it is reading from. I'm going to continue exploring the space and if I every get around to building something more or less complete I will update my findings and ask for input. |
This would be a really useful feature. It looks like some people are trying to work on supporting this, but from what I can tell current actix really does not support getting any information from the App. |
What about to generate code for actix from openapi 3.0 file? |
@sergeysova for my specific use case that wouldn't really be super helpful (although it might be for others). Also I believe that swagger-codegen can be used to generate client/server code in rust from an openapi spec which could then be adapted to actix-web but I haven't tried it out. |
☝️I agree with @clearydude. It would be really great to be able to write inline docs. Something like the way flasgger can use docstrings in Python to then generate an API spec, would be nice. |
The prospect of generating a spec from an actix-web app is super exciting. We're currently in the throes of developing a process for generating typescript definitions for the serde data we're responding with, and we are able to run conformance tests when our server code changes. A CI job uses the server to spit out a new If we were able to have our actix server spit out an openapi spec, we'd be able to effectively use this for snapshot testing of our public API, checking the spec against the previous release. Snapshot testing like this could help to drive effective versioning of the API. This would be a very powerful communication tool, even for small shops like mine, keeping the team in the loop as we go. P.S, we are currently writing our specs independently by hand and rendering with ReDoc. It's basic but works for us. Likely if we got actix to generate a spec the way we'd like, we'd be doing it "offline" as a part of a docker build and spitting out the generated HTML to serve it as static files. That's our use case, at any rate. |
Hey everyone! I've been working on OpenAPI-related tooling over the past few weeks - I'm not completely sure whether actix-web should stick to some specification such as OpenAPI v2/v3, so I thought I could try to come up with a plugin for hosting the spec, and I may have a solution (I'm still working on the proof of concept). Taking this basic example: use actix_web::{App, web};
#[derive(Deserialize, Serialize)]
pub struct Pet {
name: String,
id: Option<String>,
}
fn add_pet(body: web::Json<Counter>) -> web::Json<Counter> {
body
}
let app = App::new()
.service(web::resource("/pets").route(web::post().to(add_pet))); Using the plugin, it'll become: use actix_web::App;
use paperclip::actix::{web, prelude::*}; // feature gated
#[api_v2_schema]
#[derive(Deserialize, Serialize)]
pub struct Pet {
name: String,
id: Option<String>,
}
#[api_v2_operation]
fn add_pet(body: web::Json<Counter>) -> web::Json<Counter> {
body
}
let app = App::new()
.wrap_api() // keep track of all routes and operations from this line
.with_json_spec_at("/api/spec")
.service(web::resource("/pets").route(web::post().to(add_pet)))
.build(); Other than the attributes on top of the handlers and models, the code will look pretty much exactly the same as the normal actix-web flow. WDYT?
|
@wafflespeanut looks pretty cool! if you want we can include section on actix.rs |
@fafhrd91 That'd be great! Thank you! I think I'll have a working version by this weekend. I'll post my updates here :) |
@wafflespeanut This looks great! Thanks so much for sharing :) Excited to check it out |
0Hi @fafhrd91! Would it be possible to expose (Progress update for everyone else! It's coming!) |
@wafflespeanut ok, but lets mark this traits as |
Hello everyone! I've just released paperclip 0.3.0 and it comes with the initial version of actix-web plugin for hosting OpenAPI v2 spec. It shouldn't break your actix-web flow. Please try it out! Detailed example in https://paperclip.waffles.space/actix-plugin.html :) |
Is there a way to add doxygen like API docs for a RESTful API? |
@jonnius yes but not really in Rust atm afaik. There are two plugins for having your server code output OpenAPI data, the paperclip project above for actix, and another WIP one for Rocket. I don't think either are at a point that they can use comments from your code to add to the documentation like Crates can. Paperclip also currently only supports OpenAPI v2(not that it should be a barrier for supporting descriptions). If you don't need descriptions and just want to document the REST API endpoints along with parameters, then either of these may be sufficient. Otherwise, you may want to consider writing the OpenAPI files(YAML/JSON) and using a generator to output Rust code and take it from there(no idea what quality is like for such). |
One work around I have settled on since I wanted to move to stable and
paperclip, at least at the time, didn't support stable is to use
https://apidocjs.com/. It has the downside that it is just parsing comments
and doesn't actually look at the code itself but it works quite well as a
stop gap until we have something better in the future.
…On Wed, Dec 11, 2019, 05:58 Brennan Kinney ***@***.***> wrote:
@jonnius <https://github.com/jonnius> yes but not really in Rust atm
afaik.
There are two plugins for having your server code output OpenAPI data, the
paperclip project above for actix, and another WIP one for Rocket. I don't
think either are at a point that they can use comments from your code to
add to the documentation like Crates can. Paperclip also currently only
supports OpenAPI v2(not that it should be a barrier for supporting
descriptions).
If you don't need descriptions and just want to document the REST API
endpoints along with parameters, then either of these may be sufficient.
Otherwise, you may want to consider writing the OpenAPI files(YAML/JSON)
and using a generator to output Rust code and take it from there(no idea
what quality is like for such).
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#310?email_source=notifications&email_token=AAPJZBCGQSVRQ3UASSOXSR3QYDPVRA5CNFSM4FEXHRKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGTAHDY#issuecomment-564528015>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAPJZBEW3I6PSDGVBSXYOZTQYDPVRANCNFSM4FEXHRKA>
.
|
Thanks for the replies. I need to add descriptions to the API end points. Can apiDoc be used with Rust code? It's not listed on their website. |
It isn't listed and it won't detect thing automatically but if you
explicitly tell it to look for .rs files and put the comments in /******
*
*/
Format like their js examples it works just fine since it is just parsing
comments. It isn't a great solution but it does the job.
…On Fri, Dec 13, 2019, 03:51 jonnius ***@***.***> wrote:
Thanks for the replies. I need to add descriptions to the API end points.
Can apiDoc be used with Rust code? It's not listed on their website.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#310?email_source=notifications&email_token=AAPJZBHMKFOSUZGJUPKC5Z3QYNSJ5A5CNFSM4FEXHRKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGZUEKQ#issuecomment-565396010>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAPJZBBVFTPCHGLUNT6N5G3QYNSJ5ANCNFSM4FEXHRKA>
.
|
@wafflespeanut any plans on OpenApi 3.0? |
This is far from perfect, but it works! - This is version Swagger 2.0 (current is OpenAPI 3.0) - Paperclip dev says they would work on v3.0 for next release actix/actix-web#310 (comment) - It doesn't seem to show descriptions of API operations (sigh), but it does show descriptions of *some* output schema fields. - It even lists possible error codes and descriptions, but doesn't mention schema of the error response (undestandably). - No Swagger UI is exposed, but there is an open MR for that in Paperclip: paperclip-rs/paperclip#174 - `language` enum varians are nicely listed and correctly lowercased. Given that Paperclip says it is WIP, this seems rather fine. They also claim (about the actix support) that *While it's not feature complete, you can rely on it to not break your actix-web flow.* And diff of this commit confirms that, is is basically just addition of some derives, attributes and wrappers.
It was add on https://github.com/paperclip-rs/paperclip: CHANGELOG |
A new crate emerged recently, which I found a really nice alternative when you are only looking for openapi generation: https://github.com/juhaku/utoipa |
This is what I've wanted. |
I think it's safe to close this issue now that we have several projects that can easily generate API docs for actix. |
Maybe most suited ones should be added to the actix docs as a pointer? |
I've found Apidog highly effective for document generation. Check out their tutorial for detailed guidance: [How to Generate API Documentation Using Apidog] |
This comment has been minimized.
This comment has been minimized.
https://github.com/kurtbuilds/oasgen It could be very nice to implement something like this into the actix framework itself |
I would also checkout Salvo as inspiration (https://salvo.rs/book/middlewares/openapi.html), the API docs are automatic, including all the return types. It allows you to use Swagger TypeScript/Dart auto-api generator for front-end projects. Something that is not possible with this project without clunky manual Documentation adders like Apidog and Utopia (which result in human error) |
I'm using
actix-web
to build a RESTful API in Rust, accepting various Json payloads on multiple routes and methods, etc.It would be incredibly awesome if actix was able to generate documentation for these endpoints, possibly with some template that's used to generate html.
There are a few ways this could be implemented, but I'm opening this issue first mostly to see if there is interest in such a feature from the core developers.
The text was updated successfully, but these errors were encountered: