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

[Rust Server] Hyper 0.13 + Async/Await support #6244

Merged
merged 5 commits into from
May 29, 2020
Merged

[Rust Server] Hyper 0.13 + Async/Await support #6244

merged 5 commits into from
May 29, 2020

Conversation

richardwhiuk
Copy link
Contributor

  • Updated dependencies:
    • hyper 0.13 (from 0.12)
    • hyper-openssl 0.8 (from 0.7)
    • futures 0.3 (from 0.1)
    • swagger-rs 5 (from 4)
    • uuid 0.8 (from 0.7)
    • serde_ignored 0.1 (from 0.0.4)
    • url 2.1 (new)
    • serde_urlencoded 0.6 (from 0.5)
    • percent-encoding 2 (from 1)
    • regex 1 (from 0.2)
    • frunk-enum-derive 0.2 (from 0.1 internal)
    • frunk-enum-core 0.2 (from 0.1 internal)
  • Updated dev dependencies
    • error_chain removed
    • tokio 0.2 (from 0.1)
    • native-tls 0.2 (from 0.1)
    • tokio-tls 0.3 (from 0.1)
    • tokio-openssl 0.4 (from 0.3)
  • API changes
    • Addition of poll_ready to expose API busy-ness - this is optional.
    • Trait is now tagged with async_trait, and all methods are async.
  • Deprecation removals
    • No longer export swagger::ApiError, or futures::Future
  • Client changes:
    • Now parameterised by enclosing Service, rather than by the future it produces
    • ⚠️ Service must be Clone and Send and Sync.
  • Server Changes:
    • ⚠️ Context is now required to be Clone and Send and Sync.
    • MakeService and Service are now a tower::Services.
  • Middleware changes
    • MakeAddContext/AddContext now impl tower::Service
  • Server and Client are implemented using async/await.
    • Note, for Server, this is done by mirroring how async_trait works
    • Sadly tower::Service doesn't use async_trait, so this doesn't just fall out.
    • For client, both URL construction and Multipart construction is forced into a block to workaround limitations in Rust's escape analysis for futures.

This resolves #3865

Rust Server Technical Committee

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

Upgrade dependencies to Hyper 0.13 and use async/await.
@richardwhiuk
Copy link
Contributor Author

@dbcfd I know you've got a set of changes in #4210 which also resolves this - I'm going to take a look through the differences.

This MR should be ready to merge - whereas I think yours is WIP - correct?

futures = "0.1"
swagger = "4.0"
futures = "0.3"
swagger = "5.0.0-alpha-1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an alpha release, mainly because the Hyper 0.13 code here is so new. I'll cut a 5.0 release of swagger prior to 5.0 of OpenAPI Generator being released, and update this to match.

@dbcfd
Copy link

dbcfd commented May 10, 2020

It was ready to merge, but the recent changes to master would require significant additional work. Server is not required to be clone, think Context wasn't either, so might be useful to look at that.

You might also want to look at https://crates.io/crates/hyper-multipart-rfc7578 for multipart, to remove the hyper 0.10 and related dependencies.

@dbcfd
Copy link

dbcfd commented May 11, 2020

Generated cargo files aren't valid, due to examples not having path.

error: failed to parse manifest at `<path-to-generated>/Cargo.toml` Caused by: can't find `client` example, specify example.path

[edit] Existing generations needs to have examples/client and examples/server directory removed. Might be a note for upgrade.

[edit2] Actually seems like they are still getting generated, and thus the cargo generated is invalid.

@dbcfd
Copy link

dbcfd commented May 11, 2020

Withing server, hyper_tls is not found

error[E0433]: failed to resolve: use of undeclared type or module `hyper_tls`
   --> src\client\mod.rs:235:23
    |
235 | type HttpsConnector = hyper_tls::HttpsConnector<hyper::client::HttpConnector>;
    |                       ^^^^^^^^^ use of undeclared type or module `hyper_tls`

@richardwhiuk
Copy link
Contributor Author

@dbcfd I've fixed up the issue with hyper-tls - but I can't reproduce the issue you are seeing with the examples?

The examples are the standard multi-file examples described in https://doc.rust-lang.org/cargo/guide/project-layout.html

Should look like:

openapi-v3$ ls -R examples/
examples/:
ca.pem  client  server  server-chain.pem  server-key.pem

examples/client:
main.rs  server.rs

examples/server:
main.rs  server.rs

or for an API without callbacks:

rust-server-test$ ls -R examples/
examples/:
ca.pem  client  server  server-chain.pem  server-key.pem

examples/client:
main.rs

examples/server:
main.rs  server.rs

and the Cargo.toml snippet is standard as well:

[[example]]
name = "client"
required-features = ["client"]

[[example]]
name = "server"
required-features = ["server"]

as per https://doc.rust-lang.org/cargo/reference/cargo-targets.html#examples

@richardwhiuk richardwhiuk merged commit 82410ae into OpenAPITools:master May 29, 2020
@richardwhiuk richardwhiuk deleted the rust-server-hyper-0.13 branch May 29, 2020 14:18
jimschubert added a commit to jimschubert/openapi-generator that referenced this pull request May 30, 2020
* master:
  [PS] Refactor the http signing auth with ecdsa support (OpenAPITools#6397)
  [Rust Server] Hyper 0.13 + Async/Await support (OpenAPITools#6244)
  [Rust] set supportAsync to true as the default (OpenAPITools#6480)
  [php-symfony] Set required PHP version ^7.1.3 (OpenAPITools#6181)
  update doc
  [csharp] Rename netstandard to netstandard1.3 (OpenAPITools#6460)
  feat: support deprecated parameters for typescript-axios generator (OpenAPITools#6475)
  [REQ][typescript-axios] useSingleRequestParameter should mark parameter optional if all properties are optional (OpenAPITools#6477)
  better struct alias in rust (OpenAPITools#6470)
  Migrate Go server samples to OAS 3 only (OpenAPITools#6471)
  [Rust][reqwest] add async support (OpenAPITools#6464)
  [codegen][python-experimental] Composed schema with additionalProperties  (OpenAPITools#6290)
  [Java] Decommission Retrofit 1.x support (OpenAPITools#6447)
  remove scala oas3 samples (OpenAPITools#6446)
  [Java][jersey2] Fix RuntimeException when HTTP signature parameters are not configured (OpenAPITools#6457)
  [Java][jersey2] Improve http signature code comments (OpenAPITools#6463)
  [typescript-angular] drop support of angular below 6.0.0 (OpenAPITools#6360)
  [cli] new 'author template' command (OpenAPITools#6441)
  python-experimental updates ancestor + adds descendant discriminator tests (OpenAPITools#6417)
jimschubert added a commit that referenced this pull request May 30, 2020
* master: (36 commits)
  Improve handling spaces in example command (#6482)
  fix maven plugin snapshot version
  comment out erlang server test (#6499)
  Migrate Perl samples to use OAS v3 spec (#6490)
  [core] Refactor templating management (#6357)
  migrate apex samples to use oas3 spec (#6488)
  add new file in php-symfony sample
  [PS] Refactor the http signing auth with ecdsa support (#6397)
  [Rust Server] Hyper 0.13 + Async/Await support (#6244)
  [Rust] set supportAsync to true as the default (#6480)
  [php-symfony] Set required PHP version ^7.1.3 (#6181)
  update doc
  [csharp] Rename netstandard to netstandard1.3 (#6460)
  feat: support deprecated parameters for typescript-axios generator (#6475)
  [REQ][typescript-axios] useSingleRequestParameter should mark parameter optional if all properties are optional (#6477)
  better struct alias in rust (#6470)
  Migrate Go server samples to OAS 3 only (#6471)
  [Rust][reqwest] add async support (#6464)
  [codegen][python-experimental] Composed schema with additionalProperties  (#6290)
  [Java] Decommission Retrofit 1.x support (#6447)
  ...
@wing328 wing328 added this to the 5.0.0 milestone Jul 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REQ] Upgrade to tokio 0.2 and related async/await features
3 participants