python-pydantic-v1.model_enum.mustache Maven / Gradle / Ivy
import json
import pprint
import re # noqa: F401
from aenum import Enum, no_arg
{{#vendorExtensions.x-py-datetime-imports}}{{#-first}}from datetime import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-datetime-imports}}
{{#vendorExtensions.x-py-typing-imports}}{{#-first}}from typing import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-typing-imports}}
{{#vendorExtensions.x-py-pydantic-imports}}{{#-first}}from pydantic import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-pydantic-imports}}
class {{classname}}({{vendorExtensions.x-py-enum-type}}, Enum):
"""
{{{description}}}{{^description}}{{{classname}}}{{/description}}
"""
"""
allowed enum values
"""
{{#allowableValues}}
{{#enumVars}}
{{{name}}} = {{{value}}}
{{/enumVars}}
@classmethod
def from_json(cls, json_str: str) -> {{{classname}}}:
"""Create an instance of {{classname}} from a JSON string"""
return {{classname}}(json.loads(json_str))
{{#defaultValue}}
#
@classmethod
def _missing_value_(cls, value):
if value is no_arg:
return cls.{{{.}}}
{{/defaultValue}}
{{/allowableValues}}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy