Beispiel #1
0
def _get_current_registry(api=None):
    # import ipdb;ipdb.set_trace()
    global registry
    app_name = None
    overrides = {}
    if api:
        app_name = api.blueprint.name if api.blueprint else None
    else:
        app_name = request.blueprint
        urlparts = urlparse.urlparse(request.url_root.rstrip('/'))
        proto = request.headers.get("x-forwarded-proto") or urlparts[0]
        overrides = {
            'basePath': urlparse.urlunparse([proto] + list(urlparts[1:]))
        }

    if not app_name:
        app_name = 'app'

    overrides['models'] = registry.get('models', {})

    reg = registry.setdefault(app_name, {})
    reg.update(overrides)

    reg['basePath'] = reg['basePath'] + reg.get('x-api-prefix', '')

    return reg
def _get_current_registry(api=None):
  # import ipdb;ipdb.set_trace()
  global registry
  app_name = None
  overrides = {}
  if api:
    app_name = api.blueprint.name if api.blueprint else None
  else:
    app_name = request.blueprint
    urlparts =  urlparse.urlparse(request.url_root.rstrip('/'))
    proto = request.headers.get("x-forwarded-proto") or urlparts[0]
    overrides = {'basePath': urlparse.urlunparse([proto] + list(urlparts[1:]))}

  if not app_name:
    app_name = 'app'

  overrides['models'] = registry.get('models', {})

  reg = registry.setdefault(app_name, {})
  reg.update(overrides)

  reg['basePath'] = reg['basePath'] + reg.get('x-api-prefix', '')
  reg['basePath'] = reg["basePath"].replace("http://localhost:5000/", "/")

  return reg
Beispiel #3
0
def _get_current_registry(api=None):
    # import ipdb;ipdb.set_trace()
    global registry
    app_name = None
    overrides = {}
    if api:
        app_name = api.blueprint.name if api.blueprint else None
    else:
        app_name = request.blueprint
        urlparts = urlparse.urlparse(request.url_root.rstrip("/"))
        proto = request.headers.get("x-forwarded-proto") or urlparts[0]
        overrides = {
            "basePath": urlparse.urlunparse([proto] + list(urlparts[1:])),
        }

    if not app_name:
        app_name = "app"

    overrides["models"] = registry.get("models", {})

    reg = registry.setdefault(app_name, {})
    reg.update(overrides)

    reg["basePath"] = reg["basePath"] + (reg.get("x-api-prefix", "") or "")

    return reg
def _get_current_registry(api=None):
  # import ipdb;ipdb.set_trace()
  global registry
  app_name = None
  overrides = {}
  if api:
    app_name = api.blueprint.name if api.blueprint else None
  else:
    app_name = request.blueprint
    overrides = {'basePath': request.url_root.rstrip('/')}

  if not app_name:
    app_name = 'app'

  overrides['models'] = registry.get('models', {})

  reg = registry.setdefault(app_name, {})
  reg.update(overrides)

  reg['basePath'] = reg['basePath'] + reg.get('x-api-prefix', '')

  return reg
def _get_current_registry(api=None):
  # import ipdb;ipdb.set_trace()
  global registry
  app_name = None
  overrides = {}
  if api:
    app_name = api.blueprint.name if api.blueprint else None
  else:
    app_name = request.blueprint
    overrides = {'basePath': request.url_root.rstrip('/')}

  if not app_name:
    app_name = 'app'

  overrides['models'] = registry.get('models', {})

  reg = registry.setdefault(app_name, {})
  reg.update(overrides)

  reg['basePath'] = reg['basePath'] + reg.get('x-api-prefix', '')

  return reg
def register_once(api, add_resource_func, apiVersion, swaggerVersion, basePath, resourcePath, produces, endpoint_path, description):
    global api_spec_static
    global resource_listing_endpoint

    if api.blueprint and not registry.get(api.blueprint.name):    # Most of all this can be taken from the blueprint/app
        registry[api.blueprint.name] = {
          'apiVersion': apiVersion,
          'swaggerVersion': swaggerVersion,
          'basePath': basePath,
          'spec_endpoint_path': endpoint_path,
          'resourcePath': resourcePath,
          'produces': produces,
          'x-api-prefix': '',
          'apis': [],
          'description': description
        }

        def registering_blueprint(setup_state):
            reg = registry[setup_state.blueprint.name]
            reg['x-api-prefix'] = setup_state.url_prefix

        api.blueprint.record(registering_blueprint)

        add_resource_func(
            SwaggerRegistry,
            endpoint_path,
            endpoint_path + '.json',
            endpoint_path + '.html'
        )

        resource_listing_endpoint = endpoint_path + '/_/resource_list.json'
        add_resource_func(ResourceLister, resource_listing_endpoint)

        api_spec_static = endpoint_path + '/_/static/'
        add_resource_func(
              StaticFiles,
              api_spec_static + '<string:dir1>/<string:dir2>/<string:dir3>',
              api_spec_static + '<string:dir1>/<string:dir2>',
              api_spec_static + '<string:dir1>')

    elif not 'app' in registry:
        registry['app'] = {
          'apiVersion': apiVersion,
          'swaggerVersion': swaggerVersion,
          'basePath': basePath,
          'spec_endpoint_path': endpoint_path,
          'resourcePath': resourcePath,
          'produces': produces,
          'description': description
        }

        add_resource_func(
          SwaggerRegistry,
          endpoint_path,
          endpoint_path + '.json',
          endpoint_path + '.html',
          endpoint='app/registry'
        )

        resource_listing_endpoint = endpoint_path + '/_/resource_list.json'
        add_resource_func(
          ResourceLister, resource_listing_endpoint,
          endpoint='app/resourcelister')

        api_spec_static = endpoint_path + '/_/static/'
        add_resource_func(
          StaticFiles,
          api_spec_static + '<string:dir1>/<string:dir2>/<string:dir3>',
          api_spec_static + '<string:dir1>/<string:dir2>',
          api_spec_static + '<string:dir1>',
          endpoint='app/staticfiles')
def register_once(api, add_resource_func, apiVersion, swaggerVersion, basePath,
                  resourcePath, produces, endpoint_path, description):
  global api_spec_static
  global resource_listing_endpoint

  if api.blueprint and not registry.get(api.blueprint.name):
    # Most of all this can be taken from the blueprint/app
    registry[api.blueprint.name] = {
      'apiVersion': apiVersion,
      'swaggerVersion': swaggerVersion,
      'basePath': basePath,
      'spec_endpoint_path': endpoint_path,
      'resourcePath': resourcePath,
      'produces': produces,
      'x-api-prefix': '',
      'apis': [],
      'description': description
    }

    def registering_blueprint(setup_state):
      reg = registry[setup_state.blueprint.name]
      reg['x-api-prefix'] = setup_state.url_prefix

    api.blueprint.record(registering_blueprint)

    add_resource_func(
      SwaggerRegistry,
      endpoint_path,
      endpoint_path + '.json',
      endpoint_path + '.html'
    )

    resource_listing_endpoint = endpoint_path + '/_/resource_list.json'
    add_resource_func(ResourceLister, resource_listing_endpoint)

    api_spec_static = endpoint_path + '/_/static/'
    add_resource_func(
      StaticFiles,
      api_spec_static + '<string:dir1>/<string:dir2>/<string:dir3>',
      api_spec_static + '<string:dir1>/<string:dir2>',
      api_spec_static + '<string:dir1>')
  elif not 'app' in registry:
    registry['app'] = {
      'apiVersion': apiVersion,
      'swagger': swaggerVersion,
      'basePath': basePath,
      'spec_endpoint_path': endpoint_path,
      'resourcePath': resourcePath,
      'produces': produces,
      'description': description
    }

    add_resource_func(
      SwaggerRegistry,
      endpoint_path,
      endpoint_path + '.json',
      endpoint_path + '.html',
      endpoint='app/registry'
    )

    resource_listing_endpoint = endpoint_path + '/_/resource_list.json'
    add_resource_func(
      ResourceLister, resource_listing_endpoint,
      endpoint='app/resourcelister')

    api_spec_static = endpoint_path + '/_/static/'
    add_resource_func(
      StaticFiles,
      api_spec_static + '<string:dir1>/<string:dir2>/<string:dir3>',
      api_spec_static + '<string:dir1>/<string:dir2>',
      api_spec_static + '<string:dir1>',
      endpoint='app/staticfiles')
