Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Discussion about implementation #3

Open
sergeysova opened this issue Mar 22, 2020 · 1 comment
Open

Discussion about implementation #3

sergeysova opened this issue Mar 22, 2020 · 1 comment
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@sergeysova
Copy link
Member

sergeysova commented Mar 22, 2020

https://t.me/rustlang_ru/285259 https://teleg.one/rustlang_ru/285259 (Russian)

Translated:
made a sufficient version of the code generator for actix_swagger.
Generates this: https://github.com/sergeysova/actix-swagger/blob/master/cargo-swagg/out.rs.

In principle, it's enough to write applications, I have about this kind of communication. But there is no execution of the contract of request handlers here. There is no obligation to correctly process the request body in the handler. I could not find a way to do it through actix_web::dev::Factory.

Here is a discussion issue: actix/actix-web#1339.

By actix-swagger:
I will now write a conversion of yaml structures to the code generator format. Most likely there will be a HashMap/BTreeMap bundle to correctly resolve links. The first implementation will be very stupid and will be able to work only with links in requestBody, params and so on. There will also be no support for importing from files.

What do you need help with?

  • Have a look at the code. Almost everything is written there to get the first working version.
  • It would be cool to throw tests on the code generator (called printer). I think trivial inline snapshots would be enough. Give different configuration options to input and get sane code.
  • Convert your personal openapi3 snapshots into cargo-swagg structures and see if it's enough to have or need something else. If you need something else, create an issue/pr with implementation.

Project goals:
To input the openapi3 specification, to get the generated code at the output that does not need to be corrected by hand. At the same time, you may commit it into the repo and watch changes in the guitar after manual re-generation. You can take it to a separate crate, re-generate it into ci and deploy the crate of the new version. Update it in the project when it is convenient.

How to use:

We have to figure this out:

how to get the request handler to execute the contract on the request body, query, and headers.

I was thinking of making my analogue actix_web::dev::Factory, the so-called BoundFactory. Which would prescribe the implementation for Fn. BoundFactory is a trait that requires a function to have several mandatory parameters for specific types.

In this way, handlers could have the first arguments of clear types, such as request_body: request_bodies::Example, query: session_create::Query, and the rest of the arguments would be derived types, so you can pull out the necessary things, such as actix_web::web::Data.

But I'm relying on the privacy of Handler - actix/actix-web#1339.

I did not understand how to implement BoundFactory or even achieve the goal through Handle trait (actix/actix-web#1275).

I'd be so grateful for any help.

@sergeysova sergeysova added help wanted Extra attention is needed question Further information is requested labels Mar 22, 2020
@sergeysova sergeysova pinned this issue Mar 22, 2020
@fafhrd91
Copy link

fafhrd91 commented Mar 23, 2020

Just a note, you can bypass whole extractor/handler subsystem with https://github.com/actix/actix-web/blob/master/src/web.rs#L271

and WebService is just wrapper for Service
https://github.com/actix/actix-web/blob/master/src/service.rs#L424

you can use any T as service, it just needs to implement

Service<Config = (), Request = ServiceRequest, Response = ServiceResponse, Error = Error>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants