Skip to content

Commit

Permalink
fix: circular reference
Browse files Browse the repository at this point in the history
  • Loading branch information
legends-killer committed Mar 18, 2024
1 parent cffee52 commit 95f974c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yaje",
"version": "1.2.1",
"version": "1.2.2",
"author": "legends-killer <yyy@legends-killer.cq.cn>",
"description": "yet another json editor",
"keywords": [
Expand Down
12 changes: 8 additions & 4 deletions src/JsonEditor/helper/jsonSchemaProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: legends-killer
* @Date: 2023-12-27 21:58:54
* @LastEditors: legends-killer
* @LastEditTime: 2024-01-31 23:31:10
* @LastEditTime: 2024-03-18 23:26:25
* @Description:
*/

Expand All @@ -29,7 +29,7 @@ export class JsonSchemaProcessor {
return this.schema.definitions[refName] ?? {}
}

private deRef(currentDefinition: any) {
private deRef(currentDefinition: any, visited: string[]) {
const properties = currentDefinition.properties
const res = {} as any
if (!properties) return res
Expand All @@ -38,8 +38,12 @@ export class JsonSchemaProcessor {
if (value.$ref?.length) {
const cachedDeRefResult = this.deRefCache.get(value.$ref)
if (cachedDeRefResult) res[key] = cachedDeRefResult
else if (visited.includes(value.$ref)) {
res[key] = {title: '', description: `Repeate Reference: ${value.$ref}`, type: "string", properties: {}}
}
else {
const deRefResult = this.deRef(this.getSchemaByRef(value.$ref))
visited.push(value.$ref)
const deRefResult = this.deRef(this.getSchemaByRef(value.$ref), visited)
res[key] = deRefResult
this.deRefCache.set(value.$ref, deRefResult)
}
Expand Down Expand Up @@ -112,7 +116,7 @@ export class JsonSchemaProcessor {
const definitions = { ...this.schema.definitions, ...this.schema.properties }
for (const [key, val] of Object.entries<any>(definitions)) {
if (val.type === 'object') {
const deRefedDefinition = this.deRef(val)
const deRefedDefinition = this.deRef(val, [])

valueSuggestions.push({
title: key,
Expand Down

0 comments on commit 95f974c

Please sign in to comment.