diff --git a/README.md b/README.md index 33a1eb5..e213d67 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,8 @@ What follows is a description of the main draft methods. **Currently unsupported core features:** - `$vocabulary` - meta-schemas are not parsed for enabled features -- `unevaluatedItems: uncle-schema` - evaluation of uncle-schemas is not supported. Properties will be return as evaluated -- `unevaluatedProperties: uncle-schema` - evaluation of uncle-schemas is not supported. Properties will be return as evaluated +- `unevaluatedItems: uncle-schema` - evaluation of uncle-schemas is not supported. Properties will be returned as evaluated +- `unevaluatedProperties: uncle-schema` - evaluation of uncle-schemas is not supported. Properties will be returned as evaluated For further details see [draft2019-09 tests](https://github.com/sagold/json-schema-library/blob/main/test/spec/v2019-09/draft2019-09.test.ts) diff --git a/lib/getChildSchemaSelection.ts b/lib/getChildSchemaSelection.ts index 423f464..45459f3 100644 --- a/lib/getChildSchemaSelection.ts +++ b/lib/getChildSchemaSelection.ts @@ -6,7 +6,7 @@ import { isJsonError, JsonError, JsonSchema } from "./types"; * could be added at the given property (e.g. item-index), thus an array of options is returned. In all other cases * a list with a single item will be returned * - * @param draft - draft to use + * @param draft - draft to use * @param property - parent schema of following property * @param [schema] - parent schema of following property * @return @@ -20,12 +20,17 @@ export default function getChildSchemaSelection( return schema.oneOf.map((item: JsonSchema) => draft.createNode(item).resolveRef().schema); } if (schema.items?.oneOf) { - return schema.items.oneOf.map((item: JsonSchema) => draft.createNode(item).resolveRef().schema); + return schema.items.oneOf.map( + (item: JsonSchema) => draft.createNode(item).resolveRef().schema + ); + } + if (Array.isArray(schema.items) && schema.items.length <= +property) { + return []; } const node = draft.step(draft.createNode(schema), property, {}); if (isJsonError(node)) { - return node; + const error: JsonError = node; + return error; } - return [node.schema]; } diff --git a/test/unit/createSchemaOf.test.ts b/test/unit/createSchemaOf.test.ts index 3854e5a..ca78922 100644 --- a/test/unit/createSchemaOf.test.ts +++ b/test/unit/createSchemaOf.test.ts @@ -1,9 +1,7 @@ import { expect } from "chai"; import createSchemaOf from "../../lib/createSchemaOf"; - describe("createSchemaOf", () => { - it("should add type 'object' of data to schema", () => { const res = createSchemaOf({}); expect(res.type).to.eq("object");