Skip to content

Commit

Permalink
finos#486 lint
Browse files Browse the repository at this point in the history
  • Loading branch information
willosborne committed Nov 18, 2024
1 parent 96df39f commit 32e3dc5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
32 changes: 16 additions & 16 deletions shared/src/commands/generate/components/instantiate.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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') {
Expand All @@ -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;
}
Expand All @@ -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));
}

Expand Down
2 changes: 1 addition & 1 deletion shared/src/commands/generate/components/metadata.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions shared/src/commands/generate/components/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion shared/src/commands/generate/components/property.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('getConstValue', () => {
}
});
});
})
});

describe('getPropertyValue', () => {
it('generates string placeholder name from variable', () => {
Expand Down
2 changes: 1 addition & 1 deletion shared/src/commands/generate/components/relationship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


Expand Down

0 comments on commit 32e3dc5

Please sign in to comment.