diff --git a/docs/source/usage.const.rst b/docs/source/usage.const.rst new file mode 100644 index 0000000..9fd75a4 --- /dev/null +++ b/docs/source/usage.const.rst @@ -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") \ No newline at end of file diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 2b9855f..8896842 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -45,4 +45,5 @@ For more complex schemas and types see our documentation on usage.reference usage.allof usage.anyof - usage.enum \ No newline at end of file + usage.enum + usage.const \ No newline at end of file