Skip to content

fix(openapi): content-api paths missing api.rest.prefix in generated spec#26061

Open
ousamabenyounes wants to merge 1 commit into
strapi:developfrom
ousamabenyounes:fix/openapi-content-api-prefix
Open

fix(openapi): content-api paths missing api.rest.prefix in generated spec#26061
ousamabenyounes wants to merge 1 commit into
strapi:developfrom
ousamabenyounes:fix/openapi-content-api-prefix

Conversation

@ousamabenyounes
Copy link
Copy Markdown

@ousamabenyounes ousamabenyounes commented Apr 17, 2026

What does it do?

ApiRoutesProvider now prepends api.rest.prefix (default /api) to every content-api route path it emits, and also honours router-level router.prefix and per-route route.config.prefix overrides. This mirrors how content-api routes are actually mounted at runtime (see packages/core/core/src/services/server/content-api.ts:6 and the matching logic already implemented in PluginRoutesProvider).

Diff summary:

  • packages/core/openapi/src/routes/providers/api.ts — apply prefixes when flattening routes.
  • packages/core/openapi/__tests__/mocks/strapi.mock.ts — add a config.get stub so provider instantiation doesn't crash.
  • packages/core/openapi/__tests__/routes/api-routes-provider.test.ts — four new tests covering the default /api prefix, a custom prefix, router-level prefix composition, and config.prefix override.

Why is it needed?

Fix #25493. Running strapi openapi generate produced paths like /articles while Strapi actually serves them at /api/articles, so the generated OpenAPI spec didn't match the real API and couldn't be consumed by clients or code generators without manual surgery.

How to test it?

cd packages/core/openapi
yarn test:unit

All 24 unit tests pass (20 pre-existing + 4 new).

Manually:

  1. Generate an OpenAPI spec on a stock v5 project: npx strapi openapi generate -- --output ./api-spec.json.
  2. Before the fix: paths keys are /articles, /articles/{id}, etc.
  3. After the fix: paths keys match the served URLs: /api/articles, /api/articles/{id}, etc. If api.rest.prefix is customised in config/api.ts, that custom prefix is used instead.

Related issue(s)/PR(s)

Fix #25493


Vibe Coded by Ousama Ben Younes
Developed With Ora Studio (Claude Code)

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 17, 2026

@ousamabenyounes 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
Copy Markdown

strapi-cla commented Apr 17, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added the community Changes and fixes created by community members label Apr 17, 2026
@dosubot dosubot Bot added pr: fix This PR is fixing a bug source: core:openapi Source is core/openapi package labels Apr 17, 2026
@ousamabenyounes ousamabenyounes force-pushed the fix/openapi-content-api-prefix branch from f7c2634 to 297b4a2 Compare May 9, 2026 10:17
…spec

The `strapi openapi generate` command produced paths like `/articles`
instead of `/api/articles`, so the generated spec did not match the URLs
actually served by the runtime.

ApiRoutesProvider now prepends `api.rest.prefix` (default `/api`) and
honours both router-level `router.prefix` and per-route
`route.config.prefix` overrides, mirroring how content-api routes are
mounted in packages/core/core/src/services/server/content-api.ts and the
existing handling in PluginRoutesProvider.

Fix strapi#25493
@ousamabenyounes ousamabenyounes force-pushed the fix/openapi-content-api-prefix branch from 297b4a2 to f975a3d Compare May 11, 2026 09:02
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.

strapi openapi generate produces urls with missing /api/ prefix

2 participants