botbuilder-dialogs-adaptive
Version:
Rule system for the Microsoft BotBuilder dialog system.
95 lines • 2.35 kB
JavaScript
"use strict";
/**
* @module botbuilder-dialogs-adaptive
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.PropertySchema = void 0;
/**
* Represents a property found in a JSON schema.
*/
class PropertySchema {
/**
* Creates a new `PropertySchema` instance.
*
* @param path Path to this property.
* @param schema JSON schema fragment for this property.
* @param children Optional. Child properties.
*/
constructor(path, schema, children) {
this.path = path;
this.schema = schema;
this._children = children || [];
children.forEach((child) => (child._parent = this));
this._entities = schema['$entities'] || [];
this._expectedOnly = schema['$expectedOnly'] || [];
}
/**
* Parent property schema if any.
*
* @returns The parent property schema if any.
*/
get parent() {
return this._parent;
}
/**
* Child properties if there are any.
*
* @returns The child properties if there are any.
*/
get children() {
return this._children;
}
/**
* List of entity names.
*
* @returns A list of entity names.
*/
get entities() {
return this._entities;
}
/**
* List of expected only entity names.
*
* @returns A List of expected only entity names.
*/
get expectedOnly() {
return this._expectedOnly;
}
/**
* Name for this property.
*
* @remarks
* Array brackets `[]` will have been removed.
* @returns The name for this property.
*/
get name() {
const segments = this.path.split('.');
return segments[segments.length - 1].replace('[]', '');
}
/**
* JSON Schema type.
*
* @returns The JSON Schema type.
*/
get type() {
return this.schema['type'];
}
/**
* @returns `true` if the property is an array.
*/
isArray() {
return this.path.endsWith('[]');
}
/**
* @returns `true` if the property is an enum.
*/
isEnum() {
return !!this.schema['enum'];
}
}
exports.PropertySchema = PropertySchema;
//# sourceMappingURL=propertySchema.js.map