Skip to content

Commit ea0ac6f

Browse files
fix(package.json): bump json-schema-tree version (#246)
1 parent c467ab1 commit ea0ac6f

File tree

6 files changed

+109
-11
lines changed

6 files changed

+109
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
"dependencies": {
4848
"@stoplight/json": "^3.20.1",
49-
"@stoplight/json-schema-tree": "^2.3.0",
49+
"@stoplight/json-schema-tree": "^3.0.0",
5050
"@stoplight/react-error-boundary": "^2.0.0",
5151
"@types/json-schema": "^7.0.7",
5252
"classnames": "^2.2.6",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"allOf": [
4+
{
5+
"type": "object",
6+
"properties": {
7+
"AAAAA": { "allOf": [{ "description": "AAAAA", "type": "string" }, { "examples": ["AAAAA"] }] },
8+
"BBBBB": {
9+
"allOf": [
10+
{
11+
"$ref": "#/paths/~1operation/post/requestBody/content/application~1json/schema/allOf/0/properties/AAAAA/allOf/0",
12+
"description": "BBBBB"
13+
},
14+
{ "examples": ["BBBBB"] }
15+
]
16+
}
17+
}
18+
}
19+
]
20+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"paths": {
3+
"/operation": {
4+
"post": {
5+
"summary": "operation",
6+
"requestBody": {
7+
"required": true,
8+
"content": {
9+
"application/json": {
10+
"schema": {
11+
"allOf": [
12+
{
13+
"type": "object",
14+
"properties": {
15+
"AAAAA": { "allOf": [{ "description": "AAAAA", "type": "string" }, { "examples": ["AAAAA"] }] },
16+
"BBBBB": {
17+
"allOf": [
18+
{
19+
"$ref": "#/paths/~1operation/post/requestBody/content/application~1json/schema/allOf/0/properties/AAAAA/allOf/0",
20+
"description": "BBBBB"
21+
},
22+
{ "examples": ["BBBBB"] }
23+
]
24+
}
25+
}
26+
}
27+
]
28+
}
29+
}
30+
}
31+
},
32+
"operationId": "operationId",
33+
"security": []
34+
}
35+
}
36+
},
37+
"servers": [{ "url": "http://example.com" }],
38+
"openapi": "3.1.0",
39+
"info": { "title": "Test", "version": "version" }
40+
}

src/__stories__/Refs.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { Story } from '@storybook/react';
2-
import { JSONSchema4 } from 'json-schema';
2+
import { JSONSchema4, JSONSchema7 } from 'json-schema';
33
import React from 'react';
44

55
import { JsonSchemaProps, JsonSchemaViewer } from '../components/JsonSchemaViewer';
6+
import { defaultResolver } from '../utils/refResolver';
67

78
const defaultSchema = require('../__fixtures__/default-schema.json');
89
const refSchema = require('../__fixtures__/references/base.json');
910
const nullRefSchema = require('../__fixtures__/references/nullish.json');
1011
const brokenRefArraySchema = require('../__fixtures__/arrays/of-refs.json');
12+
const allOfRefSchema = require('../__fixtures__/references/allOfReference.json');
13+
const fullAllOfRefDoc = require('../__fixtures__/references/fullAllOfReference.json');
1114

1215
export default {
1316
component: JsonSchemaViewer,
@@ -26,3 +29,9 @@ Nullish.args = { schema: nullRefSchema as JSONSchema4 };
2629

2730
export const Broken = Template.bind({});
2831
Broken.args = { schema: brokenRefArraySchema as JSONSchema4 };
32+
33+
export const RefResolverAllOfRef = Template.bind({});
34+
RefResolverAllOfRef.args = {
35+
schema: allOfRefSchema as JSONSchema7,
36+
resolveRef: defaultResolver(fullAllOfRefDoc),
37+
};

src/utils/refResolver.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { resolveInlineRef } from '@stoplight/json';
2+
import { Dictionary } from '@stoplight/types';
3+
4+
export type ReferenceInfo = {
5+
source: string | null;
6+
pointer: string | null;
7+
};
8+
9+
export type ReferenceResolver = (ref: ReferenceInfo, propertyPath: string[] | null, currentObject?: object) => any;
10+
11+
export const defaultResolver =
12+
(contextObject: object): ReferenceResolver =>
13+
({ pointer }, _, currentObject) => {
14+
const activeObject = contextObject ?? currentObject;
15+
16+
if (pointer === null) {
17+
return null;
18+
}
19+
20+
if (pointer === '#') {
21+
return activeObject;
22+
}
23+
24+
const resolved = resolveInlineRef(activeObject as Dictionary<string>, pointer);
25+
26+
if (resolved) return resolved;
27+
28+
throw new ReferenceError(`Could not resolve '${pointer}`);
29+
};

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,22 +2383,22 @@
23832383
dependencies:
23842384
eslint-config-prettier "^8.3.0"
23852385

2386-
"@stoplight/json-schema-merge-allof@^0.7.8":
2387-
version "0.7.8"
2388-
resolved "https://registry.yarnpkg.com/@stoplight/json-schema-merge-allof/-/json-schema-merge-allof-0.7.8.tgz#7efe5e0086dff433eb011f617e82f7295c3de061"
2389-
integrity sha512-JTDt6GYpCWQSb7+UW1P91IAp/pcLWis0mmEzWVFcLsrNgtUYK7JLtYYz0ZPSR4QVL0fJ0YQejM+MPq5iNDFO4g==
2386+
"@stoplight/json-schema-merge-allof@^0.8.0":
2387+
version "0.8.0"
2388+
resolved "https://registry.yarnpkg.com/@stoplight/json-schema-merge-allof/-/json-schema-merge-allof-0.8.0.tgz#62f8116f59d9df5a910d037b1965decd2efab472"
2389+
integrity sha512-g8e0s43v96Xbzvd8d6KKUuJTO16CS2oJglJrviUi8ASIUxzFvAJqTHWLtGmpTryisQopqg1evXGJfi0+164+Qw==
23902390
dependencies:
23912391
compute-lcm "^1.1.0"
23922392
json-schema-compare "^0.2.2"
23932393
lodash "^4.17.4"
23942394

2395-
"@stoplight/json-schema-tree@^2.3.0":
2396-
version "2.3.0"
2397-
resolved "https://registry.yarnpkg.com/@stoplight/json-schema-tree/-/json-schema-tree-2.3.0.tgz#cdad7f7571700016d8e0e5bad59d287e9bb782d0"
2398-
integrity sha512-IH4SYuvV0C4maYQEPftduDBG1qVV4hy5ZXzS9rgq3V7zCT34I7xVwX9Vmpl0mOQTh2IZaTcyPWXkngt21ShJaQ==
2395+
"@stoplight/json-schema-tree@^3.0.0":
2396+
version "3.0.0"
2397+
resolved "https://registry.yarnpkg.com/@stoplight/json-schema-tree/-/json-schema-tree-3.0.0.tgz#967cecda59b0dd8efa2275e580d5a8c71868cc3c"
2398+
integrity sha512-lxALWJtl7ev+iTNbW+QHDr66+nmspwrDyVEhNSIjWjp8Vd6+qYxqk3r9zr8Ktfrx4pREfG7iTq6rwNSxYdP+Nw==
23992399
dependencies:
24002400
"@stoplight/json" "^3.12.0"
2401-
"@stoplight/json-schema-merge-allof" "^0.7.8"
2401+
"@stoplight/json-schema-merge-allof" "^0.8.0"
24022402
"@stoplight/lifecycle" "^2.3.2"
24032403
"@types/json-schema" "^7.0.7"
24042404
magic-error "0.0.1"

0 commit comments

Comments
 (0)