Skip to content

Conversation

@Levilutz
Copy link
Contributor

This PR contains the proposed solution to #22356 - introducing an optional useSerdePathToError config option for the Rust generator (defaulting to false) that adds the serde_path_to_error library for improving Serde error responses. The linked issue contains an example before / after error message.

Change breakdown:

  • Add a useSerdePathToError config option to the Rust generator
  • Add a conditional serde_path_to_error = "^0.1" dependency
  • Add a conditional SerdePathToError error type and all appropriate methods
  • Conditionally switch the main API response parse between serde_json::from_str and the appropriate serde_path_to_error equivalent
  • Add a new sample: samples/client/petstore/rust/reqwest/petstore-serde-path-to-error

Notably, I'm leaving the 4XX/5XX-path serde_json::from_str untouched. This path will include the both the received raw response body and (if parseable) the JSON response body. This should improve debug-ability sufficiently to not need this additional library.

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 WSL)
    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 solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@Levilutz
Copy link
Contributor Author

👋 @frol @farcaller @richardwhiuk @paladinzh @jacob-pro @dsteeley let me know if this looks good to you, any and all feedback would be appreciated 🙇

@wing328
Copy link
Member

wing328 commented Nov 15, 2025

thanks for the PR

This is a broad issue people have with the serde library, and thankfully there's an established library addressing this gap - serde_path_to_error.

if that's the case, shall we add this feature without the option to start with as it should benefit everyone using the auto-generated Rust SDK?

@Levilutz
Copy link
Contributor Author

thanks for the PR

This is a broad issue people have with the serde library, and thankfully there's an established library addressing this gap - serde_path_to_error.

if that's the case, shall we add this feature without the option to start with as it should benefit everyone using the auto-generated Rust SDK?

@wing328 Thanks for the quick response!

I was considering that as well. I'm erring on the conservative side for three reasons:

  • It's "one more dependency" that's not strictly necessary
  • It introduces another possible error signature - users may have their own custom handling for Serde errors, and not want a new SerdePathToError type that they have to add code to handle. This constitutes a breaking API change imo
  • The issue at serde-rs/json#173 has been open for ~9 years, indicating some reluctance to include this functionality in the Serde standard library as-is. While the reasons aren't clarified, I still want to take that as an indicator of something.

@wing328 wing328 added this to the 7.18.0 milestone Nov 16, 2025
@wing328 wing328 merged commit a52e902 into OpenAPITools:master Nov 16, 2025
17 checks passed
@wing328
Copy link
Member

wing328 commented Nov 16, 2025

looks good to me

let's give it a try

thanks for your contribution

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