Skip to content

fix(openapi): add REST API prefix to content-api routes in generated spec#25737

Open
mahmoodhamdi wants to merge 1 commit intostrapi:developfrom
mahmoodhamdi:fix/openapi-add-api-prefix
Open

fix(openapi): add REST API prefix to content-api routes in generated spec#25737
mahmoodhamdi wants to merge 1 commit intostrapi:developfrom
mahmoodhamdi:fix/openapi-add-api-prefix

Conversation

@mahmoodhamdi
Copy link

What does this PR do?

Adds the configured REST API prefix (api.rest.prefix, default /api) to content-api routes in the OpenAPI spec generator's ApiRoutesProvider.

Why is this change needed?

When running strapi openapi generate, the generated spec produces paths like /articles instead of /api/articles. Since the REST API prefix is applied at the Koa Router level, routes stored in strapi.apis do not include it. The OpenAPI generator reads these routes directly, so the generated paths are missing the prefix and don't match the actual API endpoints.

This follows the same pattern used by the core content-api service when registering routes:

const apiPrefix = strapi.config.get('api.rest.prefix');
routes.map((route) => ({ ...route, path: `${apiPrefix}${route.path}` }));

Issue: #25493

Changes

  • ApiRoutesProvider: Apply api.rest.prefix to content-api routes (admin routes are left unchanged)
  • Test fixtures: Updated to reflect that routes in strapi.apis don't include the prefix
  • StrapiMock: Added config.get method
  • Tests: Added 2 new tests for prefix application and custom prefix support

How was this tested?

  • All 22 existing + new OpenAPI tests pass
  • Verified the prefix is only applied to content-api type routes
  • Verified custom prefix support via config

Checklist

  • My branch is based on develop
  • Tests added/updated
  • All tests pass
  • Linked to relevant issue

…spec

The OpenAPI spec generator reads routes from strapi.apis without
applying the REST API prefix (default /api). This causes generated
paths like /articles instead of the correct /api/articles.

Apply the configured api.rest.prefix to content-api routes in the
ApiRoutesProvider, matching how the core content-api service
registers routes with the Koa router.

Update test fixtures to reflect that routes stored in strapi.apis
do not include the prefix, and add tests verifying prefix application
and custom prefix support.

Fixes strapi#25493
@vercel
Copy link

vercel bot commented Mar 15, 2026

@mahmoodhamdi is attempting to deploy a commit to the Strapi Team on Vercel.

A member of the Team first needs to authorize it.

@strapi-cla
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions bot added the community Changes and fixes created by community members label Mar 15, 2026
@dosubot dosubot bot added pr: fix This PR is fixing a bug source: core:openapi Source is core/openapi package labels Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Changes and fixes created by community members pr: fix This PR is fixing a bug source: core:openapi Source is core/openapi package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants