import datetime
import decimal
from marshmallow.fields import *
from servicestack import *
from typing import *
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, LetterCase, Undefined, config
from enum import Enum, IntEnum
class EnumType(str, Enum):
VALUE1 = 'Value1'
VALUE2 = 'Value2'
VALUE3 = 'Value3'
class EnumWithValues(str, Enum):
NONE = 'None'
VALUE1 = 'Member 1'
VALUE2 = 'Value2'
# @Flags()
class EnumFlags(IntEnum):
VALUE0 = 0
VALUE1 = 1
VALUE2 = 2
VALUE3 = 4
VALUE123 = 7
class EnumStyle(str, Enum):
LOWER = 'lower'
UPPER = 'UPPER'
PASCAL_CASE = 'PascalCase'
CAMEL_CASE = 'camelCase'
CAMEL_U_P_P_E_R = 'camelUPPER'
PASCAL_U_P_P_E_R = 'PascalUPPER'
@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@dataclass
class HelloWithEnumMap:
enum_prop: Dict[str, EnumType] = field(default_factory=dict)
enum_with_values: Dict[str, EnumWithValues] = field(default_factory=dict)
nullable_enum_prop: Dict[str, EnumType] = field(default_factory=dict)
enum_flags: Dict[str, EnumFlags] = field(default_factory=dict)
enum_style: Dict[str, EnumStyle] = field(default_factory=dict)
To override the Content-type in your clients, use the HTTP Accept Header, append the .json suffix or ?format=json
To embed the response in a jsonp callback, append ?callback=myCallback
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /json/oneway/HelloWithEnumMap HTTP/1.1
Host: test.servicestack.net
Accept: application/json
Content-Type: application/json
Content-Length: length
{"enumProp":{"Value1":"Value1"},"enumWithValues":{"None":"None"},"nullableEnumProp":{"Value1":"Value1"},"enumFlags":{"0":0},"enumStyle":{"lower":"lower"}}