Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {JSONSchema4Type, JSONSchema4TypeName} from 'json-schema'
import {findKey, includes, isPlainObject, map, omit} from 'lodash'
import {findKey, includes, isPlainObject, map, memoize, omit} from 'lodash'
import {format} from 'util'
import {Options} from './'
import {typesOfSchema} from './typesOfSchema'
Expand Down Expand Up @@ -119,7 +119,7 @@ function parseNonLiteral(
processed: Processed,
usedNames: UsedNames
): AST {
const definitions = getDefinitions(getRootSchema(schema as any)) // TODO
const definitions = getDefinitionsMemoized(getRootSchema(schema as any)) // TODO
const keyNameFromDefinition = findKey(definitions, _ => _ === schema)

switch (type) {
Expand Down Expand Up @@ -433,9 +433,6 @@ via the \`definition\` "${key}".`

type Definitions = {[k: string]: LinkedJSONSchema}

/**
* TODO: Memoize
*/
function getDefinitions(
schema: LinkedJSONSchema,
isSchema = true,
Expand Down Expand Up @@ -469,6 +466,8 @@ function getDefinitions(
return {}
}

const getDefinitionsMemoized = memoize(getDefinitions)

/**
* TODO: Reduce rate of false positives
*/
Expand Down