[typescript-fetch] Fix Omit generic using baseName for readOnly fields

Merged
KA
5mo ago
+54-4

Fixes #23380

When generating the Omit<...> utility type for readOnly fields in models, the typescript-fetch generator incorrectly used baseName instead of name. This resulted in invalid TypeScript compiler errors when the model property naming strategy diverged from the raw OpenAPI property name (e.g. single_car in the spec vs singleCar in the generated interface).

This commit fixes modelGeneric.mustache to properly use the generated property name ({{name}}) instead of {{baseName}} for read-only fields, and adds test coverage to ensure the fix is maintained.

PR checklist

  • Read the contribution guidelines.
  • 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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
    @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04) @joscha (2024/10)

Summary by cubic

Fixes #23380. The typescript-fetch generator now uses generated property names in the Omit<...> for readOnly fields, preventing TypeScript errors when spec names differ from interface names.

  • Bug Fixes
    • Use {{name}} instead of {{baseName}} when building Omit<...> for read-only properties in modelGeneric.mustache.
    • Add a test (issue_23380.yaml) to verify camelCase names are used in Omit, and update petstore samples accordingly.