Browse Source

update: template for generating only one form of get function

pull/25761/head
sumeyye 1 month ago
parent
commit
cc203a1eb1
  1. 44
      npm/ng-packs/packages/schematics/src/commands/api/files-service/proxy/__namespace@dir__/__name@kebab__.service.ts.template
  2. 7
      npm/ng-packs/packages/schematics/src/tests/proxy-service-template-render.spec.ts

44
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<Rest.Config>
@ -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 });<% } %><%
} %>
}

7
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<any, MyDto>');
});
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)', () => {

Loading…
Cancel
Save