Ejemplo n.º 1
0
    def __init__(self, schema=None, status=None):
        if isinstance(schema, dict):
            schema = Structure(schema)
        if schema and not schema.name:
            schema.name = 'response'

        self.schema = schema
        self.status = status
Ejemplo n.º 2
0
    def __init__(self, schema=None, status=None):
        if isinstance(schema, dict):
            schema = Structure(schema)
        if schema and not schema.name:
            schema.name = 'response'

        self.schema = schema
        self.status = status
Ejemplo n.º 3
0
    def construct(cls, resource, declaration):
        bases = declaration.__bases__
        if isinstance(declaration, (type, ClassType)) and bases:
            params = cls._pull_request(resource, bases[0])
        else:
            params = {}

        params.update(pull_class_dict(declaration, cls.ATTRS))
        if 'responses' not in params:
            params['responses'] = {}
        
        schema = getattr(declaration, 'schema', None)
        if schema is not None:
            if isinstance(schema, dict):
                schema = Structure(schema)
            if not schema.name:
                schema.name = 'request'
            params['schema'] = schema

        fields = getattr(declaration, 'fields', None)
        if fields:
            if isinstance(params['schema'], Structure):
                structure = params['schema'].structure
                for name, field in fields.iteritems():
                    if isinstance(field, Field):
                        if not field.name:
                            field.name = name
                        structure[name] = field
                    elif field is None and name in structure:
                        del structure[name]
            else:
                raise SpecificationError()

        responses = getattr(declaration, 'responses', {})
        for status, response in responses.iteritems():
            if not isinstance(response, Response):
                response = Response(response)
            response.status = status
            params['responses'][status] = response

        description = params.get('description')
        if not description and declaration.__doc__:
            params['description'] = dedent(declaration.__doc__)

        return cls(resource=resource, name=declaration.__name__, **params)
Ejemplo n.º 4
0
    def construct(cls, resource, declaration):
        bases = declaration.__bases__
        if isinstance(declaration, (type, ClassType)) and bases:
            params = cls._pull_request(resource, bases[0])
        else:
            params = {}

        params.update(pull_class_dict(declaration, cls.ATTRS))
        if 'responses' not in params:
            params['responses'] = {}

        schema = getattr(declaration, 'schema', None)
        if schema is not None:
            if isinstance(schema, dict):
                schema = Structure(schema)
            if not schema.name:
                schema.name = 'request'
            params['schema'] = schema

        fields = getattr(declaration, 'fields', None)
        if fields:
            if isinstance(params['schema'], Structure):
                structure = params['schema'].structure
                for name, field in fields.iteritems():
                    if isinstance(field, Field):
                        if not field.name:
                            field.name = name
                        structure[name] = field
                    elif field is None and name in structure:
                        del structure[name]
            else:
                raise SpecificationError()

        responses = getattr(declaration, 'responses', {})
        for status, response in responses.iteritems():
            if not isinstance(response, Response):
                response = Response(response)
            response.status = status
            params['responses'][status] = response

        description = params.get('description')
        if not description and declaration.__doc__:
            params['description'] = dedent(declaration.__doc__)

        return cls(resource=resource, name=declaration.__name__, **params)
Ejemplo n.º 5
0
Archivo: request.py Proyecto: siq/mesh
    def construct(cls, resource, declaration):
        bases = declaration.__bases__
        if isinstance(declaration, (type, ClassType)) and bases:
            params = cls._pull_request(resource, bases[0], declaration)
        else:
            params = {}

        params.update(pull_class_dict(declaration, cls.ATTRS))
        if "responses" not in params:
            params["responses"] = {}

        schema = getattr(declaration, "schema", None)
        if schema is not None:
            if isinstance(schema, dict):
                for name, field in schema.items():
                    if isinstance(field, basestring):
                        field = resource.schema.get(field)
                        if field:
                            schema[name] = field
                schema = Structure(schema)
            if not schema.name:
                schema.name = "request"
            params["schema"] = schema

        fields = getattr(declaration, "fields", None)
        if fields:
            if isinstance(params["schema"], Structure):
                structure = params["schema"].structure
                for name, field in fields.iteritems():
                    if isinstance(field, Field):
                        if not field.name:
                            field.name = name
                        structure[name] = field
                    elif isinstance(field, basestring):
                        field = resource.schema.get(field)
                        if field:
                            if field.name != name:
                                field = field.clone(name=name)
                            structure[name] = field
                        else:
                            raise SpecificationError()
                    elif field is None and name in structure:
                        del structure[name]
            else:
                raise SpecificationError()

        responses = getattr(declaration, "responses", {})
        for status, response in responses.iteritems():
            if not isinstance(response, Response):
                response = Response(response)
            response.status = status
            params["responses"][status] = response

        description = params.get("description")
        if not description and declaration.__doc__:
            params["description"] = dedent(declaration.__doc__)

        metadata = getattr(declaration, "metadata", None)
        if metadata:
            if "metadata" in params:
                params["metadata"].update(metadata)
            else:
                params["metadata"] = metadata

        return cls(resource=resource, name=declaration.__name__, **params)