-
-
Notifications
You must be signed in to change notification settings - Fork 170
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
fix: rust compile errors #869
fix: rust compile errors #869
Conversation
The normal toPascalCase method separates number e.g. `abc_123` is converted to `Abc_123`. This causes compile warnings in Rust. The new method converts it to `Abc123`.
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.
Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.
👋 Hey @YushiOMOTE, thank you for the contributions! Would you feel comfortable adding tests to demonstrate how the code breaks, and verify your fixes? Feel free to ping me if you're having trouble getting the tests (unit or black-box) running locally. An excellent first step would be to add a test for Can you share a schema with example data structures? That will make it easier to grok the behavior you're describing. Thanks! The Regarding imports, the decision to render unit types and use fully-qualified |
link against #847 for ref |
Thank you! Yes let me add tests. I cannot share the exact schema as it’s closed, but probably can share example schemas that can reproduce the issues. |
51e1ca3
to
1ab80a6
Compare
There was mismatch of conditions for struct constructor and definition.
`modelName` contains `CargoToml` or `lib` instead of `Cargo.toml` and `lib.rs`. Fixed to use `model.name` that contains the actual file names.
The `type` field of union contains the type name with suffix number, which is non-existent type name. The actual name is stored in `ref` side.
Follow the actual Rust spec to generate PartialEq, PartialOrd, Eq, Ord derives.
1ab80a6
to
301cb29
Compare
@@ -50,7 +50,7 @@ impl Address { | |||
exports[`Should be able to render Rust Models and should log expected output to console 2`] = ` | |||
Array [ | |||
"// Members represents a union of types: String, f64, bool | |||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] | |||
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)] |
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.
Expected as f64
supports PartialOrd
Updated/added tests.
I have changed to use fully-qualified syntax instead of importing.
I think the updated snapshots in this PR describes most of the issues I faced. Except for this one:
I'm trying to give the example swagger or add a test in PR to describe this case soon 👀 |
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] | ||
pub enum Things { | ||
pub enum Things123 { |
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.
Things_123
in schema is converted to Things123
now. Previously, it was Things_123
which caused compile warnings.
@@ -2,18 +2,18 @@ | |||
|
|||
exports[`RUST_COMMON_PRESET Enum should render \`enum\` of union type with Default implementation of integer type 1`] = ` | |||
"// Address represents a Address model. | |||
#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] |
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.
Ord
and PartialOrd
are removed now as HashMap
doesn't support those.
pub struct Address { | ||
#[serde(rename=\\"members\\")] | ||
members: Box<crate::Members>, | ||
members: crate::Members, |
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.
Expected. Since we take Members
in fn new
side without Box
, the definition should be just Members
as well.
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.
I think we should keep references to models as pointer-heap memory by default. If you need the entire data structure to be loaded into stack memory, I think a preset would be the right mechanism for that behavior.
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.
Got it! I fixed to use Box
for reference. Now the constructor side is fixed to use Box
: https://github.com/asyncapi/modelina/pull/869/files#diff-9f4739c9c2692512b77fc209d671487d26937caed76f432ff6adf62a343a3ebaR18
#[serde(rename=\\"optional_members\\", skip_serializing_if = \\"Option::is_none\\")] | ||
optional_members: Option<Box<crate::OptionalMembers>>, | ||
#[serde(rename=\\"additionalProperties\\", skip_serializing_if = \\"Option::is_none\\")] | ||
additional_properties: Option<std::collections::HashMap<String, String>>, | ||
} | ||
|
||
impl Address { | ||
pub fn new(members: Members, optional_members: Option<crate::OptionalMembers>, additional_properties: Option<std::collections::HashMap<String, String>>) -> Address { | ||
pub fn new(members: crate::Members, optional_members: Option<crate::OptionalMembers>, additional_properties: Option<std::collections::HashMap<String, String>>) -> Address { |
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.
crate::
is needed as Members
and Address
are defined in separate files when we use RustFileGenerator
Kudos, SonarCloud Quality Gate passed!
|
This spec generates the issue with union. |
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub enum ReservedUnion { | ||
#[serde(rename=\\"Student0\\")] | ||
Student0(crate::Student), |
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.
This snapshot is for the issue fixed by this revision
Before the fix, the line became Student0(crate::Student0)
, which caused compile error.
Sorry for the delay in responding! Thank you for sticking with this PR @YushiOMOTE 🙇♀️ The failing black-box tests are related to #847 , so don't worry about those. Linter caught a couple of nits: |
Cant wait for this to be merged 😄 Just encountered the same issues 👍 |
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.
👋 I'd love to merge this @YushiOMOTE, just a few suggestions to pass the linter (added in review).
Co-authored-by: Leigh Johnson <hi@leighjohnson.me>
Co-authored-by: Leigh Johnson <hi@leighjohnson.me>
Co-authored-by: Leigh Johnson <hi@leighjohnson.me>
Co-authored-by: Leigh Johnson <hi@leighjohnson.me>
Co-authored-by: Leigh Johnson <hi@leighjohnson.me>
Co-authored-by: Leigh Johnson <hi@leighjohnson.me>
Co-authored-by: Leigh Johnson <hi@leighjohnson.me>
Co-authored-by: Leigh Johnson <hi@leighjohnson.me>
Co-authored-by: Leigh Johnson <hi@leighjohnson.me>
Kudos, SonarCloud Quality Gate passed!
|
Co-authored-by: Leigh Johnson <hi@leighjohnson.me>
Kudos, SonarCloud Quality Gate passed!
|
Kudos, SonarCloud Quality Gate passed!
|
@YushiOMOTE Looks like the last thing left is to update this snapshot 🎉 👏 |
@YushiOMOTE Just a heads up, I'm going to merge this PR into a new branch, |
@all-contributors |
I've put up a pull request to add @YushiOMOTE! 🎉 I've put up a pull request to add @leigh-johnson! 🎉 |
Description
Locally tried Rust generator with more complicated private examples and got some compile errors in the generate Rust crate.
The PR makes compile pass fixing the following issues:
Abc_123
)crate::
in some cases