[Feature] Adds Enums #28
37
docs/source/usage.enum.rst
Normal file
37
docs/source/usage.enum.rst
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
Enum Type
|
||||||
|
==================
|
||||||
|
|
||||||
|
An enum type is a special data type that enables a variable to be a set of predefined constants. The enum type is used to define variables that can only take one out of a small set of possible values.
|
||||||
|
|
||||||
|
It does not have any specific properties, but it has the generic properties:
|
||||||
|
|
||||||
|
- default: Default value for the enum.
|
||||||
|
- description: Description of the enum field.
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
from jambo import SchemaConverter
|
||||||
|
|
||||||
|
schema = {
|
||||||
|
"title": "EnumExample",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"status": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["active", "inactive", "pending"],
|
||||||
|
"description": "The status of the object.",
|
||||||
|
"default": "active",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": ["status"],
|
||||||
|
}
|
||||||
|
|
||||||
|
Model = SchemaConverter.build(schema)
|
||||||
|
|
||||||
|
obj = Model(status="active")
|
||||||
|
print(obj) # Output: EnumExample(status=status.ACTIVE)
|
||||||
@@ -45,3 +45,4 @@ For more complex schemas and types see our documentation on
|
|||||||
usage.reference
|
usage.reference
|
||||||
usage.allof
|
usage.allof
|
||||||
usage.anyof
|
usage.anyof
|
||||||
|
usage.enum
|
||||||
@@ -50,6 +50,7 @@ repository = "https://github.com/HideyoshiNakazone/jambo.git"
|
|||||||
create-hooks = "bash .githooks/set-hooks.sh"
|
create-hooks = "bash .githooks/set-hooks.sh"
|
||||||
tests = "python -m coverage run -m unittest discover -v"
|
tests = "python -m coverage run -m unittest discover -v"
|
||||||
tests-report = "python -m coverage xml"
|
tests-report = "python -m coverage xml"
|
||||||
|
serve-docs = "sphinx-autobuild docs/source docs/build"
|
||||||
|
|
||||||
# Build System
|
# Build System
|
||||||
[tool.hatch.version]
|
[tool.hatch.version]
|
||||||
|
|||||||
Reference in New Issue
Block a user