예제 #1
0
    def decode(self, content, **options):
        base_format = infer_json_or_yaml(content)
        if base_format == "json":
            data = parse_json(content, validator=SWAGGER)
        else:
            data = parse_yaml(content, validator=SWAGGER)

        title = lookup(data, ["info", "title"])
        description = lookup(data, ["info", "description"])
        version = lookup(data, ["info", "version"])
        host = lookup(data, ["host"])
        path = lookup(data, ["basePath"], "/")
        scheme = lookup(data, ["schemes", 0], "https")
        base_url = None
        if host:
            base_url = "%s://%s%s" % (scheme, host, path)
        schema_definitions = self.get_schema_definitions(data)
        content = self.get_content(data, base_url, schema_definitions)
        return Document(
            title=title,
            description=description,
            version=version,
            url=base_url,
            content=content,
        )
예제 #2
0
def generate_document(routes):
    content = []
    for item in routes:
        if isinstance(item, Route) and item.documented:
            content.append(item.link)
        elif isinstance(item, Include) and item.documented:
            content.append(item.section)
    return Document(content=content)
예제 #3
0
파일: openapi.py 프로젝트: rhelms/apistar
 def decode_data(self, data, **options):
     openapi = OPEN_API.validate(data)
     title = lookup(openapi, ['info', 'title'])
     description = lookup(openapi, ['info', 'description'])
     version = lookup(openapi, ['info', 'version'])
     base_url = lookup(openapi, ['servers', 0, 'url'])
     schema_definitions = self.get_schema_definitions(openapi)
     content = self.get_content(openapi, base_url, schema_definitions)
     return Document(title=title, description=description, version=version, url=base_url, content=content)
예제 #4
0
def generate_document(routes):
    content = []
    for item in routes:
        if isinstance(item, Route) and item.documented:
            content.append(item.link)
        elif isinstance(item, Include) and item.documented:
            content.append(item.section)
            for link in item.section.get_links():
                link.url = item.url + link.url
    return Document(content=content)
예제 #5
0
    def load(self, data):
        title = lookup(data, ['info', 'title'])
        description = lookup(data, ['info', 'description'])
        version = lookup(data, ['info', 'version'])
        base_url = lookup(data, ['servers', 0, 'url'])
        schema_definitions = self.get_schema_definitions(data)
        content = self.get_content(data, base_url, schema_definitions)

        return Document(title=title,
                        description=description,
                        version=version,
                        url=base_url,
                        content=content)
예제 #6
0
 def decode_data(self, data, **options):
     swagger = SWAGGER.validate(data)
     title = lookup(swagger, ['info', 'title'])
     description = lookup(swagger, ['info', 'description'])
     version = lookup(swagger, ['info', 'version'])
     host = lookup(swagger, ['host'])
     path = lookup(swagger, ['basePath'], '/')
     scheme = lookup(swagger, ['schemes', 0], 'https')
     base_url = None
     if host:
         base_url = '%s://%s%s' % (scheme, host, path)
     schema_definitions = self.get_schema_definitions(swagger)
     content = self.get_content(swagger, base_url, schema_definitions)
     return Document(title=title, description=description, version=version, url=base_url, content=content)
예제 #7
0
    def decode(self, bytestring, **options):
        try:
            data = json.loads(bytestring.decode('utf-8'))
        except ValueError as exc:
            raise ParseError('Malformed JSON. %s' % exc) from None

        openapi = OPEN_API.validate(data)
        title = lookup(openapi, ['info', 'title'])
        description = lookup(openapi, ['info', 'description'])
        version = lookup(openapi, ['info', 'version'])
        base_url = lookup(openapi, ['servers', 0, 'url'])
        schema_definitions = self.get_schema_definitions(openapi)
        content = self.get_content(openapi, base_url, schema_definitions)
        return Document(title=title, description=description, version=version, url=base_url, content=content)
예제 #8
0
    def load(self, data):
        title = lookup(data, ["info", "title"])
        description = lookup(data, ["info", "description"])
        version = lookup(data, ["info", "version"])
        base_url = lookup(data, ["servers", 0, "url"])
        schema_definitions = self.get_schema_definitions(data)
        content = self.get_content(data, base_url, schema_definitions)

        return Document(
            title=title,
            description=description,
            version=version,
            url=base_url,
            content=content,
        )
예제 #9
0
 def load(self, data):
     title = lookup(data, ['info', 'title'])
     description = lookup(data, ['info', 'description'])
     version = lookup(data, ['info', 'version'])
     host = lookup(data, ['host'])
     path = lookup(data, ['basePath'], '/')
     scheme = lookup(data, ['schemes', 0], 'https')
     base_url = None
     if host:
         base_url = '%s://%s%s' % (scheme, host, path)
     schema_definitions = self.get_schema_definitions(data)
     content = self.get_content(data, base_url, schema_definitions)
     return Document(title=title,
                     description=description,
                     version=version,
                     url=base_url,
                     content=content)
