Browse Source

Merge pull request #6102 from abpframework/feat/6085

Proxy Generator: Enable optional string properties in models
pull/6106/head
Bunyamin Coskuner 6 years ago
committed by GitHub
parent
commit
43b7474013
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11266
      npm/ng-packs/packages/schematics/src/mocks/api-definition.json
  2. 1
      npm/ng-packs/packages/schematics/src/models/api-definition.ts
  3. 10
      npm/ng-packs/packages/schematics/src/utils/model.ts

11266
npm/ng-packs/packages/schematics/src/mocks/api-definition.json

File diff suppressed because it is too large

1
npm/ng-packs/packages/schematics/src/models/api-definition.ts

@ -18,6 +18,7 @@ export interface PropertyDef {
name: string; name: string;
type: string; type: string;
typeSimple: string; typeSimple: string;
isRequired: boolean;
} }
export interface Module { export interface Module {

10
npm/ng-packs/packages/schematics/src/utils/model.ts

@ -1,5 +1,5 @@
import { VOLO_NAME_VALUE, VOLO_REGEX } from '../constants'; import { VOLO_NAME_VALUE, VOLO_REGEX } from '../constants';
import { Interface, Model, Property, Type, TypeWithEnum } from '../models'; import { Interface, Model, Property, PropertyDef, Type, TypeWithEnum } from '../models';
import { parseNamespace } from './namespace'; import { parseNamespace } from './namespace';
import { relativePathToModel } from './path'; import { relativePathToModel } from './path';
import { camel } from './text'; import { camel } from './text';
@ -119,7 +119,7 @@ export function createImportRefToInterfaceReducerCreator(params: ModelGeneratorP
typeDef.properties?.forEach(prop => { typeDef.properties?.forEach(prop => {
const name = camel(prop.name); const name = camel(prop.name);
const optional = prop.typeSimple.endsWith('?') ? '?' : ''; const optional = isOptionalProperty(prop) ? '?' : '';
const type = simplifyType(prop.typeSimple); const type = simplifyType(prop.typeSimple);
const refs = parseType(prop.type).reduce( const refs = parseType(prop.type).reduce(
(acc: string[], r) => acc.concat(parseGenerics(r).toGenerics()), (acc: string[], r) => acc.concat(parseGenerics(r).toGenerics()),
@ -150,3 +150,9 @@ export function createRefToImportReducerCreator(params: ModelGeneratorParams) {
const { solution } = params; const { solution } = params;
return (namespace: string) => createTypesToImportsReducer(solution, namespace); return (namespace: string) => createTypesToImportsReducer(solution, namespace);
} }
function isOptionalProperty(prop: PropertyDef) {
return (
prop.typeSimple.endsWith('?') || (prop.typeSimple === 'string' && prop.isRequired === false)
);
}

Loading…
Cancel
Save