Skip to content

Commit 26469cd

Browse files
committedSep 27, 2018
horejsek#29 Fix string in const
1 parent acec3cb commit 26469cd

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed
 

‎CHANGELOG.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
=== 2.4 (unreleased)
22

33
* Fix overriding variables (in pattern properties, property names, unique items and contains)
4+
* Fix string in const
45

56

67
=== 2.3 (2018-09-14) ===

‎fastjsonschema/draft06.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,8 @@ def generate_const(self):
170170
171171
Only valid value is 42 in this example.
172172
"""
173-
with self.l('if {variable} != {}:', self._definition['const']):
173+
const = self._definition['const']
174+
if isinstance(const, str):
175+
const = '"{}"'.format(const)
176+
with self.l('if {variable} != {}:', const):
174177
self.l('raise JsonSchemaException("{name} must be same as const definition")')

‎tests/test_const.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pytest
2+
3+
4+
@pytest.mark.parametrize('value', (
5+
'foo',
6+
42,
7+
False,
8+
[1, 2, 3]
9+
))
10+
def test_const(asserter, value):
11+
asserter({
12+
'$schema': 'http://json-schema.org/draft-06/schema',
13+
'const': value,
14+
}, value, value)

0 commit comments

Comments
 (0)
Please sign in to comment.