fix(openapi): content-api paths missing api.rest.prefix in generated spec#26061
Open
ousamabenyounes wants to merge 1 commit into
Open
fix(openapi): content-api paths missing api.rest.prefix in generated spec#26061ousamabenyounes wants to merge 1 commit into
ousamabenyounes wants to merge 1 commit into
Conversation
|
@ousamabenyounes is attempting to deploy a commit to the Strapi Team on Vercel. A member of the Team first needs to authorize it. |
f7c2634 to
297b4a2
Compare
…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
297b4a2 to
f975a3d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does it do?
ApiRoutesProvidernow prependsapi.rest.prefix(default/api) to every content-api route path it emits, and also honours router-levelrouter.prefixand per-routeroute.config.prefixoverrides. This mirrors how content-api routes are actually mounted at runtime (seepackages/core/core/src/services/server/content-api.ts:6and the matching logic already implemented inPluginRoutesProvider).Diff summary:
packages/core/openapi/src/routes/providers/api.ts— apply prefixes when flattening routes.packages/core/openapi/__tests__/mocks/strapi.mock.ts— add aconfig.getstub so provider instantiation doesn't crash.packages/core/openapi/__tests__/routes/api-routes-provider.test.ts— four new tests covering the default/apiprefix, a custom prefix, router-level prefix composition, andconfig.prefixoverride.Why is it needed?
Fix #25493. Running
strapi openapi generateproduced paths like/articleswhile 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:unitAll 24 unit tests pass (20 pre-existing + 4 new).
Manually:
npx strapi openapi generate -- --output ./api-spec.json.pathskeys are/articles,/articles/{id}, etc.pathskeys match the served URLs:/api/articles,/api/articles/{id}, etc. Ifapi.rest.prefixis customised inconfig/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)