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 Client] several small fixes to code generation errors #8845

Merged
merged 8 commits into from
Mar 15, 2021

Conversation

ahl
Copy link
Contributor

@ahl ahl commented Feb 26, 2021

This fixes a few rust code generation issues. I've included links to small test cases.

  • compile errors incorrectly referencing types e.g. crate::models::crate::models::...
  • compile errors on types named File
  • compile errors on cyclic types
  • compile warnings on incorrectly named enum values

Closes #8380

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.
  • File the PR against the correct branch: master, 5.1.x, 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request. (hi @frol @farcaller @richardwhiuk @paladinzh)

ahl added a commit to ahl/openapi-tests that referenced this pull request Feb 26, 2021
@ahl
Copy link
Contributor Author

ahl commented Feb 26, 2021

@antifuchs
Copy link

This PR does get much further than the latest release in generating the client that I'm interested in (docspell's). Generating from the linked .yml file results in these cargo check errors:

    Checking openapi v1.0.0 (/Users/asf/Hacks/docspell-api-client/docspell-openapi)
error: named argument never used
   --> src/apis/item_multi_edit_api.rs:366:103
    |
366 |     let local_var_uri_str = format!("{}/sec/items/customfieldremove", configuration.base_path, itemId=crate::apis::urlencode(item_id));
    |                                     -------------------------------- formatting specifier missing     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ named argument never used

error[E0412]: cannot find type `ItemUploadMeta` in module `crate::models`
   --> src/apis/integration_endpoint_api.rs:106:128
    |
106 | ...ation, id: &str, meta: Option<crate::models::ItemUploadMeta>, file: Option<Vec<std::path::PathBuf>>) -> Result<crate::models::BasicRes...
    |                                                 ^^^^^^^^^^^^^^ not found in `crate::models`

error[E0412]: cannot find type `OneOfReferenceListOrganizationList` in module `crate::models`
  --> src/apis/organization_api.rs:55:143
   |
55 | ...on<&str>) -> Result<crate::models::OneOfReferenceListOrganizationList, Error<SecOrganizationGetError>> {
   |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `crate::models`

error[E0412]: cannot find type `OneOfReferenceListPersonList` in module `crate::models`
  --> src/apis/person_api.rs:55:137
   |
55 | ...ption<&str>) -> Result<crate::models::OneOfReferenceListPersonList, Error<SecPersonGetError>> {
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `crate::models`

error[E0412]: cannot find type `ItemUploadMeta` in module `crate::models`
  --> src/apis/upload_api.rs:89:123
   |
89 | ...ation, id: &str, meta: Option<crate::models::ItemUploadMeta>, file: Option<Vec<std::path::PathBuf>>) -> Result<crate::models::BasicRes...
   |                                                 ^^^^^^^^^^^^^^ not found in `crate::models`

error[E0412]: cannot find type `ItemUploadMeta` in module `crate::models`
   --> src/apis/upload_api.rs:122:146
    |
122 | ..., item_id: &str, meta: Option<crate::models::ItemUploadMeta>, file: Option<Vec<std::path::PathBuf>>) -> Result<crate::models::BasicRes...
    |                                                 ^^^^^^^^^^^^^^ not found in `crate::models`

error[E0412]: cannot find type `ItemUploadMeta` in module `crate::models`
   --> src/apis/upload_api.rs:190:127
    |
190 | ..., item_id: &str, meta: Option<crate::models::ItemUploadMeta>, file: Option<Vec<std::path::PathBuf>>) -> Result<crate::models::BasicRes...
    |                                                 ^^^^^^^^^^^^^^ not found in `crate::models`

error[E0412]: cannot find type `ItemUploadMeta` in module `crate::models`
   --> src/apis/upload_api.rs:231:109
    |
231 | ...::Configuration, meta: Option<crate::models::ItemUploadMeta>, file: Option<Vec<std::path::PathBuf>>) -> Result<crate::models::BasicRes...
    |                                                 ^^^^^^^^^^^^^^ not found in `crate::models`

error[E0283]: type annotations needed
    --> src/apis/organization_api.rs:87:9
     |
87   |         serde_json::from_str(&local_var_content).map_err(Error::from)
     |         ^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the function `from_str`
     |
    ::: /Users/asf/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_json-1.0.63/src/de.rs:2584:8
     |
2584 |     T: de::Deserialize<'a>,
     |        ------------------- required by this bound in `serde_json::from_str`
     |
     = note: cannot satisfy `_: Deserialize<'_>`
help: consider specifying the type arguments in the method call
     |
87   |         serde_json::from_str(&local_var_content).map_err::<F, O>(Error::from)
     |                                                         ^^^^^^^^
help: consider specifying the type arguments in the function call
     |
87   |         serde_json::from_str::<'a, T>(&local_var_content).map_err(Error::from)
     |                             ^^^^^^^^^

