Browse Source
Merge pull request #8029 from abpframework/refactor/should-quote-key
Renamed prop key checker utility as shouldQuoteProp
pull/8035/head
Mehmet Erim
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
12 additions and
12 deletions
-
npm/ng-packs/packages/schematics/src/models/method.ts
-
npm/ng-packs/packages/schematics/src/utils/enum.ts
-
npm/ng-packs/packages/schematics/src/utils/model.ts
-
npm/ng-packs/packages/schematics/src/utils/prop.ts
|
|
|
@ -1,5 +1,5 @@ |
|
|
|
import { eBindingSourceId, eMethodModifier } from '../enums'; |
|
|
|
import { isValidProp } from '../utils/prop'; |
|
|
|
import { shouldQuoteProp } from '../utils/prop'; |
|
|
|
import { camel } from '../utils/text'; |
|
|
|
import { ParameterInBody } from './api-definition'; |
|
|
|
import { Property } from './model'; |
|
|
|
@ -46,9 +46,9 @@ export class Body { |
|
|
|
const camelName = camel(name); |
|
|
|
const paramName = jsonName || camelName; |
|
|
|
const value = descriptorName |
|
|
|
? isValidProp(paramName) |
|
|
|
? `${descriptorName}.${paramName}` |
|
|
|
: `${descriptorName}['${paramName}']` |
|
|
|
? shouldQuoteProp(paramName) |
|
|
|
? `${descriptorName}['${paramName}']` |
|
|
|
: `${descriptorName}.${paramName}` |
|
|
|
: nameOnMethod; |
|
|
|
|
|
|
|
switch (bindingSourceId) { |
|
|
|
|
|
|
|
@ -3,7 +3,7 @@ import { Exception } from '../enums'; |
|
|
|
import { Type } from '../models'; |
|
|
|
import { interpolate } from './common'; |
|
|
|
import { parseNamespace } from './namespace'; |
|
|
|
import { isValidProp } from './prop'; |
|
|
|
import { shouldQuoteProp } from './prop'; |
|
|
|
|
|
|
|
export interface EnumGeneratorParams { |
|
|
|
targetPath: string; |
|
|
|
@ -34,7 +34,7 @@ export function createImportRefToEnumMapper({ solution, types }: EnumGeneratorPa |
|
|
|
|
|
|
|
const namespace = parseNamespace(solution, ref); |
|
|
|
const members = enumNames!.map((key, i) => ({ |
|
|
|
key: isValidProp(key) ? key : `'${key}'`, |
|
|
|
key: shouldQuoteProp(key) ? `'${key}'` : key, |
|
|
|
value: enumValues[i], |
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
@ -8,7 +8,7 @@ import { |
|
|
|
} from './generics'; |
|
|
|
import { parseNamespace } from './namespace'; |
|
|
|
import { relativePathToModel } from './path'; |
|
|
|
import { isValidProp } from './prop'; |
|
|
|
import { shouldQuoteProp } from './prop'; |
|
|
|
import { camel } from './text'; |
|
|
|
import { parseGenerics } from './tree'; |
|
|
|
import { |
|
|
|
@ -136,7 +136,7 @@ export function createImportRefToInterfaceReducerCreator(params: ModelGeneratorP |
|
|
|
|
|
|
|
typeDef.properties?.forEach(prop => { |
|
|
|
let name = prop.jsonName || camel(prop.name); |
|
|
|
name = isValidProp(name) ? name : `'${name}'`; |
|
|
|
name = shouldQuoteProp(name) ? `'${name}'` : name; |
|
|
|
const type = simplifyType(prop.typeSimple); |
|
|
|
const refs = parseType(prop.type).reduce( |
|
|
|
(acc: string[], r) => acc.concat(parseGenerics(r).toGenerics()), |
|
|
|
|
|
|
|
@ -1,9 +1,9 @@ |
|
|
|
export const isValidProp = (name: string) => { |
|
|
|
export const shouldQuoteProp = (key: string) => { |
|
|
|
try { |
|
|
|
new Function('return {}.' + name); |
|
|
|
new Function('return {}.' + key); |
|
|
|
} catch (_) { |
|
|
|
return false; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
return false; |
|
|
|
}; |
|
|
|
|