diff --git a/cli/src/commands/generate/components/instantiate.ts b/cli/src/commands/generate/components/instantiate.ts index 3441fc508..ee89ddeee 100644 --- a/cli/src/commands/generate/components/instantiate.ts +++ b/cli/src/commands/generate/components/instantiate.ts @@ -1,8 +1,8 @@ -import { Logger } from "winston"; -import { initLogger } from "../../helper.js"; -import { SchemaDirectory } from "../schema-directory.js"; -import { appendPath, logRequiredMessage, mergeSchemas, renderPath } from "../util.js"; -import { getConstValue, getPropertyValue } from "./property.js"; +import { Logger } from 'winston'; +import { initLogger } from '../../helper.js'; +import { SchemaDirectory } from '../schema-directory.js'; +import { appendPath, logRequiredMessage, mergeSchemas, renderPath } from '../util.js'; +import { getConstValue, getPropertyValue } from './property.js'; export function instantiateGenericObject(definition: object, schemaDirectory: SchemaDirectory, objectType: string, path: string[], debug: boolean = false, instantiateAll: boolean = false): object { const logger = initLogger(debug); @@ -30,12 +30,12 @@ export function instantiateGenericObject(definition: object, schemaDirectory: Sc if (!instantiateAll && required && !required.includes(key)) { // TODO should we always do interfaces even if not required? if (key === 'interfaces') { - logger.warn(`${renderedPath}: 'interfaces' property was not marked as required. You might be missing some values if this object has interfaces defined.`) + logger.warn(`${renderedPath}: 'interfaces' property was not marked as required. You might be missing some values if this object has interfaces defined.`); } logger.debug(`${renderedPath}: Skipping property ${key} as it is not marked as required.`); continue; } - if (!!detail?.const) { + if (detail?.const) { out[key] = getConstValue(detail); } else if (detail?.type === 'object') { @@ -57,22 +57,22 @@ export function instantiateGenericObject(definition: object, schemaDirectory: Sc return out; } -function isArrayObjectComplex(detail: any, logger: Logger, pathContext: string) { +function isArrayObjectComplex(detail: object, logger: Logger, pathContext: string) { if (!detail) { return false; } - const arrayContentsType = detail.items?.type + const arrayContentsType = detail['items']?.type; if (!!arrayContentsType && ['integer', 'number', 'boolean', 'string', 'const'].includes(arrayContentsType)) { - logger.info(`${pathContext}: Skipping recursive instantiation of array as it has a simple type and no prefixItems`) - return false + logger.info(`${pathContext}: Skipping recursive instantiation of array as it has a simple type and no prefixItems`); + return false; } - if (!!detail.prefixItems && !!detail.items) { - logger.warn(`${pathContext}: Both 'items' and 'prefixItems' are defined on this array schema; only prefixItems will be instantiated.`) + if (!!detail['prefixItems'] && !!detail['items']) { + logger.warn(`${pathContext}: Both 'items' and 'prefixItems' are defined on this array schema; only prefixItems will be instantiated.`); } - if (!!detail.prefixItems) { + if (detail['prefixItems']) { // if we have prefixItems and it's not a simple array, then must be complex. return true; } @@ -85,9 +85,9 @@ export function instantiateArray(prefixItems: object[], schemaDirectory: SchemaD const logger = initLogger(debug); const output = []; - logger.debug(`${path}: Instantiating elements of array as defined in prefixItems`) + logger.debug(`${path}: Instantiating elements of array as defined in prefixItems`); for (const [index, element] of prefixItems.entries()) { - const currentPath = appendPath(path, index) + const currentPath = appendPath(path, index); output.push(instantiateGenericObject(element, schemaDirectory, objectType, currentPath, debug, instantiateAll)); } diff --git a/cli/src/commands/generate/components/metadata.ts b/cli/src/commands/generate/components/metadata.ts index 4c8827935..843e7da82 100644 --- a/cli/src/commands/generate/components/metadata.ts +++ b/cli/src/commands/generate/components/metadata.ts @@ -1,6 +1,6 @@ import { initLogger } from '../../helper.js'; import { SchemaDirectory } from '../schema-directory.js'; -import { appendPath, logRequiredMessage, mergeSchemas } from '../util.js'; +import { appendPath } from '../util.js'; import { instantiateGenericObject } from './instantiate.js'; export function instantiateMetadataObject(definition: object, schemaDirectory: SchemaDirectory, path: string[], debug: boolean = false, instantiateAll: boolean = false): object { diff --git a/cli/src/commands/generate/components/node.ts b/cli/src/commands/generate/components/node.ts index d1cf3a85e..d4173bfcc 100644 --- a/cli/src/commands/generate/components/node.ts +++ b/cli/src/commands/generate/components/node.ts @@ -2,7 +2,7 @@ import { initLogger } from '../../helper.js'; import { SchemaDirectory } from '../schema-directory.js'; -import { appendPath, logRequiredMessage, mergeSchemas } from '../util.js'; +import { appendPath } from '../util.js'; import { instantiateGenericObject } from './instantiate.js'; /** @@ -36,7 +36,7 @@ export function instantiateNodes(pattern: any, schemaDirectory: SchemaDirectory, const outputNodes = []; for (const [index, node] of nodes.entries()) { - const path = appendPath(['nodes'], index) + const path = appendPath(['nodes'], index); outputNodes.push(instantiateNode(node, schemaDirectory, path, debug, instantiateAll)); } return outputNodes; diff --git a/cli/src/commands/generate/components/property.spec.ts b/cli/src/commands/generate/components/property.spec.ts index 6594e3904..2c95284d8 100644 --- a/cli/src/commands/generate/components/property.spec.ts +++ b/cli/src/commands/generate/components/property.spec.ts @@ -37,7 +37,7 @@ describe('getConstValue', () => { } }); }); -}) +}); describe('getPropertyValue', () => { it('generates string placeholder name from variable', () => { diff --git a/cli/src/commands/generate/components/relationship.ts b/cli/src/commands/generate/components/relationship.ts index 4054e8a30..5109969a4 100644 --- a/cli/src/commands/generate/components/relationship.ts +++ b/cli/src/commands/generate/components/relationship.ts @@ -2,7 +2,7 @@ import { initLogger } from '../../helper.js'; import { SchemaDirectory } from '../schema-directory.js'; -import { appendPath, logRequiredMessage, mergeSchemas } from '../util.js'; +import { appendPath } from '../util.js'; import { instantiateGenericObject } from './instantiate.js';