@takeshape/json-schema 11.104.4 → 11.105.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,3 @@
1
1
  import type { JSONSchema7 } from 'json-schema';
2
2
  export declare const jsonSchema7Keys: Array<keyof JSONSchema7>;
3
+ export declare const jsonSchema7PrimitiveTypes: ["string", "number", "boolean", "integer", "null"];
@@ -47,3 +47,10 @@ export const jsonSchema7Keys = [
47
47
  'definitions',
48
48
  '$defs'
49
49
  ];
50
+ export const jsonSchema7PrimitiveTypes = [
51
+ 'string',
52
+ 'number',
53
+ 'boolean',
54
+ 'integer',
55
+ 'null'
56
+ ];
@@ -1,6 +1,7 @@
1
- import type { JSONSchema7, JSONSchema7Definition } from 'json-schema';
2
- import type { AllOfSchema, AnyOfSchema, ArraySchema, EnumSchema, ListSchema, ObjectSchema, OneOfSchema, PropertySchema, RefSchema, TupleSchema } from './types.ts';
3
- export declare function isSchema(schema: JSONSchema7Definition): schema is JSONSchema7;
1
+ import type { JSONSchema7Definition } from 'json-schema';
2
+ import type { AllOfSchema, AnyOfSchema, ArraySchema, ConstSchema, EnumSchema, ListSchema, ObjectSchema, OneOfSchema, PrimitiveSchema, PropertySchema, RefSchema, TupleSchema, TypeUnionSchema } from './types.ts';
3
+ export declare function isBooleanProperty(schema: JSONSchema7Definition): schema is boolean;
4
+ export declare function isSchema(schema: JSONSchema7Definition): schema is Exclude<JSONSchema7Definition, boolean>;
4
5
  export declare function isOneOfSchema(schema: JSONSchema7Definition): schema is OneOfSchema;
5
6
  export declare function isAnyOfSchema(schema: JSONSchema7Definition): schema is AnyOfSchema;
6
7
  export declare function isAllOfSchema(schema: JSONSchema7Definition): schema is AllOfSchema;
@@ -11,4 +12,7 @@ export declare function isArraySchema(schema: JSONSchema7Definition): schema is
11
12
  export declare function isListSchema(schema: JSONSchema7Definition): schema is ListSchema;
12
13
  export declare function isTupleSchema(schema: JSONSchema7Definition): schema is TupleSchema;
13
14
  export declare function isEnumSchema(schema: JSONSchema7Definition): schema is EnumSchema;
15
+ export declare function isConstSchema(schema: JSONSchema7Definition): schema is ConstSchema;
14
16
  export declare function isRefSchema(schema: JSONSchema7Definition): schema is RefSchema;
17
+ export declare function isTypeUnionSchema(schema: JSONSchema7Definition): schema is TypeUnionSchema;
18
+ export declare function isPrimitiveSchema(schema: JSONSchema7Definition): schema is PrimitiveSchema;
@@ -1,5 +1,9 @@
1
+ import { jsonSchema7PrimitiveTypes } from "./constants.js";
2
+ export function isBooleanProperty(schema) {
3
+ return typeof schema === 'boolean';
4
+ }
1
5
  export function isSchema(schema) {
2
- return typeof schema !== 'boolean';
6
+ return !isBooleanProperty(schema);
3
7
  }
4
8
  export function isOneOfSchema(schema) {
5
9
  return isSchema(schema) && Array.isArray(schema.oneOf);
@@ -31,6 +35,21 @@ export function isTupleSchema(schema) {
31
35
  export function isEnumSchema(schema) {
32
36
  return Boolean(isSchema(schema) && schema.enum);
33
37
  }
38
+ export function isConstSchema(schema) {
39
+ return Boolean(isSchema(schema) && schema.const);
40
+ }
34
41
  export function isRefSchema(schema) {
35
42
  return Boolean(isSchema(schema) && schema.$ref);
36
43
  }
44
+ export function isTypeUnionSchema(schema) {
45
+ return isSchema(schema) && Array.isArray(schema.type);
46
+ }
47
+ export function isPrimitiveSchema(schema) {
48
+ if (typeof schema !== 'object') {
49
+ return false;
50
+ }
51
+ if (isTypeUnionSchema(schema)) {
52
+ return schema.type.every((t) => jsonSchema7PrimitiveTypes.includes(t));
53
+ }
54
+ return jsonSchema7PrimitiveTypes.includes(schema.type);
55
+ }
@@ -1,4 +1,5 @@
1
1
  import type { JSONSchema7, JSONSchema7Definition, JSONSchema7Type, JSONSchema7TypeName } from 'json-schema';
2
+ import type { jsonSchema7PrimitiveTypes } from './constants.ts';
2
3
  /**
3
4
  * Add the discriminator property to JSONSchema7, which we make frequent use of.
4
5
  */
@@ -9,36 +10,46 @@ declare module 'json-schema' {
9
10
  };
10
11
  }
11
12
  }
