Skip to content

feat: [rust] Dynamically add uuid crate only if used#20619

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
ranger-ross:optional-uuid
Feb 10, 2025
Merged

feat: [rust] Dynamically add uuid crate only if used#20619
wing328 merged 1 commit into
OpenAPITools:masterfrom
ranger-ross:optional-uuid

Conversation

@ranger-ross

Copy link
Copy Markdown
Contributor

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.toml if a UUID is found.

The motivation for this is to reduce un-needed dependencies and improve compile times.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in Git BASH)
    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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

cc: @frol @farcaller @richardwhiuk @paladinzh @jacob-pro

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I think it's unnecessarily verbose :) hasUUIDs communicates the intent better,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, just changed it and re-pushed. 👍

serde_json = "^1.0"
serde_repr = "^0.1"
url = "^2.5"
uuid = { version = "^1.8", features = ["serde", "v4"] }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we'd want a sample where the condition procs true too, then? To make sure the code paths are correct.

@ranger-ross ranger-ross Feb 8, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ranger-ross ranger-ross force-pushed the optional-uuid branch 2 times, most recently from 4036d39 to 40f7ae6 Compare February 8, 2025 10:23
CodegenModel m = map.getModel();
if (m.getIsUuid() || hasUuidInProperties(m.vars)) {
hasUUIDs = true;
LOGGER.info("found UUID in model: " + m.name);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we change this to LOGGER.debug instead?

return objs;
}

private boolean hasUuidInProperties(List<CodegenProperty> properties) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor suggestion: add a docstring explaining what this function does

@wing328 wing328 merged commit 79f70dc into OpenAPITools:master Feb 10, 2025
@ranger-ross ranger-ross deleted the optional-uuid branch February 10, 2025 03:19
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