Feature/adds const #30

Merged
HideyoshiNakazone merged 3 commits from feature/adds-const into main 2025-06-23 18:32:37 +00:00
2 changed files with 42 additions and 1 deletions
Showing only changes of commit 60ac12fe39 - Show all commits

View 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")

View File

@@ -46,3 +46,4 @@ For more complex schemas and types see our documentation on
usage.allof
usage.anyof
usage.enum
usage.const