def register_once(api, add_resource_func, apiVersion, swaggerVersion, basePath,
                  resourcePath, produces, endpoint_path, description, info):
  global resource_listing_endpoint
  api_spec_static = endpoint_path + api_spec_static_suffix

  if api.blueprint and not registry.get(api.blueprint.name):
    # Most of all this can be taken from the blueprint/app
    registry[api.blueprint.name] = {
      'apiVersion': apiVersion,
      'swaggerVersion': swaggerVersion,
      'basePath': basePath,
      'spec_endpoint_path': endpoint_path,
      'resourcePath': resourcePath,
      'produces': produces,
      'x-api-prefix': '',
      'apis': [],
      'description': description,
      'info': info,
      'resources_hierarchy': {
        'default': {
          'link': {
            # Real 'path' will be rendered at runtime from updated basePath and path_suffix
            'path_suffix': endpoint_path + '/default',
            'description': description
          },
          'content': []
        }
      }
    }

    def registering_blueprint(setup_state):
      reg = registry[setup_state.blueprint.name]
      reg['x-api-prefix'] = setup_state.url_prefix

    api.blueprint.record(registering_blueprint)

    add_resource_func(
      SwaggerRegistry,
      endpoint_path + '/default',
      endpoint_path,
      endpoint_path + '.json',
      endpoint_path + '.html'
    )

    resource_listing_endpoint = endpoint_path + '/_/resource_list.json'
    add_resource_func(ResourceLister, resource_listing_endpoint)

    add_resource_func(
      StaticFiles,
      api_spec_static + '<string:dir1>/<string:dir2>/<string:dir3>',
      api_spec_static + '<string:dir1>/<string:dir2>',
      api_spec_static + '<string:dir1>')
  elif not 'app' in registry:
    registry['app'] = {
      'apiVersion': apiVersion,
      'swaggerVersion': swaggerVersion,
      'basePath': basePath,
      'spec_endpoint_path': endpoint_path,
      'resourcePath': resourcePath,
      'produces': produces,
      'x-api-prefix': api.prefix,
      'description': description,
      'info': info,
      'resources_hierarchy': {
        'default': {
          'link': {
            # Real 'path' will be rendered at runtime from updated basePath and path_suffix
            'path_suffix': endpoint_path + '/default',
            'description': description
          },
          'content': []
        }
      }
    }

    add_resource_func(
      SwaggerRegistry,
      endpoint_path + '/default',
      endpoint_path,
      endpoint_path + '.json',
      endpoint_path + '.html',
      endpoint='app/registry'
    )

    resource_listing_endpoint = endpoint_path + '/_/resource_list.json'
    add_resource_func(
      ResourceLister, resource_listing_endpoint,
      endpoint='app/resourcelister')

    add_resource_func(
      StaticFiles,
      api_spec_static + '<string:dir1>/<string:dir2>/<string:dir3>',
      api_spec_static + '<string:dir1>/<string:dir2>',
      api_spec_static + '<string:dir1>',
      endpoint='app/staticfiles')
Beispiel #9
0
def register_once(
    api,
    add_resource_func,
    apiVersion,
    swaggerVersion,
    basePath,
    resourcePath,
    produces,
    endpoint_path,
    description,
):
    global api_spec_static
    global resource_listing_endpoint

    if api.blueprint and not registry.get(api.blueprint.name):
        # Most of all this can be taken from the blueprint/app
        registry[api.blueprint.name] = {
            "apiVersion": apiVersion,
            "swaggerVersion": swaggerVersion,
            "basePath": basePath,
            "spec_endpoint_path": endpoint_path,
            "resourcePath": resourcePath,
            "produces": produces,
            "x-api-prefix": "",
            "apis": [],
            "description": description,
        }

        def registering_blueprint(setup_state):
            reg = registry[setup_state.blueprint.name]
            reg["x-api-prefix"] = setup_state.url_prefix

        api.blueprint.record(registering_blueprint)

        add_resource_func(
            SwaggerRegistry,
            endpoint_path,
            endpoint_path + ".json",
            endpoint_path + ".html",
        )

        resource_listing_endpoint = endpoint_path + "/_/resource_list.json"
        add_resource_func(ResourceLister, resource_listing_endpoint)

        api_spec_static = endpoint_path + "/_/static/"
        add_resource_func(
            StaticFiles,
            api_spec_static + "<string:dir1>/<string:dir2>/<string:dir3>",
            api_spec_static + "<string:dir1>/<string:dir2>",
            api_spec_static + "<string:dir1>",
        )
    elif "app" not in registry:
        registry["app"] = {
            "apiVersion": apiVersion,
            "swaggerVersion": swaggerVersion,
            "basePath": basePath,
            "spec_endpoint_path": endpoint_path,
            "resourcePath": resourcePath,
            "produces": produces,
            "description": description,
        }

        add_resource_func(
            SwaggerRegistry,
            endpoint_path,
            endpoint_path + ".json",
            endpoint_path + ".html",
            endpoint="app/registry",
        )

        resource_listing_endpoint = endpoint_path + "/_/resource_list.json"
        add_resource_func(
            ResourceLister,
            resource_listing_endpoint,
            endpoint="app/resourcelister",
        )

        api_spec_static = endpoint_path + "/_/static/"
        add_resource_func(
            StaticFiles,
            api_spec_static + "<string:dir1>/<string:dir2>/<string:dir3>",
            api_spec_static + "<string:dir1>/<string:dir2>",
            api_spec_static + "<string:dir1>",
            endpoint="app/staticfiles",
        )