예제 #10
0
 def load(self, data):
     title = lookup(data, ["info", "title"])
     description = lookup(data, ["info", "description"])
     version = lookup(data, ["info", "version"])
     host = lookup(data, ["host"])
     path = lookup(data, ["basePath"], "/")
     scheme = lookup(data, ["schemes", 0], "https")
     base_url = None
     if host:
         base_url = "%s://%s%s" % (scheme, host, path)
     schema_definitions = self.get_schema_definitions(data)
     content = self.get_content(data, base_url, schema_definitions)
     return Document(
         title=title,
         description=description,
         version=version,
         url=base_url,
         content=content,
     )
예제 #11
0
    def decode(self, content, **options):
        base_format = infer_json_or_yaml(content)
        if base_format == 'json':
            data = parse_json(content, validator=OPEN_API)
        else:
            data = parse_yaml(content, validator=OPEN_API)

        title = lookup(data, ['info', 'title'])
        description = lookup(data, ['info', 'description'])
        version = lookup(data, ['info', 'version'])
        base_url = lookup(data, ['servers', 0, 'url'])
        schema_definitions = self.get_schema_definitions(data)
        content = self.get_content(data, base_url, schema_definitions)

        return Document(title=title,
                        description=description,
                        version=version,
                        url=base_url,
                        content=content)
예제 #12
0
    def decode(self, content, **options):
        base_format = infer_json_or_yaml(content)
        if base_format == "json":
            data = parse_json(content, validator=OPEN_API)
        else:
            data = parse_yaml(content, validator=OPEN_API)

        title = lookup(data, ["info", "title"])
        description = lookup(data, ["info", "description"])
        version = lookup(data, ["info", "version"])
        base_url = lookup(data, ["servers", 0, "url"])
        schema_definitions = self.get_schema_definitions(data)
        content = self.get_content(data, base_url, schema_definitions)

        return Document(
            title=title,
            description=description,
            version=version,
            url=base_url,
            content=content,
        )
예제 #13
0
    def decode(self, content, **options):
        base_format = infer_json_or_yaml(content)
        if base_format == 'json':
            data = parse_json(content, validator=SWAGGER)
        else:
            data = parse_yaml(content, validator=SWAGGER)

        title = lookup(data, ['info', 'title'])
        description = lookup(data, ['info', 'description'])
        version = lookup(data, ['info', 'version'])
        host = lookup(data, ['host'])
        path = lookup(data, ['basePath'], '/')
        scheme = lookup(data, ['schemes', 0], 'https')
        base_url = None
        if host:
            base_url = '%s://%s%s' % (scheme, host, path)
        schema_definitions = self.get_schema_definitions(data)
        content = self.get_content(data, base_url, schema_definitions)
        return Document(title=title,
                        description=description,
                        version=version,
                        url=base_url,
                        content=content)
예제 #14
0
document = Document([
    # Path parameters
    Link(url='/str_path_param/{param}/', method='GET', name='str_path_param'),
    Link(url='/int_path_param/{param}/', method='GET', name='int_path_param'),
    Link(url='/schema_enforced_str_path_param/{param}/',
         method='GET',
         name='schema_enforced_str_path_param',
         fields=[
             Field(name='param',
                   location='path',
                   required=True,
                   schema=validators.String(max_length=3))
         ]),
    Link(url='/schema_enforced_int_path_param/{param}/',
         method='GET',
         name='schema_enforced_int_path_param',
         fields=[
             Field(name='param',
                   location='path',
                   required=True,
                   schema=validators.Integer(minimum=0, maximum=1000))
         ]),

    # Query parameters
    Link(url='/str_query_param/', method='GET', name='str_query_param'),
    Link(url='/int_query_param/', method='GET', name='int_query_param'),
    Link(url='/str_query_param_with_default/',
         method='GET',
         name='str_query_param_with_default'),
    Link(url='/int_query_param_with_default/',
         method='GET',
         name='int_query_param_with_default'),
    Link(url='/schema_enforced_str_query_param/',
         method='GET',
         name='schema_enforced_str_query_param',
         fields=[
             Field(name='param',
                   location='query',
                   schema=validators.String(max_length=3))
         ]),
    Link(url='/schema_enforced_int_query_param/',
         method='GET',
         name='schema_enforced_int_query_param',
         fields=[
             Field(name='param',
                   location='query',
                   schema=validators.Integer(minimum=0, maximum=1000))
         ]),

    # Body parameters
    Link(url='/type_body_param/', method='POST', handler=type_body_param),
    Link(url='/schema_enforced_body_param/',
         method='POST',
         name='schema_enforced_body_param',
         encoding='application/json',
         fields=[
             Field(name='param',
                   location='body',
                   schema=validators.Object(
                       properties={
                           'name':
                           validators.String(max_length=10),
                           'age':
                           validators.Integer(
                               minimum=0, allow_null=True, default=None),
                       }))
         ]),
])