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] Adds UUID support from 'uuid' crate for better compile-time checks #12419

Closed
wants to merge 4 commits into from
Closed

[Rust] Adds UUID support from 'uuid' crate for better compile-time checks #12419

wants to merge 4 commits into from

Conversation

taufik-rama
Copy link
Contributor

Hello 👋

I've some changes regarding Rust codegen.
Currently I uses UUID for one of the value, and I think it would be nice if we can get this functionality merged, since uuid crate support should already be pretty stable (it's already 1.0), and it provides better compile-time check than plain String value

I base this changes from my previous PR on #12409 since it fixes the bug on UUID handling, which is needed here

I don't have much experience on current Java/Mustache codebase 😅, so any review/feedback is appreciated

Before

// Single parameter
#[derive(Clone, Debug, Default)]
pub struct UsersDeleteParams {
    pub id: Option<String>,
    // ...
}

// Multi parameter
pub async fn users_delete(configuration: &configuration::Configuration, id: Option<&str> /* ... */ ) { /* ... */ }

After

// Single parameter
#[derive(Clone, Debug, Default)]
pub struct UsersDeleteParams {
    pub id: Option<Uuid>,
    // ...
}

// Multi parameter
pub async fn users_delete(configuration: &configuration::Configuration, id: Option<Uuid> /* ... */ ) { /* ... */ }

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 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    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*.
    For Windows users, please run the script in Git BASH.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request. @paladinzh

@wing328
Copy link
Member

wing328 commented Jul 9, 2022

@taufik-rama thanks for the PR. Can you please resolve the merge conflicts when you've time?

@taufik-rama
Copy link
Contributor Author

@wing328 how would I update the generated samples version?

It seems that I got 6.0.0-SNAPSHOT version when I tried to update the samples, which trips up the CI check which currently generates 6.1.0-SNAPSHOT version

diff --git a/samples/server/petstore/rust-server/output/no-example-v3/.openapi-generator/VERSION b/samples/server/petstore/rust-server/output/no-example-v3/.openapi-generator/VERSION
index 5f68295f..66672d4e 100644
--- a/samples/server/petstore/rust-server/output/no-example-v3/.openapi-generator/VERSION
+++ b/samples/server/petstore/rust-server/output/no-example-v3/.openapi-generator/VERSION
@@ -1 +1 @@
-6.0.0-SNAPSHOT
\ No newline at end of file
+6.1.0-SNAPSHOT
\ No newline at end of file

I generated the samples using

$ ./bin/generate-samples.sh bin/configs/rust-*

@wing328
Copy link
Member

wing328 commented Jul 13, 2022

@taufik-rama thanks for the PR. I don't think we need another option.

If the string type has the format "uuid", then we can do it in typeMappings: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java#L169

If you change that line to map UUID to uuid::Uuid, would that meet your requirement?

@taufik-rama
Copy link
Contributor Author

I've moved the PR to #12895 with that changes, seems to still be working fine for my usecase

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.

2 participants