[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)
|
||||
@@ -44,4 +44,5 @@ For more complex schemas and types see our documentation on
|
||||
usage.object
|
||||
usage.reference
|
||||
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"
|
||||
tests = "python -m coverage run -m unittest discover -v"
|
||||
tests-report = "python -m coverage xml"
|
||||
serve-docs = "sphinx-autobuild docs/source docs/build"
|
||||
|
||||
# Build System
|
||||
[tool.hatch.version]
|
||||
|
||||
Reference in New Issue
Block a user