Skip to content

fix(typescript-fetch): generate validationAttributes when withoutRuntimeChecks=true#23107

Merged
macjohnny merged 2 commits intoOpenAPITools:masterfrom
gurkodil:fix/validation-attributes-with-without-runtime-checks
Mar 4, 2026
Merged

fix(typescript-fetch): generate validationAttributes when withoutRuntimeChecks=true#23107
macjohnny merged 2 commits intoOpenAPITools:masterfrom
gurkodil:fix/validation-attributes-with-without-runtime-checks

Conversation

@gurkodil
Copy link
Copy Markdown
Contributor

@gurkodil gurkodil commented Mar 3, 2026

Previously, setting validationAttributes=true had no effect when withoutRuntimeChecks=true was set. This commit fixes that by adding the validation attributes to the modelGenericInterfaces.mustache template (that is used when withoutRuntimeChecks is enabled)

  • Moves validationAttributes logic to a partial template and includes it
    in the modelGenericInterfaces.mustache template
  • modelGeneric.mustache includes the modelGenericInterfaces.mustache
    partial and should work as before

cc: @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) @dennisameling (2026/02)

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.

Summary by cubic

Generate validationAttributes for typescript-fetch models when withoutRuntimeChecks=true. Restores validation metadata in interface-only builds while keeping default builds unchanged.

  • Bug Fixes
    • Moved validationAttributes to a new partial and included it from modelGenericInterfaces.mustache (default model builds still pick it up via existing includes).
    • Added a test that verifies PetPropertyValidationAttributesMap is generated in withoutRuntimeChecks builds.
    • Updated petstore samples.

Written for commit 0bf54dd. Summary will update on new commits.

@gurkodil gurkodil marked this pull request as ready for review March 3, 2026 21:31
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 10 files

gurkodil added 2 commits March 3, 2026 22:58
…imeChecks=true

Previously, setting `validationAttributes=true` had no effect when
`withoutRuntimeChecks=true` was set. This commit fixes that by adding
the validation attributes to the `modelGenericInterfaces.mustache`
template (that is used when withoutRuntimeChecks is enabled)

- Moves validationAttributes logic to a partial template and includes it
  in the modelGenericInterfaces.mustache template
- modelGeneric.mustache includes the modelGenericInterfaces.mustache
  partial and should work as before
@gurkodil gurkodil force-pushed the fix/validation-attributes-with-without-runtime-checks branch from 07b1502 to 0bf54dd Compare March 3, 2026 22:03
Copy link
Copy Markdown
Member

@macjohnny macjohnny left a comment

Choose a reason for hiding this comment

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

thanks for the fix!

}
{{#validationAttributes}}

export const {{classname}}PropertyValidationAttributesMap: {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this change backwards compatible? maybe people imported this map from this file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It should be backwards compatible, this template includes the modelGenericInterfaces.mustache (which renders this map) as a partial, so this map will still be rendered in this file.

@@ -0,0 +1,65 @@
{{#validationAttributes}}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

does this change require any import changes in any of the mustache files?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no it should be ok, since the map is included in the modelGeneric.mustache, anything that previously imported from this file still works as before. And for this partial itself it only uses primitive types so no additional imports are needed in the generated output when this is used

@macjohnny macjohnny merged commit 3972c65 into OpenAPITools:master Mar 4, 2026
15 checks passed
davidricodias pushed a commit to davidricodias/openapi-generator that referenced this pull request Mar 11, 2026
…imeChecks=true (OpenAPITools#23107)

* fix(typescript-fetch): generate validationAttributes when withoutRuntimeChecks=true

Previously, setting `validationAttributes=true` had no effect when
`withoutRuntimeChecks=true` was set. This commit fixes that by adding
the validation attributes to the `modelGenericInterfaces.mustache`
template (that is used when withoutRuntimeChecks is enabled)

- Moves validationAttributes logic to a partial template and includes it
  in the modelGenericInterfaces.mustache template
- modelGeneric.mustache includes the modelGenericInterfaces.mustache
  partial and should work as before

* update samples
@wing328 wing328 added this to the 7.21.0 milestone Mar 16, 2026
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