[typescript-angular] Fix typescript model kebab-cased filenames #5085
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using "kebab-case" file names, the typescript-angular client generator would create model files with repeating dashes in the filenames, but the import statements would have single dashes. This was caused by the Inline Model Resolver naming the resolved models by concatenating the parent name to the child model name with an underscore separator; if the child model name had a leading underscore, this would cause a double underscore in the new model name. When this model name was converted to kebab case for the file name, each individual underscore was converted to a dash, resulting in a filename with repeated dashes.
To address, updated the
dashize
method in StringUtils to collapse multiple consecutive whitespace and/or underscores to a single dash. This shouldn't be a breaking change, but if need be the fix could easily be amended to make the collapsing part of the operation optional using a boolean parameter and an overloaded method call.Added test cases to the StringUtils unit tests, Angular Typescript client code gen tests, and Angular Typescript model tests. Ran all of the tests in the project using
mvn test
; no failures. There were no changes to the petstore APIs or templates. Built the project and verified using the YML and commandline arguments from #5073 (yml included at bottom of PR).Fixes #5073
PR checklist
./bin/
(or Windows batch scripts under.\bin\windows
) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the code or mustache templates for a language ({LANG}
) (e.g. php, ruby, python, etc).master
,4.3.x
,5.0.x
. Default:master
.@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @nicokoenig (2018/09) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11)
Verification
Sample YML for verification (make sure to set fileNaming to "kebab-case"):
Previous behavior would generate files
./models/foo-response.ts
and./models/foo-response--links.ts
. New behavior is to generate./models/foo-response-links.ts
(other file unchanged).