-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
core/src/main/java/com/alibaba/fastjson2/schema/UnresolvedReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.alibaba.fastjson2.schema; | ||
|
||
import java.util.Map; | ||
|
||
public class UnresolvedReference | ||
extends JSONSchema { | ||
final String refName; | ||
UnresolvedReference(String refName) { | ||
super(null, null); | ||
this.refName = refName; | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return Type.UnresolvedReference; | ||
} | ||
|
||
@Override | ||
public ValidateResult validate(Object value) { | ||
return JSONSchema.SUCCESS; | ||
} | ||
|
||
abstract static class ResolveTask { | ||
abstract void resolve(JSONSchema root); | ||
} | ||
|
||
static class PropertyResolveTask | ||
extends ResolveTask { | ||
final Map<String, JSONSchema> properties; | ||
final String entryKey; | ||
final String refName; | ||
|
||
PropertyResolveTask(Map<String, JSONSchema> properties, String entryKey, String refName) { | ||
this.properties = properties; | ||
this.entryKey = entryKey; | ||
this.refName = refName; | ||
} | ||
|
||
@Override | ||
void resolve(JSONSchema root) { | ||
Map<String, JSONSchema> defs = null; | ||
if (root instanceof ObjectSchema) { | ||
defs = ((ObjectSchema) root).defs; | ||
} else if (root instanceof ArraySchema) { | ||
defs = ((ArraySchema) root).defs; | ||
} | ||
|
||
if (defs == null) { | ||
return; | ||
} | ||
|
||
JSONSchema refSchema = defs.get(refName); | ||
if (refSchema != null) { | ||
properties.put(entryKey, refSchema); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters