Skip to content

Commit d987aee

Browse files
k1rd3rfsmorimoto
andauthored
Fix modular template to always generate class property syntax (#1398)
* Add test that generates content for modular (based on 13.2.7) * format * Fix modular template to always generate class property syntax The modular template was incorrectly using object method syntax (`:` and `,`) when route.namespace was present, introduced by PR #1326. This caused TypeScript syntax errors in generated code. The modular template should always generate class properties with arrow functions (`=` and `;`), regardless of namespace presence. This resolves the issue reported in #1366 where version 13.2.8 generated invalid TypeScript code with modular templates. Signed-off-by: Sora Morimoto <[email protected]> --------- Signed-off-by: Sora Morimoto <[email protected]> Co-authored-by: Sora Morimoto <[email protected]>
1 parent 4d3193d commit d987aee

File tree

5 files changed

+1740
-2
lines changed

5 files changed

+1740
-2
lines changed

.changeset/short-emus-fly.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"swagger-typescript-api": patch
3+
---
4+
5+
Fix modular template to always generate class property syntax.
6+
7+
The modular template was incorrectly using object method syntax (`:` and
8+
`,`) when route.namespace was present, introduced by PR #1326. This
9+
caused TypeScript syntax errors in generated code.
10+
11+
The modular template should always generate class properties with arrow
12+
functions (`=` and `;`), regardless of namespace presence.
13+
14+
This resolves the issue reported in #1366 where version 13.2.8 generated
15+
invalid TypeScript code with modular templates.

templates/modular/procedure-call.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const isValidIdentifier = (name) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
9090
<%~ routeDocs.lines %>
9191

9292
*/
93-
<% if (isValidIdentifier(route.routeName.usage)) { %><%~ route.routeName.usage %><%~ route.namespace ? ': ' : ' = ' %><% } else { %>"<%~ route.routeName.usage %>"<%~ route.namespace ? ': ' : ' = ' %><% } %>(<%~ wrapperArgs %>)<%~ config.toJS ? `: ${describeReturnType()}` : "" %> =>
93+
<% if (isValidIdentifier(route.routeName.usage)) { %><%~ route.routeName.usage %><% } else { %>"<%~ route.routeName.usage %>"<% } %> = (<%~ wrapperArgs %>)<%~ config.toJS ? `: ${describeReturnType()}` : "" %> =>
9494
<%~ config.singleHttpClient ? 'this.http.request' : 'this.request' %><<%~ type %>, <%~ errorType %>>({
9595
path: `<%~ path %>`,
9696
method: '<%~ _.upperCase(method) %>',
@@ -100,4 +100,4 @@ const isValidIdentifier = (name) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
100100
<%~ bodyContentKindTmpl ? `type: ${bodyContentKindTmpl},` : '' %>
101101
<%~ responseFormatTmpl ? `format: ${responseFormatTmpl},` : '' %>
102102
...<%~ _.get(requestConfigParam, "name") %>,
103-
})<%~ route.namespace ? ',' : '' %>
103+
})

0 commit comments

Comments
 (0)