Created by: NathanBaulch
I've noticed a lot of inconsistencies and redundancies whilst working on templates across the various languages. This PR uses regex search and replace (via sed
) to fix a lot of these minor linting issues. None of the changes here were made by hand and none of them produce any unexpected changes to the generated samples, so they're safe.
Remove redundant sections
Command:
find ./modules/openapi-generator/src/main/resources -type f -name '*.mustache' -print0 |\
xargs -0 sed -i -E 's~\{\{[^\w{](([^\Wfi]|f[^\Wn]|i[^\Ws])\w+)\}\}(\{\{\{?)(\.|\1)(\}\}\}?)\{\{/\1\}\}~\3\1\5~g'
Example:
{{#returnType}}{{{returnType}}}{{/returnType}}
->
{{{returnType}}}
Remove empty tags
Command:
find ./modules/openapi-generator/src/main/resources -type f -name '*.mustache' -print0 |\
xargs -0 sed -i -E -z 's~\{\{[^\w{](([^\Wri]|r[^\We]|i[^\Ws]|re[^Wq])\w+)\}\}([^{]*)(\{\{\{?)\1(\}\}\}?)([^{]*)\{\{/\1\}\}~{{#\1}}\3\4.\5\6{{/\1}}~g'
Example:
{{^required}}{{/required}}
->
Use dot notation where possible
Command:
find ./modules/openapi-generator/src/main/resources -type f -name '*.mustache' -print0 |\
xargs -0 sed -i -E 's~\{\{[#^](\w+)\}\}\{\{/\1\}\}~~g'
Example:
{{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
->
{{#infoEmail}}Contact: {{{.}}}{{/infoEmail}}
Reorder tags that handle missing values
Command:
find ./modules/openapi-generator/src/main/resources -type f -name '*.mustache' -print0 |\
xargs -0 sed -i -E 's~(\{\{\^(([^\Wb]|b[^\Wa])\w+)\}\}.*\{\{/\2\}\})(\{\{\2\}\})~\4\1~g'
Example:
{{^description}}Gets or Sets {{{name}}}{{/description}}{{description}}
->
{{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
Trim trailing whitespace and extra EOF new lines
Self explanatory.
As with all linting efforts, these cosmetic changes improve code quality but at the cost of potential conflicts in unmerged code.
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 ./bin/generate-samples.sh ./bin/utils/export_docs_generators.sh
-
File the PR against the correct branch: master
,5.3.x
,6.0.x
-
If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.