Skip to content

Conversation

@andrzejressel
Copy link
Contributor

@andrzejressel andrzejressel commented Aug 3, 2025

This pull requests replace more instances of HeaderValue::from_str with HeaderValue::from_static.

@frol @farcaller @richardwhiuk @paladinzh @jacob-pro @dsteeley

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.

Copilot AI review requested due to automatic review settings August 3, 2025 16:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request replaces more instances of HeaderValue::from_str with HeaderValue::from_static for compile-time string values in Rust-generated code. This optimization removes unnecessary runtime string validation since the header values are known at compile time.

  • Replaces HeaderValue::from_str() with HeaderValue::from_static() for static header values
  • Updates Mustache templates to generate more efficient code
  • Includes minor import ordering improvements for consistency

Reviewed Changes

Copilot reviewed 53 out of 53 changed files in this pull request and generated no comments.

Show a summary per file
File Description
samples/server/petstore/rust-server/output/*/src/server/mod.rs Replace HeaderValue::from_str() calls with static variants for Content-Type headers
samples/server/petstore/rust-server/output/*/src/client/mod.rs Replace dynamic header creation with static variants for known media types
samples/server/petstore/rust-axum/output/*/src/server/mod.rs Replace HeaderValue::from_str() with static variants in Axum implementations
samples/server/petstore/rust-axum/output/*/src/types.rs Minor import ordering improvements for consistency
modules/openapi-generator/src/main/resources/rust-server/*.mustache Update Mustache templates to generate static header values

@dsteeley
Copy link
Contributor

dsteeley commented Aug 3, 2025

Thanks for submitting this. You've not mentioned why you've removed the error context on some of the responses. Could you explain that decision.
My understanding is that this is a breaking change to the response in some error scenarios.

@andrzejressel
Copy link
Contributor Author

andrzejressel commented Aug 3, 2025

Thanks for submitting this. You've not mentioned why you've removed the error context on some of the responses. Could you explain that decision. My understanding is that this is a breaking change to the response in some error scenarios.

Sure, error handling was there, because HeaderValue::from_str returns Result - after all, string to header conversion may fail. But from_static performs it in compile time - so the error will happen during compilation. From runtime point of view - value is already valid.

@andrzejressel andrzejressel changed the title [Rust] Replace more HeaderValue::from_str with compile time HeaderValue::from_static [Rust] Replace more HeaderValue::from_str with compile time from_static Aug 4, 2025
@wing328 wing328 added this to the 7.15.0 milestone Aug 5, 2025
@wing328
Copy link
Member

wing328 commented Aug 5, 2025

the change sounds reasonable to me

let's give it a try

@wing328 wing328 merged commit a7af767 into OpenAPITools:master Aug 5, 2025
20 checks passed
Goopher pushed a commit to Goopher/openapi-generator that referenced this pull request Sep 9, 2025
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