diff --git a/packages/parser/json-schema-parser/src/jsonSchema/202012/calculations/getJsonSchemaBaseUri.spec.ts b/packages/parser/json-schema-parser/src/jsonSchema/202012/calculations/getJsonSchemaBaseUri.spec.ts index 79e5746..878b504 100644 --- a/packages/parser/json-schema-parser/src/jsonSchema/202012/calculations/getJsonSchemaBaseUri.spec.ts +++ b/packages/parser/json-schema-parser/src/jsonSchema/202012/calculations/getJsonSchemaBaseUri.spec.ts @@ -5,7 +5,7 @@ jest.mock('@cuaklabs/uri'); import { JsonSchemaObject } from '@cuaklabs/json-schema-types/2020-12'; import { getBaseUri, GetBaseUriOptions } from '@cuaklabs/uri'; -import { JsonRootSchema202012Fixtures } from '../fixtures/JsonRootSchema202012Fixtures'; +import { JsonRootSchemaFixtures } from '../fixtures/JsonRootSchemaFixtures'; import { getJsonSchemaBaseUri } from './getJsonSchemaBaseUri'; describe(getJsonSchemaBaseUri.name, () => { @@ -13,7 +13,7 @@ describe(getJsonSchemaBaseUri.name, () => { let jsonSchemaFixture: JsonSchemaObject; beforeAll(() => { - jsonSchemaFixture = JsonRootSchema202012Fixtures.withId; + jsonSchemaFixture = JsonRootSchemaFixtures.withId; }); describe('when called', () => { @@ -54,7 +54,7 @@ describe(getJsonSchemaBaseUri.name, () => { let jsonSchemaFixture: JsonSchemaObject; beforeAll(() => { - jsonSchemaFixture = JsonRootSchema202012Fixtures.withNoId; + jsonSchemaFixture = JsonRootSchemaFixtures.withNoId; }); describe('when called', () => { diff --git a/packages/parser/json-schema-parser/src/jsonSchema/202012/fixtures/JsonRootSchemaFixtures.ts b/packages/parser/json-schema-parser/src/jsonSchema/202012/fixtures/JsonRootSchemaFixtures.ts new file mode 100644 index 0000000..8be3bff --- /dev/null +++ b/packages/parser/json-schema-parser/src/jsonSchema/202012/fixtures/JsonRootSchemaFixtures.ts @@ -0,0 +1,244 @@ +import { + JsonRootSchemaObject, + jsonSchemaTypes, +} from '@cuaklabs/json-schema-types/2020-12'; + +export class JsonRootSchemaFixtures { + public static get any(): JsonRootSchemaObject { + return { + $schema: 'https://json-schema.org/draft/2020-12/schema', + }; + } + + public static get withId(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + $id: 'https://schema.id', + }; + } + + public static get withNoId(): JsonRootSchemaObject { + const fixture: JsonRootSchemaObject = JsonRootSchemaFixtures.any; + + delete fixture.$id; + + return fixture; + } + + public static get with$DefsOne(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + $defs: { + enabledToggle: { + default: null, + description: `Whether the feature is enabled (true), +disabled (false), or under +automatic control (null)`, + title: 'Enabled', + type: [jsonSchemaTypes.boolean, jsonSchemaTypes.null], + }, + }, + }; + } + + public static get withAdditionalProperties(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + additionalProperties: { $ref: 'other.json' }, + }; + } + + public static get withAllOfTwo(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + allOf: [{ maximum: 30 }, { minimum: 20 }], + }; + } + + public static get withAnyOfTwo(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + anyOf: [{ maximum: 30 }, { minimum: 20 }], + }; + } + + public static get withContains(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + contains: { + enabledToggle: { + default: null, + description: `Whether the feature is enabled (true), +disabled (false), or under +automatic control (null)`, + title: 'Enabled', + type: [jsonSchemaTypes.boolean, jsonSchemaTypes.null], + }, + }, + }; + } + + public static get withDependentSchemasOne(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + dependentSchemas: { + enabledToggle: { + default: null, + description: `Whether the feature is enabled (true), +disabled (false), or under +automatic control (null)`, + title: 'Enabled', + type: [jsonSchemaTypes.boolean, jsonSchemaTypes.null], + }, + }, + }; + } + + public static get withElse(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + else: { + enabledToggle: { + default: null, + description: `Whether the feature is enabled (true), +disabled (false), or under +automatic control (null)`, + title: 'Enabled', + type: [jsonSchemaTypes.boolean, jsonSchemaTypes.null], + }, + }, + }; + } + + public static get withIf(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + if: { + enabledToggle: { + default: null, + description: `Whether the feature is enabled (true), +disabled (false), or under +automatic control (null)`, + title: 'Enabled', + type: [jsonSchemaTypes.boolean, jsonSchemaTypes.null], + }, + }, + }; + } + + public static get withItems(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + items: { + enabledToggle: { + default: null, + description: `Whether the feature is enabled (true), +disabled (false), or under +automatic control (null)`, + title: 'Enabled', + type: [jsonSchemaTypes.boolean, jsonSchemaTypes.null], + }, + }, + }; + } + + public static get withNot(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + not: { + enabledToggle: { + default: null, + description: `Whether the feature is enabled (true), +disabled (false), or under +automatic control (null)`, + title: 'Enabled', + type: [jsonSchemaTypes.boolean, jsonSchemaTypes.null], + }, + }, + }; + } + + public static get withOneOfTwo(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + oneOf: [{ maximum: 20 }, { minimum: 30 }], + }; + } + + public static get withPatternProperiesOne(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + patternProperties: { + '^[a-z0-9]+$': { + type: [jsonSchemaTypes.boolean, jsonSchemaTypes.null], + }, + }, + }; + } + + public static get withPrefixItemsOne(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + prefixItems: [ + { + enabledToggle: { + default: null, + description: `Whether the feature is enabled (true), +disabled (false), or under +automatic control (null)`, + title: 'Enabled', + type: [jsonSchemaTypes.boolean, jsonSchemaTypes.null], + }, + }, + ], + }; + } + + public static get withProperiesOne(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + properties: { + z39: { + type: [jsonSchemaTypes.boolean, jsonSchemaTypes.null], + }, + }, + }; + } + + public static get withProperyNames(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + propertyNames: { maxLength: 3 }, + }; + } + + public static get withThen(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + then: { + enabledToggle: { + default: null, + description: `Whether the feature is enabled (true), +disabled (false), or under +automatic control (null)`, + title: 'Enabled', + type: [jsonSchemaTypes.boolean, jsonSchemaTypes.null], + }, + }, + }; + } + + public static get withUnevaluatedItems(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + unevaluatedItems: { maxLength: 3 }, + }; + } + + public static get withUnevaluatedProperties(): JsonRootSchemaObject { + return { + ...JsonRootSchemaFixtures.any, + unevaluatedProperties: { maxLength: 3 }, + }; + } +}