Пример #1
0
class RamlResponse(Model):
    schema = String()
    example = String()
    notNull = Bool()
    description = String()
    headers = Map(String(), Reference(RamlHeader))
    body = Reference("pyraml.entities.RamlBody")
Пример #2
0
class RamlMethod(Model):
    notNull = Bool()
    description = String()
    body = Reference(RamlBody)
    responses = Map(Int(), Reference(RamlBody))
    #responses = Map(Int(), Reference(RamlResponse))
    queryParameters = Map(String(), Reference(RamlQueryParameter))
Пример #3
0
class RamlResource(Model):
    displayName = String()
    description = String()
    uri = String()
    type = Reference(RamlTrait, field_name="is")
    parentResource = Reference("pyraml.entities.RamlResource")
    methods = Map(String(), Reference(RamlBody))
    resources = Map(String(), Reference("pyraml.entities.RamlResource"))
Пример #4
0
class RamlBody(Model):
    schema = String()
    example = String()
    notNull = Bool()
    formParameters = Map(String(), Reference(RamlHeader))
    headers = Map(String(), Reference(RamlHeader))
    body = Map(String(), Reference("pyraml.entities.RamlBody"))
    is_ = List(String(), field_name="is")
Пример #5
0
class RamlResource(ResourceTypedEntity, TraitedEntity, SecuredEntity, Model):
    """ http://raml.org/spec.html#resources-and-nested-resources """
    displayName = String()
    description = String()
    parentResource = Reference("pyraml.entities.RamlResource")
    methods = Map(String(), Reference(RamlMethod))
    resources = Map(String(), Reference("pyraml.entities.RamlResource"))
    uriParameters = RamlNamedParametersMap()
    baseUriParameters = RamlNamedParametersMap()
Пример #6
0
class RamlMethod(TraitedEntity, SecuredEntity, Model):
    """ http://raml.org/spec.html#methods """
    notNull = Bool()
    description = String()
    body = Map(String(), Reference(RamlBody))
    responses = Map(Int(), Reference(RamlResponse))
    queryParameters = RamlNamedParametersMap()
    baseUriParameters = RamlNamedParametersMap()
    headers = RamlNamedParametersMap()
    protocols = List(
        Choice(field_name='protocols', choices=RAML_VALID_PROTOCOLS))
Пример #7
0
class RamlRoot(Model):
    raml_version = String(required=True)
    title = String()
    version = String()
    baseUri = String()
    protocols = List(String())
    mediaType = String()
    documentation = List(Reference(RamlDocumentation))
    traits = Map(String(), Reference(RamlTrait))
    resources = Map(String(), Reference(RamlResource))
    resourceTypes =  Map(String(), Reference(RamlResourceType))
Пример #8
0
class RamlSecuritySchemeDescription(Model):
    """ The describedBy attribute MAY be used to apply a trait-like
    structure to a security scheme mechanism so as to extend the
    mechanism, such as specifying response codes, HTTP headers or
    custom documentation.
    """
    description = String()
    body = Map(String(), Reference(RamlBody))
    headers = RamlNamedParametersMap()
    queryParameters = RamlNamedParametersMap()
    responses = Map(Int(), Reference(RamlResponse))
    baseUriParameters = RamlNamedParametersMap()
    protocols = List(
        Choice(field_name='protocols', choices=RAML_VALID_PROTOCOLS))
Пример #9
0
class RamlRoot(SecuredEntity, Model):
    """ http://raml.org/spec.html#root-section """
    raml_version = String(required=True)
    title = String(required=True)
    version = Or(String(), Int(), Float())
    baseUri = String(required=True)
    protocols = List(
        Choice(field_name='protocols', choices=RAML_VALID_PROTOCOLS))
    mediaType = String()
    documentation = List(Reference(RamlDocumentation))
    traits = Map(String(), Reference(RamlTrait))
    resources = Map(String(), Reference(RamlResource))
    resourceTypes = Map(String(), Reference(RamlResourceType))
    schemas = Map(String(), Or(JSONData(), XMLData(), String()))
    baseUriParameters = RamlNamedParametersMap()
    securitySchemes = Map(String(), Reference(RamlSecurityScheme))