error[E0283]: type annotations needed
    --> src/apis/person_api.rs:87:9
     |
87   |         serde_json::from_str(&local_var_content).map_err(Error::from)
     |         ^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the function `from_str`
     |
    ::: /Users/asf/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_json-1.0.63/src/de.rs:2584:8
     |
2584 |     T: de::Deserialize<'a>,
     |        ------------------- required by this bound in `serde_json::from_str`
     |
     = note: cannot satisfy `_: Deserialize<'_>`
help: consider specifying the type arguments in the method call
     |
87   |         serde_json::from_str(&local_var_content).map_err::<F, O>(Error::from)
     |                                                         ^^^^^^^^
help: consider specifying the type arguments in the function call
     |
87   |         serde_json::from_str::<'a, T>(&local_var_content).map_err(Error::from)
     |                             ^^^^^^^^^

@wing328 wing328 added this to the 5.1.0 milestone Mar 3, 2021
@wing328
Copy link
Member

wing328 commented Mar 3, 2021

cc @frol (2017/07) @farcaller (2017/08) @richardwhiuk (2019/07) @paladinzh (2020/05)

@ahl
Copy link
Contributor Author

ahl commented Mar 11, 2021

Hey @wing328 -- how can I help to move this forward? Thanks.

@wing328
Copy link
Member

wing328 commented Mar 12, 2021

@ahl did you see the issues reported by @antifuchs when he tried your PR/fix? Are you able to reproduce those locally?

@ahl
Copy link
Contributor Author

ahl commented Mar 12, 2021

@ahl did you see the issues reported by @antifuchs when he tried your PR/fix? Are you able to reproduce those locally?

Yes, he said "This PR does get much further than the latest release in generating the client that I'm interested in..." i.e. that it's a significant improvement over the latest version.

The Rust generator struggles with quite a few constructions--too many for me to fix in this PR. With over 2k open issues, it's a little hard to understand what's filed or not, but from the output @antifuchs posted I recognize several issues that exist independent of this PR:

  • the ItemUploadMeta error is due to incorrect handling of multipart/form-data
  • no support for oneOf schemas (hence the several
  • general sloppiness and poor test coverage

@wing328
Copy link
Member

wing328 commented Mar 12, 2021

Yes, he said "This PR does get much further than the latest release in generating the client that I'm interested in..." i.e. that it's a significant improvement over the latest version.

Totally agree on that. My question is wondering if you've looked into the issue he reported and the finding, and it's perfectly fine to have another PR to fix those instead of squeezing all the fixes into one giant PR.

no support for oneOf schemas (hence the several

We are definitely looking for contributors to help on that as we've already come up with the implementation in some other generators (java, csharp, go, python, and more). We can use these as the reference implementations to start with.

I'll take another look over the weekend and merge if no further feeddback/question from me.

Thanks again for the PR. Have a nice weekend.

@ahl
Copy link
Contributor Author

ahl commented Mar 12, 2021

Thanks, William. Yes I was able to reproduce those. I have some ideas about how to fix them, but this code feels quite fragile. I'm unsure about test coverage and wouldn't be confident that a fix in one place wouldn't regress another. In this PR I tried to stick to some pretty clear wins like resolving a fundamental issue with circular types.

// TODO: deleting the variable from the array was
// problematic; I don't know what this is supposed to do
// so I'm just cloning it for the moment
List<CodegenProperty> vars = new ArrayList<>(model.getVars());
Copy link
Member

Choose a reason for hiding this comment

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

@ahl when you've time, can you please elaborate on the problem ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, sorry to leave that turd. This code section seems to be handling discriminators and relocates a particular variable into the discriminators variables. It previously did so destructively which caused the original variable to be absent.

This is definitely ugly and poorly structured, but I don't have a good sense of how it should be structured or how to properly and exhaustively test some of the subtle semantics here.

Copy link
Member

Choose a reason for hiding this comment

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

No worries bro. Do you have a spec that can reproduce the issue that you encountered with this line/section of code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was running the influxdb openapi spec through it: https://docs.influxdata.com/influxdb/v2.0/api/

Copy link
Member

Choose a reason for hiding this comment

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

OK. Will take a look when I can find the time later.

@wing328 wing328 merged commit 15c3bf4 into OpenAPITools:master Mar 15, 2021
@wing328
Copy link
Member

wing328 commented Mar 16, 2021

@antifuchs I wonder if you can open an issue with the details to track the problem you reported above. Thanks.

@wing328
Copy link
Member

wing328 commented Mar 22, 2021

@thanks for the PR, which has been included in the v5.1.0 release: https://twitter.com/oas_generator/status/1373636654024380423

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.

[BUG][Rust Client] Duplicated crate::models in Params struct
4 participants