fast-json-stringify 5.0.3 → 5.0.6

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.
package/index.js CHANGED
@@ -55,7 +55,7 @@ function resolveRef (location, ref) {
55
55
  }
56
56
 
57
57
  const schemaId = ref.slice(0, hashIndex) || location.schemaId
58
- const jsonPointer = ref.slice(hashIndex)
58
+ const jsonPointer = ref.slice(hashIndex) || '#'
59
59
 
60
60
  const schemaRef = schemaId + jsonPointer
61
61
 
@@ -489,6 +489,11 @@ function mergeAllOfSchema (location, schema, mergedSchema) {
489
489
  }
490
490
  }
491
491
  delete mergedSchema.allOf
492
+
493
+ mergedSchema.$id = `merged_${randomUUID()}`
494
+ ajvInstance.addSchema(mergedSchema)
495
+ location.schemaId = mergedSchema.$id
496
+ location.jsonPointer = '#'
492
497
  }
493
498
 
494
499
  function buildInnerObject (location) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-json-stringify",
3
- "version": "5.0.3",
3
+ "version": "5.0.6",
4
4
  "description": "Stringify your JSON at max speed",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "homepage": "https://github.com/fastify/fast-json-stringify#readme",
35
35
  "devDependencies": {
36
- "@sinclair/typebox": "^0.23.3",
36
+ "@sinclair/typebox": "^0.24.9",
37
37
  "benchmark": "^2.1.4",
38
38
  "cli-select": "^1.1.2",
39
39
  "compile-json-stringify": "^0.1.2",
@@ -0,0 +1,57 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('tap')
4
+ const build = require('..')
5
+
6
+ test('should validate anyOf after allOf merge', (t) => {
7
+ t.plan(1)
8
+
9
+ const schema = {
10
+ $id: 'schema',
11
+ type: 'object',
12
+ allOf: [
13
+ {
14
+ $id: 'base',
15
+ type: 'object',
16
+ properties: {
17
+ name: {
18
+ type: 'string'
19
+ }
20
+ },
21
+ required: [
22
+ 'name'
23
+ ]
24
+ },
25
+ {
26
+ $id: 'inner_schema',
27
+ type: 'object',
28
+ properties: {
29
+ union: {
30
+ $id: '#id',
31
+ anyOf: [
32
+ {
33
+
34
+ $id: 'guid',
35
+ type: 'string'
36
+ },
37
+ {
38
+
39
+ $id: 'email',
40
+ type: 'string'
41
+ }
42
+ ]
43
+ }
44
+ },
45
+ required: [
46
+ 'union'
47
+ ]
48
+ }
49
+ ]
50
+ }
51
+
52
+ const stringify = build(schema)
53
+
54
+ t.equal(
55
+ stringify({ name: 'foo', union: 'a8f1cc50-5530-5c62-9109-5ba9589a6ae1' }),
56
+ '{"name":"foo","union":"a8f1cc50-5530-5c62-9109-5ba9589a6ae1"}')
57
+ })
package/test/ref.test.js CHANGED
@@ -1891,3 +1891,65 @@ test('input schema is not mutated', (t) => {
1891
1891
  t.equal(output, '{"obj":"test"}')
1892
1892
  t.same(schema, clonedSchema)
1893
1893
  })
1894
+
1895
+ test('anyOf inside allOf', (t) => {
1896
+ t.plan(1)
1897
+
1898
+ const schema = {
1899
+ anyOf: [
1900
+ {
1901
+ type: 'object',
1902
+ allOf: [
1903
+ {
1904
+ properties: {
1905
+ a: {
1906
+ anyOf: [
1907
+ { const: 'A1' },
1908
+ { const: 'A2' }
1909
+ ]
1910
+ }
1911
+ }
1912
+ },
1913
+ {
1914
+ properties: {
1915
+ b: { const: 'B' }
1916
+ }
1917
+ }
1918
+ ]
1919
+ }
1920
+ ]
1921
+ }
1922
+
1923
+ const object = { a: 'A1', b: 'B' }
1924
+ const stringify = build(schema)
1925
+ const output = stringify(object)
1926
+
1927
+ t.equal(output, JSON.stringify(object))
1928
+ })
1929
+
1930
+ test('should resolve absolute $refs', (t) => {
1931
+ t.plan(1)
1932
+
1933
+ const externalSchema = {
1934
+ FooSchema: {
1935
+ $id: 'FooSchema',
1936
+ type: 'object',
1937
+ properties: {
1938
+ type: {
1939
+ anyOf: [
1940
+ { type: 'string', const: 'bar' },
1941
+ { type: 'string', const: 'baz' }
1942
+ ]
1943
+ }
1944
+ }
1945
+ }
1946
+ }
1947
+
1948
+ const schema = { $ref: 'FooSchema' }
1949
+
1950
+ const object = { type: 'bar' }
1951
+ const stringify = build(schema, { schema: externalSchema })
1952
+ const output = stringify(object)
1953
+
1954
+ t.equal(output, JSON.stringify(object))
1955
+ })