diff --git a/README.md b/README.md index 0b0fe44..363866b 100644 --- a/README.md +++ b/README.md @@ -925,8 +925,9 @@ With version `v8.0.0`, _getTemplate_ was improved to better support optional pro - Renamed `JSONError` to `JsonError` and `JSONSchema` to `JsonSchema` - `getTemplate` only adds required properties. Behaviour can be changed by [getTemplate default options](#gettemplate-default-options) -- internal schema property `oneOfSchema` has been replaced by `schema.getOneOfOrigin()` +- Internal schema property `oneOfSchema` has been replaced by `schema.getOneOfOrigin()` - Changed `unique-items-error` to point to error for duplicated item and changed data-properties +- Removed `SchemaService` as it was no longer used nor tested
Exposed new helper functions diff --git a/index.ts b/index.ts index f07412b..848bcc1 100644 --- a/index.ts +++ b/index.ts @@ -4,7 +4,6 @@ import { resolveOneOf, resolveOneOfFuzzy } from "./lib/features/oneOf"; import { resolveAllOf } from "./lib/features/allOf"; import resolveRef from "./lib/resolveRef.strict"; import resolveRefMerge from "./lib/resolveRef.merge"; -import SchemaService from "./lib/SchemaService"; import settings from "./lib/config/settings"; import strings from "./lib/config/strings"; import validateAsync from "./lib/validateAsync"; @@ -36,7 +35,7 @@ export { getTypeOf, // returns the javascript datatype isDynamicSchema, // NEW isJsonError, - JsonEditor, // adjusted core of draft04 to better support the json-editor + JsonEditor, // adjusted core of draft07 to better support the json-editor mergeSchema, // NEW reduceSchema, // NEW render, @@ -46,7 +45,6 @@ export { resolveOneOfFuzzy, resolveRef, resolveRefMerge, - SchemaService, settings, validateAsync // async validation of data by a schema }; diff --git a/lib/SchemaService.ts b/lib/SchemaService.ts deleted file mode 100644 index bc8cdb0..0000000 --- a/lib/SchemaService.ts +++ /dev/null @@ -1,72 +0,0 @@ -import getSchema from "./getSchema"; -import { JsonEditor as Draft } from "./jsoneditor"; -import gp from "@sagold/json-pointer"; -import copy from "./utils/copy"; -import { JsonSchema, JsonPointer } from "./types"; - -export default class SchemaService { - draft: Draft; - schema: JsonSchema; - data: unknown; - cache: Record; - - constructor(schema: JsonSchema, data: unknown) { - this.draft = new Draft(schema); - this.schema = schema; - this.data = data; - this.cache = {}; - } - - updateData(data: unknown) { - this.data = data; - this.cache = {}; - } - - updateSchema(schema: JsonSchema) { - this.schema = schema; - this.draft.setSchema(schema); - this.cache = {}; - } - - get(pointer: JsonPointer, data: unknown): JsonSchema { - if (data) { - // possibly separate entry point - const schema = getSchema(this.draft, pointer, data, this.schema); - return copy(schema); - } - - if (pointer === "#") { - // root - return this.schema; - } - - if (this.cache[pointer]) { - // return cached result - return this.cache[pointer]; - } - - const parentPointer = gp.join(pointer, ".."); - let parentSchema = this.cache[parentPointer]; - if (parentSchema == null) { - // store parent (major performance improvement if its within oneof) - parentSchema = getSchema(this.draft, parentPointer, this.data, this.schema); - if (parentSchema.variableSchema !== true) { - this.cache[parentPointer] = copy(parentSchema); - } - } - - // step from parent to child - const key = gp.split(pointer).pop(); - let schema = getSchema( - this.draft, - key, - gp.get(this.data, parentPointer), - this.cache[parentPointer] - ); - schema = copy(schema); - if (schema.variableSchema !== true) { - this.cache[pointer] = schema; - } - return schema; - } -}