12
- export type OneOfSchema = JSONSchema7 & {
13
+ export type OneOfSchema = Omit<JSONSchema7, 'oneOf'> & {
13
14
  oneOf: Exclude<JSONSchema7['oneOf'], undefined>;
14
15
  };
15
- export type AnyOfSchema = JSONSchema7 & {
16
+ export type AnyOfSchema = Omit<JSONSchema7, 'anyOf'> & {
16
17
  anyOf: Exclude<JSONSchema7['anyOf'], undefined>;
17
18
  };
18
- export type AllOfSchema = JSONSchema7 & {
19
+ export type AllOfSchema = Omit<JSONSchema7, 'allOf'> & {
19
20
  allOf: Exclude<JSONSchema7['allOf'], undefined>;
20
21
  };
21
22
  export type ObjectSchema = Omit<JSONSchema7, 'type'> & {
22
23
  type: 'object';
23
24
  };
24
- export type PropertySchema = ObjectSchema & {
25
+ export type PropertySchema = Omit<ObjectSchema, 'properties'> & {
25
26
  properties: Exclude<JSONSchema7['properties'], undefined>;
26
27
  };
27
28
  export type ArraySchema = Omit<JSONSchema7, 'type'> & {
28
29
  type: 'array';
29
30
  };
30
- export type ListSchema = ArraySchema & {
31
+ export type ListSchema = Omit<ArraySchema, 'items'> & {
31
32
  items: Exclude<JSONSchema7['items'], JSONSchema7Definition[] | undefined>;
32
33
  };
33
34
  export type TupleSchema = ArraySchema & {
34
35
  items: Exclude<JSONSchema7['items'], JSONSchema7Definition | undefined>;
35
36
  };
36
- export type EnumSchema = JSONSchema7 & {
37
+ export type EnumSchema = Omit<JSONSchema7, 'enum'> & {
37
38
  enum: Exclude<JSONSchema7['enum'], undefined>;
38
39
  };
39
- export type RefSchema = JSONSchema7 & {
40
+ export type ConstSchema = Omit<JSONSchema7, 'const'> & {
41
+ const: Exclude<JSONSchema7['const'], undefined>;
42
+ };
43
+ export type RefSchema = Omit<JSONSchema7, '$ref'> & {
40
44
  $ref: Exclude<JSONSchema7['$ref'], undefined>;
41
45
  };
46
+ export type TypeUnionSchema = Omit<JSONSchema7, 'type'> & {
47
+ type: Exclude<JSONSchema7['type'], undefined | JSONSchema7TypeName>;
48
+ };
49
+ export type PrimitiveJSONSchema7TypeName = (typeof jsonSchema7PrimitiveTypes)[number];
50
+ export type PrimitiveSchema = Omit<JSONSchema7, 'type'> & {
51
+ type: PrimitiveJSONSchema7TypeName | PrimitiveJSONSchema7TypeName[] | undefined;
52
+ };
42
53
  export type OpenAISchema = {
43
54
  type?: JSONSchema7TypeName | JSONSchema7TypeName[];
44
55
  enum?: JSONSchema7Type[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeshape/json-schema",
3
- "version": "11.104.4",
3
+ "version": "11.105.1",
4
4
  "description": "JSON Schema validator",
5
5
  "homepage": "https://www.takeshape.io",
6
6
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "ajv-formats": "3.0.1",
39
39
  "lodash": "4.17.21",
40
40
  "minimatch": "^3.0.4",
41
- "@takeshape/util": "11.104.4"
41
+ "@takeshape/util": "11.105.1"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/json-schema": "^7.0.7",