-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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-Axum] Fix uuid in header params causing compilation errors #18563
Conversation
thanks for the PR. cc @linxGnu |
@@ -552,6 +553,12 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation | |||
} | |||
} | |||
|
|||
// Include renderUuidConversionImpl exactly once in the vendorExtensions map when | |||
// at least one `uuid::Uuid` converted from a header value in the resulting Rust code. | |||
Boolean renderUuidConversionImpl = op.headerParams.stream().anyMatch(h -> h.getDataType().equals(uuidType)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change it to
final Boolean renderUuidConversionImpl
Using final
whenever possible is a best/good practice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the hint!
@@ -178,3 +178,39 @@ impl TryFrom<IntoHeaderValue<DateTime<Utc>>> for HeaderValue { | |||
} | |||
} | |||
} | |||
|
|||
{{#renderUuidConversionImpl}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please run integration test.
./bin/generate-samples.sh ./bin/configs/manual/*.yaml
mvn integration-test -f samples/server/petstore/rust-axum/pom.xml
You might need to create new api with uuid in the header if those specs do not have
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, done that. Should have done it in the first place.
Thank you very much for having reviewed the PR so far. I have made the changes you described and hope to not have made any mistakes. |
Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors. Let me know if you need help fixing it. |
Routes with header parameters with a `format` of `uuid` in the openAPI specification used to cause a compilation error in the resulting Rust Axum code. This commit fixes the issue by including the correct conversion trait implementation on the condition that at least one header parameter of `format` `uuid` is included in the specification.
The trait needs to be in scope for the TryFrom implementation: `TryFrom<HeaderValue> for IntoHeaderValue<uuid::Uuid> ` It will only be brought into scope when the implementation is rendered.
b197ad1
to
71c367a
Compare
Sorry for causing so much work with this PR. Now I have rebased the history so that the e-mail aligns with my GitHub account. I will change the integration test for this change because the same bug I have fixed for the rust-axum generator exists for the rust-server generator also. So I will create a new test that is only run during the integration test of the rust-axum generator. Then in an another PR, if I have the time, I will fix the same bug in the rust-server generator. |
No problem. We appreciate your contributions to the Rust generators. |
This commit adds an integration test that tests the bug fix for OpenAPITools#18554. A header parameter of `format: uuid` is included in one route. This makes the example create a route handler that tries to extract a Rust `uuid::Uuid` type from the header. The integration test will check that the generated code compiles.
The generated samples are updated with: `./bin/generate-samples.sh ./bin/configs/manual/*.yaml` Most example projects have their version numbers bumped. Some changes show, that there are some other unrelated changes to the files, which indicates that some prior commit did not update the samples accordingly. The relevant integration test `mvn integration-test -f samples/server/petstore/rust-axum/pom.xml` passes.
71c367a
to
a8e06cd
Compare
I found time to add a clean integration test for the changes to the rust-axum generator. The relevant samples are updated and the relevant integration test passes. |
the build failure doesn't seem to be related to this PR, right? |
Yes this is an unrelated error. I can try to tackle this together with #18572 |
I created a PR that should resolve the problem of the failing test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Please also trying to use latest uuid crate.
@myz-dev both of your PR, please ensure that you pass Integration Test. It's critical to verify. |
Hi. The template includes (in Cargo.mustache): [[package]]
name = "uuid"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0"
dependencies = [
"serde",
] With If I did not misunderstand your comment, the latest version of |
Sorry can you please explain what test does not pass? When I run
|
Then LGTM |
…nAPITools#18563) * fix: Fix uuid in header params causing errors Routes with header parameters with a `format` of `uuid` in the openAPI specification used to cause a compilation error in the resulting Rust Axum code. This commit fixes the issue by including the correct conversion trait implementation on the condition that at least one header parameter of `format` `uuid` is included in the specification. * refactor: Add final to boolean * fix: Bring str::FromStr optionally into scope The trait needs to be in scope for the TryFrom implementation: `TryFrom<HeaderValue> for IntoHeaderValue<uuid::Uuid> ` It will only be brought into scope when the implementation is rendered. * test: Add integration test and its specification This commit adds an integration test that tests the bug fix for OpenAPITools#18554. A header parameter of `format: uuid` is included in one route. This makes the example create a route handler that tries to extract a Rust `uuid::Uuid` type from the header. The integration test will check that the generated code compiles. * test: Update examples and run integration test The generated samples are updated with: `./bin/generate-samples.sh ./bin/configs/manual/*.yaml` Most example projects have their version numbers bumped. Some changes show, that there are some other unrelated changes to the files, which indicates that some prior commit did not update the samples accordingly. The relevant integration test `mvn integration-test -f samples/server/petstore/rust-axum/pom.xml` passes.
Routes with header parameters with a
format
ofuuid
in the openAPI specification used to cause a compilation error in the resulting Rust Axum code.This commit fixes the issue by including the correct conversion trait implementation on the condition that at least one header parameter of
format
uuid
is included in the specification.Problem details: #18554
How to validate:
The faulty behavior can be reproduced like this:
On the current master branch generate a Rust axum library with the specification described in #18554 .
Then (when you have installed
rustc
andcargo
, runcargo check
in the rust workspace containing the generated library. You will get compile errors in the places where theuuid
is extracted from the request headers.To verify the fix do the same with the code changes contained in this pull request.
Now cargo check will not report any compilation errors. Note the change in the
src/header.rs
file. A few lines have been added to it.PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming 7.1.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)@frol @farcaller @richardwhiuk @paladinzh @jacob-pro