diff --git a/src/mapping.ts b/src/mapping.ts index 16bc2e1e..367c5e4b 100644 --- a/src/mapping.ts +++ b/src/mapping.ts @@ -457,7 +457,7 @@ function handleType(type: Type, generics: Map, path: return handleUnionType(type, new Map(generics), path, topTypeName, tags); } if (type instanceof ReferenceType) { - if (typeof type.reflection !== 'undefined') { + if (typeof premaps[type.name] === 'undefined' && typeof type.reflection !== 'undefined') { // there is really no way to make this typesafe, every element in DeclarationReflection is optional. return handleDeclarationReflection(type.reflection as DeclarationReflection, getReflectionGeneric(type, new Map(generics), path, topTypeName, tags), path, topTypeName, tags); diff --git a/src/mappings/definitions/typemap.ts b/src/mappings/definitions/typemap.ts index dd5b82ef..1e8845e0 100644 --- a/src/mappings/definitions/typemap.ts +++ b/src/mappings/definitions/typemap.ts @@ -32,7 +32,7 @@ export enum ElasticsearchDataType { geo_point = 'geo_point', geo_shape = 'geo_shape', completion = 'completion', - date_range = 'date_rage', + date_range = 'date_range', // integer_range = 'integer_range', // float_range = 'float_range', // long_range = 'long_range', diff --git a/test/mapping-model/mappings/src/type-overrides.ts b/test/mapping-model/mappings/src/type-overrides.ts new file mode 100644 index 00000000..945faab3 --- /dev/null +++ b/test/mapping-model/mappings/src/type-overrides.ts @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +export interface SCISO8601DateRange { + bar: string; +} + +/** + * @indexable + */ +export interface TypeOverrides { + foo: SCISO8601DateRange; + + type: ThingType.TypeOverrides +} + +export const typeOverridesTest: MapAggTestOptions = { + name: ThingType.TypeOverrides, + map: { + maps: { + foo: { + type: ElasticsearchDataType.date_range, + }, + } + } +}; diff --git a/test/mapping-model/mappings/src/types.ts b/test/mapping-model/mappings/src/types.ts index c3015ac0..514e141b 100644 --- a/test/mapping-model/mappings/src/types.ts +++ b/test/mapping-model/mappings/src/types.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 StApps + * Copyright (C) 2020-2021 StApps * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, version 3. @@ -38,4 +38,5 @@ export enum ThingType { InheritTags = 'inherit tags', TagsIgnoreCase = 'tags ignore case', TypeAlias = 'type alias', + TypeOverrides = 'type overrides', } diff --git a/test/mapping.spec.ts b/test/mapping.spec.ts index d2acafd2..9e5994b1 100644 --- a/test/mapping.spec.ts +++ b/test/mapping.spec.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 StApps + * Copyright (C) 2020-2021 StApps * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, version 3. @@ -37,6 +37,7 @@ import {anyUnknownTest} from './mapping-model/mappings/src/any-unknown'; import {tagsIgnoreCaseTest} from './mapping-model/mappings/src/tags-ignore-case'; import {typeAliasTest} from './mapping-model/mappings/src/type-alias'; import {dateAndRangeTest} from './mapping-model/mappings/src/date'; +import {typeOverridesTest} from './mapping-model/mappings/src/type-overrides'; process.on('unhandledRejection', (error: unknown) => { if (error instanceof Error) { @@ -174,4 +175,9 @@ export class MappingSpec { async 'Dates and date ranges should have the correct type'() { magAppInstance.testInterfaceAgainstPath(dateAndRangeTest); } + + @test + async 'Premaps should support non-external types'() { + magAppInstance.testInterfaceAgainstPath(typeOverridesTest); + } }