nitrojs / nitrojs/nitro

OpenAPI auto generated path params not merged correctly

Open
#3,535 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

Environment

Nitro 2.12.4
Node v22.13.1

Reproduction

Step 1:
use definePageMeta in any route.

Step 2:
make sure that openAPI object contains parameters array, even if empty.
/api/{projectId}/index.get.ts

openAPI: {
    description: 'Get a specific project by ID',
    tags: ['projects'],
    summary: 'Get project by ID',
    operationId: 'getProjectById',
    parameters: [],
  }

Step 3:
Open swagger docs and notice that path variable is not auto-populated.

Describe the bug

Nitro has this feature of auto detecting API path variables and populating them as path parameters in Open API spec. However, this feature is not working as intended.

Additional context

This can be easily fixed. Just use DEFU!!!

Logs

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with /api/{projectId}/index.get.ts, definePageMeta, and an OpenAPI parameters: [] array, then inspect the generated Swagger documentation. Compare the generated path parameters with the route variable. Done means projectId appears as an automatically generated path parameter even when the parameters array is empty.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.