@@ -2,7 +2,14 @@ import { is, isSchemaFactoryType } from '../../utils';
22import { BuildSchemaError , ValidationError } from '../errors' ;
33import { Schema } from '../schema' ;
44import { CoreType } from '../types' ;
5- import { CustomValidations , FactoryFunction , FieldMap , IOttomanType , SchemaDef } from '../interfaces/schema.types' ;
5+ import {
6+ CoreTypeOptions ,
7+ CustomValidations ,
8+ FactoryFunction ,
9+ FieldMap ,
10+ IOttomanType ,
11+ SchemaDef ,
12+ } from '../interfaces/schema.types' ;
613import { cast , CAST_STRATEGY , CastOptions } from '../../utils/cast-strategy' ;
714
815type ParseResult = {
@@ -37,7 +44,7 @@ export const buildFields = (obj: Schema | SchemaDef, strict = true): FieldMap =>
3744 if ( ! opts . type ) {
3845 throw new BuildSchemaError ( `Property '${ _key } ' is a required type` ) ;
3946 }
40- fields [ _key ] = _makeField ( _key , opts ) ;
47+ fields [ _key ] = _makeField ( _key , opts , obj [ _key ] ) ;
4148 }
4249 return fields ;
4350} ;
@@ -105,11 +112,14 @@ const _getFieldType = (type: any): any => {
105112 * @param def result of parsing the field schema
106113 * @throws BuildSchemaError
107114 */
108- const _makeField = ( name : string , def : ParseResult ) : IOttomanType => {
115+ const _makeField = ( name : string , def : ParseResult , arrayOptions ?: CoreTypeOptions ) : IOttomanType => {
109116 const typeFactory = Schema . FactoryTypes [ String ( def . type ) ] ;
110117 if ( typeFactory === undefined ) {
111118 throw new BuildSchemaError ( `Unsupported type specified in the property '${ name } '` ) ;
112119 }
120+ if ( arrayOptions !== undefined ) {
121+ return typeFactory ( name , def . options , arrayOptions ) ;
122+ }
113123 return typeFactory ( name , def . options ) ;
114124} ;
115125/**
0 commit comments