feat: [rust] Dynamically add uuid crate only if used#20619
Merged
Conversation
farcaller
reviewed
Feb 8, 2025
| protected String modelFolder = "src/models"; | ||
| // The API has at least one UUID type. | ||
| // If the API does not contain any UUIDs we do not need depend on the `uuid` crate | ||
| private boolean hasAtLeastOneUuid = false; |
Contributor
There was a problem hiding this comment.
nit: I think it's unnecessarily verbose :) hasUUIDs communicates the intent better,
Contributor
Author
There was a problem hiding this comment.
sure, just changed it and re-pushed. 👍
farcaller
reviewed
Feb 8, 2025
| serde_json = "^1.0" | ||
| serde_repr = "^0.1" | ||
| url = "^2.5" | ||
| uuid = { version = "^1.8", features = ["serde", "v4"] } |
Contributor
There was a problem hiding this comment.
I think we'd want a sample where the condition procs true too, then? To make sure the code paths are correct.
Contributor
Author
There was a problem hiding this comment.
yes, there are few in samples/client/petstore/rust/reqwest
farcaller
approved these changes
Feb 8, 2025
4036d39 to
40f7ae6
Compare
farcaller
approved these changes
Feb 8, 2025
wing328
reviewed
Feb 9, 2025
| CodegenModel m = map.getModel(); | ||
| if (m.getIsUuid() || hasUuidInProperties(m.vars)) { | ||
| hasUUIDs = true; | ||
| LOGGER.info("found UUID in model: " + m.name); |
Member
There was a problem hiding this comment.
can we change this to LOGGER.debug instead?
wing328
reviewed
Feb 9, 2025
| return objs; | ||
| } | ||
|
|
||
| private boolean hasUuidInProperties(List<CodegenProperty> properties) { |
Member
There was a problem hiding this comment.
minor suggestion: add a docstring explaining what this function does
40f7ae6 to
628cc97
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds logic to check if an API has at least one UUID type property and only add the uuid crate to the
Cargo.tomlif a UUID is found.The motivation for this is to reduce un-needed dependencies and improve compile times.
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(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)cc: @frol @farcaller @richardwhiuk @paladinzh @jacob-pro