Beispiel #1
0
    def process(self, is_type=False):
        logger.debug("Processing resource: %s" % self.schema.fullname())
        menu = self.menu
        schema = self.schema
        baseid = html_str_to_id(schema.fullid(True))
        div = self.container.div(id=baseid)
        menu.add_item(schema.name, href=div)

        div.h2().text = ('Type: ' if is_type else 'Resource: ') + schema.name
        if schema.description != '':
            div.p().text = schema.description

        if (not is_type):
            uri = schema.links['self'].path.template
            if uri[0] == '$':
                uri = self.basepath + uri[1:]
            div.pre().text = uri

        self.schema_table(schema, div, baseid)

        if (not is_type):
            div.h3(id="links").text = "Links"
            self.process_links(div, baseid)

            if self.schema.relations:
                div.h3(id="relations").text = "Relations"
                self.process_relations(div, baseid)
Beispiel #2
0
    def process(self, is_type=False):
        logger.debug("Processing resource: %s" % self.schema.fullname())
        menu = self.menu
        schema = self.schema
        baseid = html_str_to_id(schema.fullid(True))
        div = self.container.div(id=baseid)
        menu.add_item(schema.name, href=div)

        div.h2().text = ('Type: ' if is_type else 'Resource: ') + schema.name
        if schema.description != '':
            div.p().text = schema.description

        if (not is_type):
            uri = schema.links['self'].path.template
            if uri[0] == '$':
                uri = self.basepath + uri[1:]
            div.pre().text = uri

        self.schema_table(schema, div, baseid)

        if (not is_type):
            div.h3(id="links").text = "Links"
            self.process_links(div, baseid)

            if self.schema.relations:
                div.h3(id="relations").text = "Relations"
                self.process_relations(div, baseid)
Beispiel #3
0
    def __init__(self, schema, options=None, attrname='refschema'):
        self.schema = schema
        self.options = options

        try:
            self.passthrough = True
            self.refschema = getattr(schema, attrname)
            refid = self.refschema.fullid()
            self.name = self.refschema.name
            self.typestr = self.refschema.typestr
        except NoManager:
            self.passthrough = False
            refid = getattr(schema, '_' + attrname + '_id')
            self.name = refid.split('/')[-1]
            self.typestr = '<ref>'
            self.description = refid

        # refid is something like:
        #   http://support.riverbed.com/apis/test/1.0#/types/type_number_limits
        #
        # Drop the netloc and api root and replace with a relative path ref
        # based on the current schema id
        parsed_id = urllib.parse.urlparse(refid)

        # Fall back to just using an href of the schema id for the
        # following cases:
        #  - not a riverbed service
        #  - no match to '/apis'
        #  - looking for printable format
        m = re.match("/apis/(.*)$", parsed_id.path)
        if (parsed_id.netloc != 'support.riverbed.com' or not m
                or self.options.printable):
            self.href = refid
        else:
            # Build a relative link based on the difference between this
            # schema id and the refschema id.
            #
            # Figure out how many levels up to recurse -- up to the first diff
            parsed_parent_id = urllib.parse.urlparse(schema.servicedef.id)
            m_parent = re.match("/apis/(.*)$", parsed_parent_id.path)
            relpath_count = len(m_parent.group(1).split('/'))
            relpath = '/'.join(['..' for i in range(relpath_count)])

            frag_id = html_str_to_id(parsed_id.fragment)
            self.href = ('%s/%s/service.html#%s' %
                         (relpath, m.group(1), frag_id))
Beispiel #4
0
    def __init__(self, schema, options=None, attrname='refschema'):
        self.schema = schema
        self.options = options

        try:
            self.passthrough = True
            self.refschema = getattr(schema, attrname)
            refid = self.refschema.fullid()
            self.name = self.refschema.name
            self.typestr = self.refschema.typestr
        except NoManager:
            self.passthrough = False
            refid = getattr(schema, '_' + attrname + '_id')
            self.name = refid.split('/')[-1]
            self.typestr = '<ref>'
            self.description = refid

        # refid is something like:
        #   http://support.riverbed.com/apis/test/1.0#/types/type_number_limits
        #
        # Drop the netloc and api root and replace with a relative path ref
        # based on the current schema id
        parsed_id = urlparse.urlparse(refid)

        # Fall back to just using an href of the schema id for the
        # following cases:
        #  - not a riverbed service
        #  - no match to '/apis'
        #  - looking for printable format
        m = re.match("/apis/(.*)$", parsed_id.path)
        if (parsed_id.netloc != 'support.riverbed.com' or
                not m or self.options.printable):
            self.href = refid
        else:
            # Build a relative link based on the difference between this
            # schema id and the refschema id.
            #
            # Figure out how many levels up to recurse -- up to the first diff
            parsed_parent_id = urlparse.urlparse(schema.servicedef.id)
            m_parent = re.match("/apis/(.*)$", parsed_parent_id.path)
            relpath_count = len(m_parent.group(1).split('/'))
            relpath = '/'.join(['..' for i in range(relpath_count)])

            frag_id = html_str_to_id(parsed_id.fragment)
            self.href = ('%s/%s/service.html#%s' %
                         (relpath, m.group(1), frag_id))
Beispiel #5
0
 def test_invalid_ref_in_links(self):
     """
     testing when one property's ref consists of undefined resources,
     an invalid reference exception should be raised. such as below:
     properties:
     links:
       self: { path: '$/test_invalid_ref_in_lnks'}
       params:
          id:
             $ref: '#/types/does_not_exist'
     """
     with self.assertRaises(reschema.exceptions.InvalidReference):
         resource = self.sd.resources.values()[0]
         title = "%s v%s %s" % (self.sd.title, self.sd.version,
                                self.sd.status)
         htmldoc = reschema.html.Document(title, printable=False)
         r2h = ResourceToHtml(resource, htmldoc.content,
                              htmldoc.menu.add_submenu(),
                              "http://{device}/{root}",
                              None)
         baseid = html_str_to_id(r2h.schema.fullid(True))
         div = r2h.container.div(id=baseid)
         r2h.menu.add_item(r2h.schema.name, href=div)
         r2h.process_links(div, baseid)