From cc203a1eb18874add28ffd415849d63b4a5be023 Mon Sep 17 00:00:00 2001 From: sumeyye Date: Tue, 7 Jul 2026 08:55:39 +0300 Subject: [PATCH] update: template for generating only one form of get function --- .../__name@kebab__.service.ts.template | 44 +++++++++---------- .../proxy-service-template-render.spec.ts | 7 ++- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/npm/ng-packs/packages/schematics/src/commands/api/files-service/proxy/__namespace@dir__/__name@kebab__.service.ts.template b/npm/ng-packs/packages/schematics/src/commands/api/files-service/proxy/__namespace@dir__/__name@kebab__.service.ts.template index 97661ef3bc..aaa4220d9b 100644 --- a/npm/ng-packs/packages/schematics/src/commands/api/files-service/proxy/__namespace@dir__/__name@kebab__.service.ts.template +++ b/npm/ng-packs/packages/schematics/src/commands/api/files-service/proxy/__namespace@dir__/__name@kebab__.service.ts.template @@ -20,28 +20,8 @@ export class <%= name %>Service { const resourceArgs = resourceParameters.map(p => `params.${p.name}`).join(', '); %> - <%= camel(signature.name) %> = (<%= serializeParameters(signature.parameters) %>) => - this.restService.request<<%= body.requestType %>, <%= responseType %>>({ - method: '<%= body.method %>',<% - if (httpResponseType && httpResponseType !== 'json') { %> - responseType: '<%= httpResponseType %>',<% } %><% - if (acceptHeader) { %> - headers: { Accept: '<%= acceptHeader %>' },<% } %> - url: <%= body.url %>,<% - if (body.dictParamVar && !body.params.length) { %> - params: <%= body.dictParamVar %>,<% } %><% - if (body.dictParamVar && body.params.length) { %> - params: { ...<%= body.dictParamVar %>, <%= body.params.join(', ') %> },<% } %><% - if (!body.dictParamVar && body.params.length) { %> - params: { <%= body.params.join(', ') %> },<% } - if (body.body) { %> - body: <%= body.body %>,<% } %> - }, - { apiName: this.apiName,...config });<% - - if (resourceApi && body.method === 'GET') { %> - - <%= camel(signature.name) %>Resource = (<% + <% if (resourceApi && body.method === 'GET') { %> + <%= camel(signature.name) %> = (<% if (resourceParameters.length) { %> params: Signal<<%= resourceType %>>,<% } %> config?: Partial @@ -67,6 +47,24 @@ export class <%= name %>Service { }); }), { apiName: this.apiName, ...config }, - );<% } + );<% } else { %> + <%= camel(signature.name) %> = (<%= serializeParameters(signature.parameters) %>) => + this.restService.request<<%= body.requestType %>, <%= responseType %>>({ + method: '<%= body.method %>',<% + if (httpResponseType && httpResponseType !== 'json') { %> + responseType: '<%= httpResponseType %>',<% } %><% + if (acceptHeader) { %> + headers: { Accept: '<%= acceptHeader %>' },<% } %> + url: <%= body.url %>,<% + if (body.dictParamVar && !body.params.length) { %> + params: <%= body.dictParamVar %>,<% } %><% + if (body.dictParamVar && body.params.length) { %> + params: { ...<%= body.dictParamVar %>, <%= body.params.join(', ') %> },<% } %><% + if (!body.dictParamVar && body.params.length) { %> + params: { <%= body.params.join(', ') %> },<% } + if (body.body) { %> + body: <%= body.body %>,<% } %> + }, + { apiName: this.apiName,...config });<% } %><% } %> } diff --git a/npm/ng-packs/packages/schematics/src/tests/proxy-service-template-render.spec.ts b/npm/ng-packs/packages/schematics/src/tests/proxy-service-template-render.spec.ts index 1860b088c7..611c0ef599 100644 --- a/npm/ng-packs/packages/schematics/src/tests/proxy-service-template-render.spec.ts +++ b/npm/ng-packs/packages/schematics/src/tests/proxy-service-template-render.spec.ts @@ -122,7 +122,9 @@ describe('proxy service template — rendered output', () => { expect(output).toContain('const { input } = params();'); expect(output).toContain('this.restService.requestResource('); expect(output).toContain('{ apiName: this.apiName, ...config }'); - expect(output).toContain('getSampleAsyncResource'); + expect(output).toContain('getSampleAsync = ('); + expect(output).not.toContain('getSampleAsyncResource'); + expect(output).not.toContain('this.restService.request'); }); test('resource api mode does not emit helpers for non-GET methods', () => { @@ -132,7 +134,8 @@ describe('proxy service template — rendered output', () => { responseTypeWithNamespace: 'My.Project.MyDto', }, true)); - expect(output).not.toContain('getSampleAsyncResource'); + expect(output).toContain('getSampleAsync = ('); + expect(output).not.toContain('requestResource('); }); test('json httpResponseType emits Accept but no responseType (default is json)', () => {