From fb4afa3d919815c8111175f78aaee393b4f45aa9 Mon Sep 17 00:00:00 2001 From: Fahri Gedik Date: Tue, 19 Aug 2025 12:15:09 +0300 Subject: [PATCH] Support dictionary query params in service templates Added logic to handle dictionary-type query parameters in generated service templates. Updated method model and template to correctly assign dictionary params, and introduced isDictionaryType utility for type detection. --- .../__namespace@dir__/__name@kebab__.service.ts.template | 6 +++++- npm/ng-packs/packages/schematics/src/models/method.ts | 8 +++++++- npm/ng-packs/packages/schematics/src/utils/methods.ts | 7 +++++-- 3 files changed, 17 insertions(+), 4 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 8b0c343173..c445286162 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 @@ -21,7 +21,11 @@ export class <%= name %>Service { if (isBlob) { %> responseType: 'blob',<% } %> url: <%= body.url %>,<% - if (body.params.length) { %> + 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 %>,<% } %> diff --git a/npm/ng-packs/packages/schematics/src/models/method.ts b/npm/ng-packs/packages/schematics/src/models/method.ts index 043df6d458..404fa9d233 100644 --- a/npm/ng-packs/packages/schematics/src/models/method.ts +++ b/npm/ng-packs/packages/schematics/src/models/method.ts @@ -1,11 +1,12 @@ import { eBindingSourceId, eMethodModifier } from '../enums'; import { camel, camelizeHyphen } from '../utils/text'; -import { getParamName, getParamValueName } from '../utils/methods'; +import { getParamName, getParamValueName, isDictionaryType } from '../utils/methods'; import { ParameterInBody } from './api-definition'; import { Property } from './model'; import { Omissible } from './util'; import { VOLO_REMOTE_STREAM_CONTENT } from '../constants'; // eslint-disable-next-line @typescript-eslint/no-var-requires + const shouldQuote = require('should-quote'); export class Method { @@ -40,6 +41,7 @@ export class Body { body?: string; method: string; params: string[] = []; + dictParamVar?: string; responseTypeWithNamespace: string; requestType = 'any'; responseType: string; @@ -57,6 +59,10 @@ export class Body { switch (bindingSourceId) { case eBindingSourceId.Model: case eBindingSourceId.Query: + if (isDictionaryType(param.type, param.typeSimple)) { + this.dictParamVar = value; + break; + } this.params.push(paramName === value ? value : `${getParamName(paramName)}: ${value}`); break; case eBindingSourceId.FormFile: diff --git a/npm/ng-packs/packages/schematics/src/utils/methods.ts b/npm/ng-packs/packages/schematics/src/utils/methods.ts index 6767adf540..d3fc935819 100644 --- a/npm/ng-packs/packages/schematics/src/utils/methods.ts +++ b/npm/ng-packs/packages/schematics/src/utils/methods.ts @@ -1,11 +1,9 @@ import { camel } from './text'; -// eslint-disable-next-line @typescript-eslint/no-var-requires const shouldQuote = require('should-quote'); export const getParamName = (paramName: string) => shouldQuote(paramName) ? `["${paramName}"]` : paramName; -// check dot exists in param name and camelize access continuously export const getParamValueName = (paramName: string, descriptorName: string) => { if (paramName.includes('.')) { const splitted = paramName.split('.'); @@ -17,3 +15,8 @@ export const getParamValueName = (paramName: string, descriptorName: string) => } return `${descriptorName}.${paramName}`; }; + +export function isDictionaryType(type?: string, typeSimple?: string): boolean { + const haystacks = [type || '', typeSimple || '']; + return haystacks.some(t => /(^|\b)(System\.Collections\.Generic\.)?(I)?Dictionary\s*