Browse Source

feat: mark not required string property as optional

pull/6102/head
Arman Ozak 6 years ago
parent
commit
83b0d20c43
  1. 10
      npm/ng-packs/packages/schematics/src/utils/model.ts

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

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

Loading…
Cancel
Save