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] Split out request logic, implement form parameters #528

Merged
merged 3 commits into from
Jul 23, 2018

Conversation

euank
Copy link
Contributor

@euank euank commented Jul 10, 2018

PR checklist

cc @frol @farcaller @bjgill

Description of the PR

This PR contains two changes which I needed to make for a particular swagger client to work.

The first moves most request logic into a standalone file / method. This makes it much erasier to avoid variable conflicts since the Request.execute method doesn't have the generated params in its scope, and as such doesn't have to worry about conflicting with them.

I intend for .execute to behave identically to what we previously generated per operation.

I did, however, also implement form data while I was at it. That is included as a second separate commit, and I can file it separately if that's preferred.

Fixes #512, #525

@euank
Copy link
Contributor Author

euank commented Jul 10, 2018

CI failure is a network or mvn flake it looks like

@euank euank force-pushed the rust-split-out-request-making branch from 92c8dd4 to ea41745 Compare July 10, 2018 19:29
@wing328 wing328 modified the milestone: 3.1.1 Jul 12, 2018
@wing328 wing328 added this to the 3.1.2 milestone Jul 19, 2018
Copy link
Contributor

@bjgill bjgill left a comment

Choose a reason for hiding this comment

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

I really like what you've done - it makes the mustache templates a lot more readable. I might need to move rust-server over to use this pattern as well.

use serde;
use serde_json;

pub struct ApiKey {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these be pub(crate)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, updated, thanks!

@@ -0,0 +1,214 @@
use std::borrow::Cow;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to have multiple copies of this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, this was a rebase mess-up to have both here; this one's gone now.

pub fn returns_nothing(mut self, val: bool) -> Self {
self.no_return_type = val;
self
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We only ever call this with val=true. Do we need to have val?

parsed.map_err(|e| Error::from(e))
})
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I've not reviewed this in detail - I assume you've just copied the logic across.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More or less.

I did add minor error handling around uri parsing that was an unwrap before and restructured it a bit to make it read cleaner, but it's meant to be just a straight copy+paste.

Other than forms. I did add form parameters since those weren't present at all before.

This reduces the number of variables which are used in the generated
operations, thus fixing OpenAPITools#512.

This also fixed a TODO related to URI parsing errors.
Other than that, it is meant to be functionally identical.
Up until now, they just weren't there at all
@euank euank force-pushed the rust-split-out-request-making branch from ea445b6 to 546f510 Compare July 23, 2018 05:55
@wing328 wing328 merged commit 2e6bec7 into OpenAPITools:master Jul 23, 2018
@wing328
Copy link
Member

wing328 commented Jul 23, 2018

@euank thanks for the PR, which has been merged into master.

@bjgill thanks for reviewing the change.

@euank euank deleted the rust-split-out-request-making branch July 23, 2018 15:22
@euank euank restored the rust-split-out-request-making branch July 23, 2018 15:22
bcourtine added a commit to bcourtine/openapi-generator that referenced this pull request Oct 17, 2018
bjgill pushed a commit that referenced this pull request Oct 26, 2018
* Port of PR swagger-api/swagger-codegen#8804.

* Correction of conflict with PR #528 (missing template file).

* Add rust-reqwest samples to Circle CI tests.

* Add integration test pom.xml file with launcher to trigger cargo execution.

* Deduplicate Maven project name.

* Fix "api_key" header for Petstore.

* Better API key management.

* Fix query param for lists of objects other than strings (numbers, etc.).

* Update to reqwest 0.9, and refactor of header management (using reqwest transition feature).

* Merge scripts generating rust-hyper and rust-reqwest samples.

* Consistent full stops.

* Use raw variables in all Rust mustache templates.

* Replace production build in CI with a quick simple check.

* Update samples.

* Finish Reqwest 0.9 migration (removing "hyper 0.11" transition feature).

* Configuration implements Default trait.

* API template reorganized: HashMap is not required anymore.

* Revert "Merge scripts generating rust-hyper and rust-reqwest samples."

This reverts commit 970f996.

* Remove deprecated "-XX:MaxPermSize" java arg.
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
…ls#528)

* [Rust] Move request logic into standalone file

This reduces the number of variables which are used in the generated
operations, thus fixing OpenAPITools#512.

This also fixed a TODO related to URI parsing errors.
Other than that, it is meant to be functionally identical.

* [Rust] Add support for non-file form params

Up until now, they just weren't there at all

* [Rust] Use more rustic terms in example
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
…1258)

* Port of PR swagger-api/swagger-codegen#8804.

* Correction of conflict with PR OpenAPITools#528 (missing template file).

* Add rust-reqwest samples to Circle CI tests.

* Add integration test pom.xml file with launcher to trigger cargo execution.

* Deduplicate Maven project name.

* Fix "api_key" header for Petstore.

* Better API key management.

* Fix query param for lists of objects other than strings (numbers, etc.).

* Update to reqwest 0.9, and refactor of header management (using reqwest transition feature).

* Merge scripts generating rust-hyper and rust-reqwest samples.

* Consistent full stops.

* Use raw variables in all Rust mustache templates.

* Replace production build in CI with a quick simple check.

* Update samples.

* Finish Reqwest 0.9 migration (removing "hyper 0.11" transition feature).

* Configuration implements Default trait.

* API template reorganized: HashMap is not required anymore.

* Revert "Merge scripts generating rust-hyper and rust-reqwest samples."

This reverts commit 970f996.

* Remove deprecated "-XX:MaxPermSize" java arg.
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.

3 participants