def __detect_content_from_type(self, val): # -> (str, bool, str): if val.type.name == "file": return "file", False, val.type.contents if val.type.name in settings.get_schemas().keys(): return val.type.name, True, None return val.type.name, False, None
def get(self): """Get handler""" self.set_header('content-type', 'application/json') apis = self.find_api() # this is a generator servers = [] server_settings = settings.default_settings.get("servers") for server in server_settings: for key in list(server.keys()): if key not in ('url', 'description'): server.pop(key, None) if server: servers.append(server) if not servers: server_host = self.request.host.split(',')[0] forwarded = self.request.headers.get('Forwarded', None) proto = None if forwarded: protopart = [ part.strip() for part in forwarded.split(';') if part.strip().startswith('proto') ] if protopart: proto = protopart[0].split('=')[-1] proto = proto or self.request.headers.get( "X-Forwarded-Proto", None) or self.request.protocol servers = [{ 'url': proto + "://" + server_host + "/", 'description': 'Default server' }] specs = { 'openapi': settings.SWAGGER_VERSION, 'info': { 'title': settings.default_settings.get("title"), 'description': settings.default_settings.get("description"), 'version': settings.default_settings.get("api_version"), }, 'servers': servers, 'paths': { path: self.__get_api_spec(spec, operations) for path, spec, operations in apis }, } if settings.SwirlVars.GLOBAL_TAGS: specs['tags'] = settings.SwirlVars.GLOBAL_TAGS schemas = settings.get_schemas() if schemas: specs.update({ "components": { "schemas": { name: self.__get_schema_spec(schemaCls) for (name, schemaCls) in schemas.items() } } }) security_schemes = settings.SwirlVars.SECURITY_SCHEMES # type: dict if security_schemes: components = specs.get("components") or {} components['securitySchemes'] = {} for name, scheme in security_schemes.items(): components['securitySchemes'][name] = scheme.spec() specs.update(components) self.finish(json_dumps(specs, self.get_arguments('pretty')))