<commit_before># -*- coding: utf-8 -*-

import json
from copy import deepcopy
from marshmallow import Schema, fields, post_load
from marshmallow.validate import OneOf
from models import *


def PartialSchemaFactory(schema_cls):
    schema = schema_cls(partial=True)
    for field_name, field in schema.fields.items():
        if isinstance(field, fields.Nested):
            new_field = deepcopy(field)
            new_field.schema.partial = True
            schema.fields[field_name] = new_field
    return schema

def load_json(str):
    print ">>>>>>>>>>", str
    try:
        return json.loads(str)
    except:
        return "Error loading JSON"

# region Protected
class KeyValueSchema(Schema):
    name = fields.String(required=True)
    value = fields.String(required=True)


class KeyValuePairExecuteRequestSchema(KeyValueSchema):
    pass


# endregion


class ApplicationListResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    description = fields.String(required=True)
    enabled = fields.Boolean(required=True, missing=True,
                             default=True)
    type = fields.String(required=True,
                         validate=[OneOf(ApplicationType.__dict__.keys())])
    execution_parameters = fields.Function(lambda x: load_json(x.execution_parameters))

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Application"""
        return Application(**data)

    class Meta:
        ordered = True


class ApplicationItemResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    description = fields.String(required=True)
    enabled = fields.Boolean(required=True, missing=True,
                             default=True)
    type = fields.String(required=True,
                         validate=[OneOf(ApplicationType.__dict__.keys())])
    execution_parameters = fields.Function(lambda x: load_json(x.execution_parameters))

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Application"""
        return Application(**data)

    class Meta:
        ordered = True


class FlowListResponseSchema(Schema):
    """ JSON schema for listing """
    source_port = fields.Integer(required=True)
    target_port = fields.Integer(required=True)
    source_id = fields.String(required=True)
    target_id = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Flow"""
        return Flow(**data)

    class Meta:
        ordered = True


class FlowItemResponseSchema(Schema):
    """ JSON schema for listing """
    source_port = fields.Integer(required=True)
    target_port = fields.Integer(required=True)
    source_id = fields.String(required=True)
    target_id = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Flow"""
        return Flow(**data)

    class Meta:
        ordered = True


class FlowCreateRequestSchema(Schema):
    """ JSON schema for new instance """
    source_port = fields.Integer(required=True)
    target_port = fields.Integer(required=True)
    source_id = fields.String(required=True)
    target_id = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Flow"""
        return Flow(**data)

    class Meta:
        ordered = True


class OperationSimpleListResponseSchema(Schema):
    """ JSON simple """
    id = fields.Integer()
    name = fields.String(required=False)
    slug = fields.String(required=False)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Operation"""
        return Operation(**data)

    class Meta:
        ordered = True


class OperationListResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    slug = fields.String(required=True)
    enabled = fields.Boolean(required=True)
    description = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(OperationType.__dict__.keys())])
    icon = fields.String(required=True)
    categories = fields.Nested('schema.OperationCategoryListResponseSchema',
                               many=True)
    forms = fields.Nested('schema.OperationFormListResponseSchema',
                          many=True)
    ports = fields.Nested('schema.OperationPortListResponseSchema',
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Operation"""
        return Operation(**data)

    class Meta:
        ordered = True


class OperationCreateRequestSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    slug = fields.String(required=True)
    enabled = fields.Boolean(required=True)
    description = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(OperationType.__dict__.keys())])
    icon = fields.String(required=True)
    categories = fields.Nested('schema.OperationCategoryCreateRequestSchema',
                               many=True)
    forms = fields.Nested('schema.OperationFormCreateRequestSchema',
                          many=True)
    ports = fields.Nested('schema.OperationPortCreateRequestSchema',
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Operation"""
        return Operation(**data)

    class Meta:
        ordered = True


class OperationItemResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    slug = fields.String(required=True)
    enabled = fields.Boolean(required=True)
    description = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(OperationType.__dict__.keys())])
    icon = fields.String(required=True)
    categories = fields.Nested('schema.OperationCategoryItemResponseSchema',
                               many=True)
    forms = fields.Nested('schema.OperationFormItemResponseSchema',
                          many=True)
    ports = fields.Nested('schema.OperationPortItemResponseSchema',
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Operation"""
        return Operation(**data)

    class Meta:
        ordered = True


class OperationUpdateRequestSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=False)
    slug = fields.String(required=False)
    enabled = fields.Boolean(required=False)
    description = fields.String(required=False)
    type = fields.String(required=False,
                         validate=[OneOf(OperationType.__dict__.keys())])
    icon = fields.String(required=False)
    categories = fields.Nested('schema.OperationCategoryUpdateRequestSchema',
                               required=True,
                               many=True)
    forms = fields.Nested('schema.OperationFormUpdateRequestSchema',
                          required=True,
                          many=True)
    ports = fields.Nested('schema.OperationPortUpdateRequestSchema',
                          required=True,
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Operation"""
        return Operation(**data)

    class Meta:
        ordered = True


class OperationCategoryCreateRequestSchema(Schema):
    """ JSON schema for request """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    type = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationCategory"""
        return OperationCategory(**data)

    class Meta:
        ordered = True


class OperationCategoryListResponseSchema(Schema):
    """ JSON schema for response """
    name = fields.String(required=True)
    type = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationCategory"""
        return OperationCategory(**data)

    class Meta:
        ordered = True


class OperationCategoryItemResponseSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    type = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationCategory"""
        return OperationCategory(**data)

    class Meta:
        ordered = True


class OperationFormListResponseSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    enabled = fields.Boolean(required=True, missing=True,
                             default=True)
    order = fields.Integer(required=True)
    fields = fields.Nested('schema.OperationFormFieldListResponseSchema',
                           many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationForm"""
        return OperationForm(**data)

    class Meta:
        ordered = True


class OperationFormCreateRequestSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    enabled = fields.Boolean(required=True, missing=True,
                             default=True)
    order = fields.Integer(required=True)
    fields = fields.Nested('schema.OperationFormFieldCreateRequestSchema',
                           many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationForm"""
        return OperationForm(**data)

    class Meta:
        ordered = True


class OperationFormItemResponseSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    enabled = fields.Boolean(required=True, missing=True,
                             default=True)
    order = fields.Integer(required=True)
    fields = fields.Nested('schema.OperationFormFieldItemResponseSchema',
                           many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationForm"""
        return OperationForm(**data)

    class Meta:
        ordered = True


class OperationFormFieldListResponseSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    label = fields.String(required=True)
    help = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(DataType.__dict__.keys())])
    required = fields.Boolean(required=True)
    order = fields.Integer(required=True)
    default = fields.String(required=True)
    suggested_widget = fields.String(required=False)
    values_url = fields.String(required=False)
    values = fields.String(required=False)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationFormField"""
        return OperationFormField(**data)

    class Meta:
        ordered = True


class OperationFormFieldCreateRequestSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    label = fields.String(required=True)
    help = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(DataType.__dict__.keys())])
    required = fields.Boolean(required=True)
    order = fields.Integer(required=True)
    default = fields.String(required=True)
    suggested_widget = fields.String(required=False)
    values_url = fields.String(required=False)
    values = fields.String(required=False)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationFormField"""
        return OperationFormField(**data)

    class Meta:
        ordered = True


class OperationFormFieldItemResponseSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    label = fields.String(required=True)
    help = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(DataType.__dict__.keys())])
    required = fields.Boolean(required=True)
    order = fields.Integer(required=True)
    default = fields.String(required=True)
    suggested_widget = fields.String(required=False)
    values_url = fields.String(required=False)
    values = fields.String(required=False)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationFormField"""
        return OperationFormField(**data)

    class Meta:
        ordered = True


class OperationPortListResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(OperationPortType.__dict__.keys())])
    description = fields.String(required=True)
    tags = fields.String(required=False)
    order = fields.Integer(required=False)
    multiplicity = fields.String(required=True, missing=1,
                                  default=1,
                                 validate=[OneOf(OperationPortMultiplicity.__dict__.keys())])
    interfaces = fields.Nested('schema.OperationPortInterfaceListResponseSchema',
                               many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationPort"""
        return OperationPort(**data)

    class Meta:
        ordered = True


class OperationPortCreateRequestSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(OperationPortType.__dict__.keys())])
    description = fields.String(required=True)
    tags = fields.String(required=False)
    order = fields.Integer(required=False)
    multiplicity = fields.String(required=True, missing=1,
                                  default=1,
                                 validate=[OneOf(OperationPortMultiplicity.__dict__.keys())])
    interfaces = fields.Nested('schema.OperationPortInterfaceCreateRequestSchema',
                               many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationPort"""
        return OperationPort(**data)

    class Meta:
        ordered = True


class OperationPortItemResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(OperationPortType.__dict__.keys())])
    description = fields.String(required=True)
    tags = fields.String(required=False)
    order = fields.Integer(required=False)
    multiplicity = fields.String(required=True, missing=1,
                                  default=1,
                                 validate=[OneOf(OperationPortMultiplicity.__dict__.keys())])
    interfaces = fields.Nested('schema.OperationPortInterfaceItemResponseSchema',
                               many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationPort"""
        return OperationPort(**data)

    class Meta:
        ordered = True


class OperationPortInterfaceCreateRequestSchema(Schema):
    """ JSON schema for request """
    id = fields.Integer(required=True)
    name = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationPortInterface"""
        return OperationPortInterface(**data)

    class Meta:
        ordered = True


class OperationPortInterfaceListResponseSchema(Schema):
    """ JSON schema for response """
    name = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationPortInterface"""
        return OperationPortInterface(**data)

    class Meta:
        ordered = True


class OperationPortInterfaceItemResponseSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationPortInterface"""
        return OperationPortInterface(**data)

    class Meta:
        ordered = True


class TaskListResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.String(required=True)
    left = fields.Integer(required=True)
    top = fields.Integer(required=True)
    z_index = fields.Integer(required=True)
    forms = fields.Function(lambda x: load_json(x.forms))
    operation = fields.Nested('schema.OperationSimpleListResponseSchema')

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Task"""
        return Task(**data)

    class Meta:
        ordered = True


class TaskCreateRequestSchema(Schema):
    """ JSON serialization schema """
    id = fields.String(required=True)
    left = fields.Integer(required=True)
    top = fields.Integer(required=True)
    z_index = fields.Integer(required=True)
    forms = fields.Dict(required=True)
    operation_id = fields.Integer(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Task"""
        data['forms'] = json.dumps(data['forms'])
        return Task(**data)

    class Meta:
        ordered = True


class TaskItemResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.String(required=True)
    left = fields.Integer(required=True)
    top = fields.Integer(required=True)
    z_index = fields.Integer(required=True)
    forms = fields.Function(lambda x: load_json(x.forms))
    operation = fields.Nested('schema.OperationSimpleListResponseSchema')

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Task"""
        return Task(**data)

    class Meta:
        ordered = True


class TaskExecuteRequestSchema(Schema):
    """ JSON schema for executing tasks """
    id = fields.String(required=True)
    left = fields.Integer(required=True)
    top = fields.Integer(required=True)
    z_index = fields.Integer(required=True)
    forms = fields.String(required=True)
    next_task_id = fields.Integer()
    operation = fields.Nested('schema.OperationExecuteRequestSchema')
    parameters = fields.Nested('schema.KeyValuePairExecuteRequestSchema',
                               many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Task"""
        return Task(**data)

    class Meta:
        ordered = True


class WorkflowExecuteRequestSchema(Schema):
    """ JSON schema for executing workflow """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    description = fields.String(required=False)
    user_id = fields.Integer(required=True)
    user_login = fields.String(required=True)
    user_name = fields.String(required=True)
    created = fields.DateTime(required=True, missing=datetime.datetime.utcnow,
                             default=datetime.datetime.utcnow)
    updated = fields.DateTime(required=True, missing=datetime.datetime.utcnow,
                             default=datetime.datetime.utcnow)
    version = fields.Integer(required=True)
    tasks = fields.Nested('schema.TaskExecuteRequestSchema',
                          many=True)
    flows = fields.Nested('schema.FlowExecuteRequestSchema',
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Workflow"""
        return Workflow(**data)

    class Meta:
        ordered = True


class WorkflowListResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    description = fields.String(required=False)
    user_id = fields.Integer(required=True)
    user_login = fields.String(required=True)
    user_name = fields.String(required=True)
    created = fields.DateTime(required=True, missing=datetime.datetime.utcnow,
                             default=datetime.datetime.utcnow)
    updated = fields.DateTime(required=True, missing=datetime.datetime.utcnow,
                             default=datetime.datetime.utcnow)
    version = fields.Integer(required=True)
    tasks = fields.Nested('schema.TaskListResponseSchema',
                          many=True)
    flows = fields.Nested('schema.FlowListResponseSchema',
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Workflow"""
        return Workflow(**data)

    class Meta:
        ordered = True


class WorkflowCreateRequestSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    description = fields.String(required=False)
    user_id = fields.Integer(required=True)
    user_login = fields.String(required=True)
    user_name = fields.String(required=True)
    tasks = fields.Nested('schema.TaskCreateRequestSchema',
                          many=True)
    flows = fields.Nested('schema.FlowCreateRequestSchema',
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Workflow"""
        return Workflow(**data)

    class Meta:
        ordered = True


class WorkflowItemResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    description = fields.String(required=False)
    user_id = fields.Integer(required=True)
    user_login = fields.String(required=True)
    user_name = fields.String(required=True)
    created = fields.DateTime(required=True, missing=datetime.datetime.utcnow,
                             default=datetime.datetime.utcnow)
    updated = fields.DateTime(required=True, missing=datetime.datetime.utcnow,
                             default=datetime.datetime.utcnow)
    version = fields.Integer(required=True)
    tasks = fields.Nested('schema.TaskItemResponseSchema',
                          many=True)
    flows = fields.Nested('schema.FlowItemResponseSchema',
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Workflow"""<commit_msg>Optional fields now support null values during JSON deserialization<commit_after># -*- coding: utf-8 -*-

import json
from copy import deepcopy
from marshmallow import Schema, fields, post_load
from marshmallow.validate import OneOf
from models import *


def PartialSchemaFactory(schema_cls):
    schema = schema_cls(partial=True)
    for field_name, field in schema.fields.items():
        if isinstance(field, fields.Nested):
            new_field = deepcopy(field)
            new_field.schema.partial = True
            schema.fields[field_name] = new_field
    return schema

def load_json(str):
    try:
        return json.loads(str)
    except:
        return "Error loading JSON"

# region Protected
class KeyValueSchema(Schema):
    name = fields.String(required=True)
    value = fields.String(required=True)


class KeyValuePairExecuteRequestSchema(KeyValueSchema):
    pass


# endregion


class ApplicationListResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    description = fields.String(required=True)
    enabled = fields.Boolean(required=True, missing=True,
                             default=True)
    type = fields.String(required=True,
                         validate=[OneOf(ApplicationType.__dict__.keys())])
    execution_parameters = fields.Function(lambda x: load_json(x.execution_parameters))

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Application"""
        return Application(**data)

    class Meta:
        ordered = True


class ApplicationItemResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    description = fields.String(required=True)
    enabled = fields.Boolean(required=True, missing=True,
                             default=True)
    type = fields.String(required=True,
                         validate=[OneOf(ApplicationType.__dict__.keys())])
    execution_parameters = fields.Function(lambda x: load_json(x.execution_parameters))

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Application"""
        return Application(**data)

    class Meta:
        ordered = True


class FlowListResponseSchema(Schema):
    """ JSON schema for listing """
    source_port = fields.Integer(required=True)
    target_port = fields.Integer(required=True)
    source_id = fields.String(required=True)
    target_id = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Flow"""
        return Flow(**data)

    class Meta:
        ordered = True


class FlowItemResponseSchema(Schema):
    """ JSON schema for listing """
    source_port = fields.Integer(required=True)
    target_port = fields.Integer(required=True)
    source_id = fields.String(required=True)
    target_id = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Flow"""
        return Flow(**data)

    class Meta:
        ordered = True


class FlowCreateRequestSchema(Schema):
    """ JSON schema for new instance """
    source_port = fields.Integer(required=True)
    target_port = fields.Integer(required=True)
    source_id = fields.String(required=True)
    target_id = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Flow"""
        return Flow(**data)

    class Meta:
        ordered = True


class OperationSimpleListResponseSchema(Schema):
    """ JSON simple """
    id = fields.Integer(allow_none=True)
    name = fields.String(required=False, allow_none=True)
    slug = fields.String(required=False, allow_none=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Operation"""
        return Operation(**data)

    class Meta:
        ordered = True


class OperationListResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    slug = fields.String(required=True)
    enabled = fields.Boolean(required=True)
    description = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(OperationType.__dict__.keys())])
    icon = fields.String(required=True)
    categories = fields.Nested('schema.OperationCategoryListResponseSchema',
                               allow_none=True,
                               many=True)
    forms = fields.Nested('schema.OperationFormListResponseSchema',
                          allow_none=True,
                          many=True)
    ports = fields.Nested('schema.OperationPortListResponseSchema',
                          allow_none=True,
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Operation"""
        return Operation(**data)

    class Meta:
        ordered = True


class OperationCreateRequestSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    slug = fields.String(required=True)
    enabled = fields.Boolean(required=True)
    description = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(OperationType.__dict__.keys())])
    icon = fields.String(required=True)
    categories = fields.Nested('schema.OperationCategoryCreateRequestSchema',
                               allow_none=True,
                               many=True)
    forms = fields.Nested('schema.OperationFormCreateRequestSchema',
                          allow_none=True,
                          many=True)
    ports = fields.Nested('schema.OperationPortCreateRequestSchema',
                          allow_none=True,
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Operation"""
        return Operation(**data)

    class Meta:
        ordered = True


class OperationItemResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    slug = fields.String(required=True)
    enabled = fields.Boolean(required=True)
    description = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(OperationType.__dict__.keys())])
    icon = fields.String(required=True)
    categories = fields.Nested('schema.OperationCategoryItemResponseSchema',
                               allow_none=True,
                               many=True)
    forms = fields.Nested('schema.OperationFormItemResponseSchema',
                          allow_none=True,
                          many=True)
    ports = fields.Nested('schema.OperationPortItemResponseSchema',
                          allow_none=True,
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Operation"""
        return Operation(**data)

    class Meta:
        ordered = True


class OperationUpdateRequestSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=False, allow_none=True)
    slug = fields.String(required=False, allow_none=True)
    enabled = fields.Boolean(required=False, allow_none=True)
    description = fields.String(required=False, allow_none=True)
    type = fields.String(required=False, allow_none=True,
                         validate=[OneOf(OperationType.__dict__.keys())])
    icon = fields.String(required=False, allow_none=True)
    categories = fields.Nested('schema.OperationCategoryUpdateRequestSchema',
                               required=True,
                               many=True)
    forms = fields.Nested('schema.OperationFormUpdateRequestSchema',
                          required=True,
                          many=True)
    ports = fields.Nested('schema.OperationPortUpdateRequestSchema',
                          required=True,
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Operation"""
        return Operation(**data)

    class Meta:
        ordered = True


class OperationCategoryCreateRequestSchema(Schema):
    """ JSON schema for request """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    type = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationCategory"""
        return OperationCategory(**data)

    class Meta:
        ordered = True


class OperationCategoryListResponseSchema(Schema):
    """ JSON schema for response """
    name = fields.String(required=True)
    type = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationCategory"""
        return OperationCategory(**data)

    class Meta:
        ordered = True


class OperationCategoryItemResponseSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    type = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationCategory"""
        return OperationCategory(**data)

    class Meta:
        ordered = True


class OperationFormListResponseSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    enabled = fields.Boolean(required=True, missing=True,
                             default=True)
    order = fields.Integer(required=True)
    fields = fields.Nested('schema.OperationFormFieldListResponseSchema',
                           allow_none=True,
                           many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationForm"""
        return OperationForm(**data)

    class Meta:
        ordered = True


class OperationFormCreateRequestSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    enabled = fields.Boolean(required=True, missing=True,
                             default=True)
    order = fields.Integer(required=True)
    fields = fields.Nested('schema.OperationFormFieldCreateRequestSchema',
                           allow_none=True,
                           many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationForm"""
        return OperationForm(**data)

    class Meta:
        ordered = True


class OperationFormItemResponseSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    enabled = fields.Boolean(required=True, missing=True,
                             default=True)
    order = fields.Integer(required=True)
    fields = fields.Nested('schema.OperationFormFieldItemResponseSchema',
                           allow_none=True,
                           many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationForm"""
        return OperationForm(**data)

    class Meta:
        ordered = True


class OperationFormFieldListResponseSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    label = fields.String(required=True)
    help = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(DataType.__dict__.keys())])
    required = fields.Boolean(required=True)
    order = fields.Integer(required=True)
    default = fields.String(required=True)
    suggested_widget = fields.String(required=False, allow_none=True)
    values_url = fields.String(required=False, allow_none=True)
    values = fields.String(required=False, allow_none=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationFormField"""
        return OperationFormField(**data)

    class Meta:
        ordered = True


class OperationFormFieldCreateRequestSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    label = fields.String(required=True)
    help = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(DataType.__dict__.keys())])
    required = fields.Boolean(required=True)
    order = fields.Integer(required=True)
    default = fields.String(required=True)
    suggested_widget = fields.String(required=False, allow_none=True)
    values_url = fields.String(required=False, allow_none=True)
    values = fields.String(required=False, allow_none=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationFormField"""
        return OperationFormField(**data)

    class Meta:
        ordered = True


class OperationFormFieldItemResponseSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    label = fields.String(required=True)
    help = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(DataType.__dict__.keys())])
    required = fields.Boolean(required=True)
    order = fields.Integer(required=True)
    default = fields.String(required=True)
    suggested_widget = fields.String(required=False, allow_none=True)
    values_url = fields.String(required=False, allow_none=True)
    values = fields.String(required=False, allow_none=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationFormField"""
        return OperationFormField(**data)

    class Meta:
        ordered = True


class OperationPortListResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(OperationPortType.__dict__.keys())])
    description = fields.String(required=True)
    tags = fields.String(required=False, allow_none=True)
    order = fields.Integer(required=False, allow_none=True)
    multiplicity = fields.String(required=True, missing=1,
                                  default=1,
                                 validate=[OneOf(OperationPortMultiplicity.__dict__.keys())])
    interfaces = fields.Nested('schema.OperationPortInterfaceListResponseSchema',
                               allow_none=True,
                               many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationPort"""
        return OperationPort(**data)

    class Meta:
        ordered = True


class OperationPortCreateRequestSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(OperationPortType.__dict__.keys())])
    description = fields.String(required=True)
    tags = fields.String(required=False, allow_none=True)
    order = fields.Integer(required=False, allow_none=True)
    multiplicity = fields.String(required=True, missing=1,
                                  default=1,
                                 validate=[OneOf(OperationPortMultiplicity.__dict__.keys())])
    interfaces = fields.Nested('schema.OperationPortInterfaceCreateRequestSchema',
                               allow_none=True,
                               many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationPort"""
        return OperationPort(**data)

    class Meta:
        ordered = True


class OperationPortItemResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    type = fields.String(required=True,
                         validate=[OneOf(OperationPortType.__dict__.keys())])
    description = fields.String(required=True)
    tags = fields.String(required=False, allow_none=True)
    order = fields.Integer(required=False, allow_none=True)
    multiplicity = fields.String(required=True, missing=1,
                                  default=1,
                                 validate=[OneOf(OperationPortMultiplicity.__dict__.keys())])
    interfaces = fields.Nested('schema.OperationPortInterfaceItemResponseSchema',
                               allow_none=True,
                               many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationPort"""
        return OperationPort(**data)

    class Meta:
        ordered = True


class OperationPortInterfaceCreateRequestSchema(Schema):
    """ JSON schema for request """
    id = fields.Integer(required=True)
    name = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationPortInterface"""
        return OperationPortInterface(**data)

    class Meta:
        ordered = True


class OperationPortInterfaceListResponseSchema(Schema):
    """ JSON schema for response """
    name = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationPortInterface"""
        return OperationPortInterface(**data)

    class Meta:
        ordered = True


class OperationPortInterfaceItemResponseSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of OperationPortInterface"""
        return OperationPortInterface(**data)

    class Meta:
        ordered = True


class TaskListResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.String(required=True)
    left = fields.Integer(required=True)
    top = fields.Integer(required=True)
    z_index = fields.Integer(required=True)
    forms = fields.Function(lambda x: load_json(x.forms))
    operation = fields.Nested('schema.OperationSimpleListResponseSchema',
                              allow_none=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Task"""
        return Task(**data)

    class Meta:
        ordered = True


class TaskCreateRequestSchema(Schema):
    """ JSON serialization schema """
    id = fields.String(required=True)
    left = fields.Integer(required=True)
    top = fields.Integer(required=True)
    z_index = fields.Integer(required=True)
    forms = fields.Dict(required=True)
    operation_id = fields.Integer(required=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Task"""
        data['forms'] = json.dumps(data['forms'])
        return Task(**data)

    class Meta:
        ordered = True


class TaskItemResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.String(required=True)
    left = fields.Integer(required=True)
    top = fields.Integer(required=True)
    z_index = fields.Integer(required=True)
    forms = fields.Function(lambda x: load_json(x.forms))
    operation = fields.Nested('schema.OperationSimpleListResponseSchema',
                              allow_none=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Task"""
        return Task(**data)

    class Meta:
        ordered = True


class TaskExecuteRequestSchema(Schema):
    """ JSON schema for executing tasks """
    id = fields.String(required=True)
    left = fields.Integer(required=True)
    top = fields.Integer(required=True)
    z_index = fields.Integer(required=True)
    forms = fields.String(required=True)
    next_task_id = fields.Integer(allow_none=True)
    operation = fields.Nested('schema.OperationExecuteRequestSchema',
                              allow_none=True)
    parameters = fields.Nested('schema.KeyValuePairExecuteRequestSchema',
                               allow_none=True,
                               many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Task"""
        return Task(**data)

    class Meta:
        ordered = True


class WorkflowExecuteRequestSchema(Schema):
    """ JSON schema for executing workflow """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    description = fields.String(required=False, allow_none=True)
    user_id = fields.Integer(required=True)
    user_login = fields.String(required=True)
    user_name = fields.String(required=True)
    created = fields.DateTime(required=True, missing=datetime.datetime.utcnow,
                             default=datetime.datetime.utcnow)
    updated = fields.DateTime(required=True, missing=datetime.datetime.utcnow,
                             default=datetime.datetime.utcnow)
    version = fields.Integer(required=True)
    tasks = fields.Nested('schema.TaskExecuteRequestSchema',
                          allow_none=True,
                          many=True)
    flows = fields.Nested('schema.FlowExecuteRequestSchema',
                          allow_none=True,
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Workflow"""
        return Workflow(**data)

    class Meta:
        ordered = True


class WorkflowListResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    description = fields.String(required=False, allow_none=True)
    user_id = fields.Integer(required=True)
    user_login = fields.String(required=True)
    user_name = fields.String(required=True)
    created = fields.DateTime(required=True, missing=datetime.datetime.utcnow,
                             default=datetime.datetime.utcnow)
    updated = fields.DateTime(required=True, missing=datetime.datetime.utcnow,
                             default=datetime.datetime.utcnow)
    version = fields.Integer(required=True)
    tasks = fields.Nested('schema.TaskListResponseSchema',
                          allow_none=True,
                          many=True)
    flows = fields.Nested('schema.FlowListResponseSchema',
                          allow_none=True,
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Workflow"""
        return Workflow(**data)

    class Meta:
        ordered = True


class WorkflowCreateRequestSchema(Schema):
    """ JSON serialization schema """
    name = fields.String(required=True)
    description = fields.String(required=False, allow_none=True)
    user_id = fields.Integer(required=True)
    user_login = fields.String(required=True)
    user_name = fields.String(required=True)
    tasks = fields.Nested('schema.TaskCreateRequestSchema',
                          allow_none=True,
                          many=True)
    flows = fields.Nested('schema.FlowCreateRequestSchema',
                          allow_none=True,
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Workflow"""
        return Workflow(**data)

    class Meta:
        ordered = True


class WorkflowItemResponseSchema(Schema):
    """ JSON serialization schema """
    id = fields.Integer(required=True)
    name = fields.String(required=True)
    description = fields.String(required=False, allow_none=True)
    user_id = fields.Integer(required=True)
    user_login = fields.String(required=True)
    user_name = fields.String(required=True)
    created = fields.DateTime(required=True, missing=datetime.datetime.utcnow,
                             default=datetime.datetime.utcnow)
    updated = fields.DateTime(required=True, missing=datetime.datetime.utcnow,
                             default=datetime.datetime.utcnow)
    version = fields.Integer(required=True)
    tasks = fields.Nested('schema.TaskItemResponseSchema',
                          allow_none=True,
                          many=True)
    flows = fields.Nested('schema.FlowItemResponseSchema',
                          allow_none=True,
                          many=True)

    @post_load
    def make_object(self, data):
        """ Deserializes data into an instance of Workflow"""
{'fraction_non_alphanumeric': 0.09997919267582189, 'fraction_numerical': 0.00029130253849354973, 'mean_word_length': 2.757701329163409, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1727990', 'n_tokens_mistral': 12543, 'n_tokens_neox': 12252, 'n_words': 2655}