Skip to content

Commit 629c298

Browse files
committed
resolve name_arg when following references
resolve the varaible name when creating path prefixes for references. without this the errors end up as `data.{data_key} must be string` instead of `data.a must be string`
1 parent 76994a0 commit 629c298

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

fastjsonschema/generator.py

+2
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ def generate_ref(self):
201201
assert self._variable_name.startswith("data")
202202
path = self._variable_name[4:]
203203
name_arg = '(name_prefix or "data") + "{}"'.format(path)
204+
if '{' in name_arg:
205+
name_arg = name_arg + '.format(**locals())'
204206
self.l('{}({variable}, custom_formats, {name_arg})', name, name_arg=name_arg)
205207

206208

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data.a must be string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"a": 1
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"type": "object",
3+
"additionalProperties": {
4+
"$ref": "#/definitions/a-ref"
5+
},
6+
"definitions": {
7+
"a-ref": {
8+
"type": "string"
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)