diff --git a/apispec/core.py b/apispec/core.py
index 66028b1..170ca0b 100644
--- a/apispec/core.py
+++ b/apispec/core.py
@@ -154,12 +154,19 @@ class APISpec(object):
         :param dict|None operations: describes the http methods and options for `path`
         :param dict kwargs: parameters used by any path helpers see :meth:`register_path_helper`
         """
+        def normalize_path(path):
+            if path and 'basePath' in self.options:
+                pattern = '^{0}'.format(re.escape(self.options['basePath']))
+                path = re.sub(pattern, '', path)
+
+            return path
+
         p = path
         if isinstance(path, Path):
             p = path.path
-        if p and 'basePath' in self.options:
-            pattern = '^{0}'.format(re.escape(self.options['basePath']))
-            p = re.sub(pattern, '', p)
+
+        p = normalize_path(p)
+
         if isinstance(path, Path):
             path.path = p
         else:
@@ -173,6 +180,7 @@ class APISpec(object):
             except TypeError:
                 continue
             if isinstance(ret, Path):
+                ret.path = normalize_path(ret.path)
                 path.update(ret)
 
         if not path.path:

Core path does not support swagger basePath
Related to #69.

Flask allows configuring the `APPLICATION_ROOT`, which provides the base path for the routes. #70 fixed this issue so that the flask extension reports the fully qualified path.

When the specs are dumped as swagger specs using `to_dict()`, the full path is shown on every route, even though the swagger specification supports the [`basePath`](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields) field on the root object.

I think it is important to keep the meaningful portion of the route URL separate from the base path to maintain readable documentation. #70 was the right fix for the flask extension since the `apispec` core assumes paths are absolute, but the fact that both `flask` and `swagger` support a configurable base path indicates that the `apispec` core should probably internalize the concept of base paths and expose them to extensions.

Examples of base path in similar libraries:
- [Bottle: ResourceManager (default) path](http://bottlepy.org/docs/dev/api.html#bottle.ResourceManager)
- [RAML: Base URI](https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md/#base-uri-and-base-uri-parameters)

> Edit: Updated to refect that generating swagger specs is a core functionality of `apispec`, not an extension.

diff --git a/tests/test_ext_flask.py b/tests/test_ext_flask.py
index eeb4a03..5bbfcfd 100644
--- a/tests/test_ext_flask.py
+++ b/tests/test_ext_flask.py
@@ -108,7 +108,8 @@ class TestPathHelpers:
 
     def test_path_includes_app_root(self, app, spec):
 
-        app.config['APPLICATION_ROOT'] = '/app/root'
+        spec.options['basePath'] = '/v1'
+        app.config['APPLICATION_ROOT'] = '/v1/app/root'
 
         @app.route('/partial/path/pet')
         def get_pet():
@@ -119,7 +120,8 @@ class TestPathHelpers:
 
     def test_path_with_args_includes_app_root(self, app, spec):
 
-        app.config['APPLICATION_ROOT'] = '/app/root'
+        spec.options['basePath'] = '/v1'
+        app.config['APPLICATION_ROOT'] = '/v1/app/root'
 
         @app.route('/partial/path/pet/{pet_id}')
         def get_pet(pet_id):
@@ -130,7 +132,8 @@ class TestPathHelpers:
 
     def test_path_includes_app_root_with_right_slash(self, app, spec):
 
-        app.config['APPLICATION_ROOT'] = '/app/root/'
+        spec.options['basePath'] = '/v1'
+        app.config['APPLICATION_ROOT'] = '/v1/app/root/'
 
         @app.route('/partial/path/pet')
         def get_pet():

pip install -e .
parse_log_pytest
requirements.txt
pytest
3.9
dev-requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
-e git+https://github.com/marshmallow-code/apispec.git@14be6d8be8608dec4af9e215a154e521f9d8ff78#egg=apispec
backports.tarfile==1.2.0
blinker==1.9.0
cachetools==5.5.2
certifi==2025.1.31
cffi==1.17.1
chardet==5.2.0
charset-normalizer==3.4.1
click==8.1.8
colorama==0.4.6
cryptography==44.0.2
distlib==0.3.9
docutils==0.21.2
exceptiongroup==1.2.2
filelock==3.18.0
flake8==2.5.4
Flask==3.1.0
id==1.5.0
idna==3.10
importlib_metadata==8.6.1
iniconfig==2.1.0
invoke==2.2.0
itsdangerous==2.2.0
jaraco.classes==3.4.0
jaraco.context==6.0.1
jaraco.functools==4.1.0
jeepney==0.9.0
Jinja2==3.1.6
keyring==25.6.0
markdown-it-py==3.0.0
MarkupSafe==3.0.2
marshmallow==3.26.1
mccabe==0.4.0
mdurl==0.1.2
mock==5.2.0
more-itertools==10.6.0
nh3==0.2.21
packaging==24.2
pep8==1.7.1
platformdirs==4.3.7
pluggy==1.5.0
pycparser==2.22
pyflakes==1.0.0
Pygments==2.19.1
pyproject-api==1.9.0
pytest==8.3.5
PyYAML==6.0.2
readme_renderer==44.0
requests==2.32.3
requests-toolbelt==1.0.0
rfc3986==2.0.0
rich==14.0.0
SecretStorage==3.3.3
tomli==2.2.1
tornado==6.4.2
tox==4.25.0
twine==6.1.0
typing_extensions==4.13.0
urllib3==2.3.0
virtualenv==20.29.3
Werkzeug==3.1.3
zipp==3.21.0

name: apispec
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - backports-tarfile==1.2.0
      - blinker==1.9.0
      - cachetools==5.5.2
      - certifi==2025.1.31
      - cffi==1.17.1
      - chardet==5.2.0
      - charset-normalizer==3.4.1
      - click==8.1.8
      - colorama==0.4.6
      - cryptography==44.0.2
      - distlib==0.3.9
      - docutils==0.21.2
      - exceptiongroup==1.2.2
      - filelock==3.18.0
      - flake8==2.5.4
      - flask==3.1.0
      - id==1.5.0
      - idna==3.10
      - importlib-metadata==8.6.1
      - iniconfig==2.1.0
      - invoke==2.2.0
      - itsdangerous==2.2.0
      - jaraco-classes==3.4.0
      - jaraco-context==6.0.1
      - jaraco-functools==4.1.0
      - jeepney==0.9.0
      - jinja2==3.1.6
      - keyring==25.6.0
      - markdown-it-py==3.0.0
      - markupsafe==3.0.2
      - marshmallow==3.26.1
      - mccabe==0.4.0
      - mdurl==0.1.2
      - mock==5.2.0
      - more-itertools==10.6.0
      - nh3==0.2.21
      - packaging==24.2
      - pep8==1.7.1
      - platformdirs==4.3.7
      - pluggy==1.5.0
      - pycparser==2.22
      - pyflakes==1.0.0
      - pygments==2.19.1
      - pyproject-api==1.9.0
      - pytest==8.3.5
      - pyyaml==6.0.2
      - readme-renderer==44.0
      - requests==2.32.3
      - requests-toolbelt==1.0.0
      - rfc3986==2.0.0
      - rich==14.0.0
      - secretstorage==3.3.3
      - tomli==2.2.1
      - tornado==6.4.2
      - tox==4.25.0
      - twine==6.1.0
      - typing-extensions==4.13.0
      - urllib3==2.3.0
      - virtualenv==20.29.3
      - werkzeug==3.1.3
      - zipp==3.21.0
prefix: /opt/conda/envs/apispec

tests/test_ext_flask.py::TestPathHelpers::test_path_includes_app_root tests/test_ext_flask.py::TestPathHelpers::test_path_with_args_includes_app_root tests/test_ext_flask.py::TestPathHelpers::test_path_includes_app_root_with_right_slash
tests/test_ext_flask.py::TestPathHelpers::test_integration_with_docstring_introspection
tests/test_ext_flask.py::TestPathHelpers::test_path_from_view tests/test_ext_flask.py::TestPathHelpers::test_path_with_multiple_methods tests/test_ext_flask.py::TestPathHelpers::test_path_is_translated_to_swagger_template
apispec/core.py
apispec/core.py