Пример #10
0
class RamlResourceType(Model):
    """ A resource type is a partial resource definition that,
    like a resource, can specify a description and methods and
    their properties.
    """
    usage = String()
    description = String()
    methods = Map(String(), Reference(RamlMethod))
Пример #11
0
class RamlResponse(Model):
    """ Responses MUST be a map of one or more HTTP status codes,
    where each status code itself is a map that describes that status
    code.
    """
    notNull = Bool()
    description = String()
    headers = RamlNamedParametersMap()
    body = Map(String(), Reference("pyraml.entities.RamlBody"))
Пример #12
0
class RamlTrait(Model):
    """ A trait is a partial method definition that, like a method,
    can provide method-level properties such as
    description, headers, query string parameters, and responses.
    """
    usage = String()
    description = String()
    headers = RamlNamedParametersMap()
    queryParameters = RamlNamedParametersMap()
    responses = Map(Int(), Reference(RamlResponse))
Пример #13
0
def parse_resource_type(c):
    """
    Parse and extract resourceType

    :param c: ParseContext object
    :type c: ParseContext

    :return: RamlResource  or None
    :rtype: RamlResource
    """

    json_resource_types = c.get('resourceTypes')
    if not json_resource_types:
        return None

    # We got list of dict from c.get('resourceTypes') so we need to convert it to dict
    #print json_resource_types[0], c.relative_path
    resource_types_context = ParseContext(json_resource_types[0],
                                          c.relative_path)

    resource_types = {}

    for rtype_name in resource_types_context:
        new_c = ParseContext(resource_types_context.get(rtype_name),
                             resource_types_context.relative_path)

        rtype_obj = RamlResourceType()
        rtype_obj.type = new_c.get_string_property("type")
        rtype_obj.is_ = new_c.get_property_with_schema("is",
                                                       RamlResourceType.is_)

        # Parse methods
        methods = OrderedDict()
        for _http_method in ["get", "post", "put", "delete", "head"]:
            _method = new_c.get(_http_method)
            if _method:
                _method = ParseContext(
                    _method, new_c.relative_path).get_property_with_schema(
                        'traits', Reference(RamlTrait))
                methods[_http_method] = _method
            elif _http_method in new_c.data:
                # workaround: if _http_method is already in new_context.data than
                # it's marked as !!null
                _method = RamlMethod(notNull=True)
                methods[_http_method] = _method

        if len(methods):
            rtype_obj.methods = methods

        resource_types[rtype_name] = rtype_obj

    return resource_types
Пример #14
0
class RamlTrait(Model):
    """
    traits:
      - secured:
          usage: Apply this to any method that needs to be secured
          description: Some requests require authentication.
          queryParameters:
            access_token:
              description: Access Token
              type: string
              example: ACCESS_TOKEN
              required: true
    """

    name = String()
    usage = String()
    description = String()
    displayName = String()
    responses = Map(Int(), Reference(RamlResponse))
    method = String()
    queryParameters = Map(String(), Reference(RamlQueryParameter))
    body = Reference(RamlBody)
    # Reference to another RamlTrait
    is_ = List(String(), field_name="is")
Пример #15
0
class RamlMethod(Model):
    notNull = Bool()
    description = String()
    body = Reference(RamlBody)
    responses = Map(Int(), Reference(RamlBody))
Пример #16
0
class RamlSecurityScheme(Model):
    """ http://raml.org/spec.html#security """
    description = String()
    type = String()
    describedBy = Reference(RamlSecuritySchemeDescription)
    settings = Map(String(), Or(String(), List(String())))
Пример #17
0
class RamlResourceType(Model):
    methods = Map(String(), Reference(RamlTrait))
    type = String()
    is_ = List(String(), field_name="is")