Feature/adds const #30
40
docs/source/usage.const.rst
Normal file
40
docs/source/usage.const.rst
Normal file
@@ -0,0 +1,40 @@
|
||||
Const Type
|
||||
=================
|
||||
|
||||
The const type is a special data type that allows a variable to be a single, fixed value.
|
||||
It does not have the same properties as the other generic types, but it has the following specific properties:
|
||||
|
||||
- const: The fixed value that the variable must always hold.
|
||||
- description: Description of the const field.
|
||||
|
||||
|
||||
Examples
|
||||
-----------------
|
||||
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from jambo import SchemaConverter
|
||||
|
||||
|
||||
schema = {
|
||||
"title": "Country",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"const": "United States of America",
|
||||
}
|
||||
},
|
||||
"required": ["name"],
|
||||
}
|
||||
|
||||
Model = SchemaConverter.build(schema)
|
||||
|
||||
obj = Model()
|
||||
self.assertEqual(obj.name, "United States of America")
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
obj.name = "Canada"
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
Model(name="Canada")
|
||||
@@ -45,4 +45,5 @@ For more complex schemas and types see our documentation on
|
||||
usage.reference
|
||||
usage.allof
|
||||
usage.anyof
|
||||
usage.enum
|
||||
usage.enum
|
||||
usage.const
|
||||
Reference in New Issue
Block a user