OpenAPITools / OpenAPITools/openapi-generator
Sorting operations by operationId leads to issues on generated server
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Suppose we have the following routes (in form operationName=route path):
getTopScoredPosts=/posts/top-scored
getPostById=/posts/{postId}
Operations are sorted by operationId like below:
ops.sort((one, another) -> ObjectUtils.compare(one.operationId, another.operationId));
When generating server, routes are going to be registered with a router (like express) in the following order:
getPostById=/posts/{postId}
getTopScoredPosts=/posts/top-scored
```
This leads to an issue where requests like `GET /posts/top-scored` will be actually matched by `GET /posts/{postId}` route handler.
The simplest solution is to avoid sorting operations and have them in order as they are defined in the opeanpi doc.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java around the operation sorting at line 604, then trace how generated server routes receive that order. Verify the behavior with the documented /posts/top-scored and /posts/{postId} routes; done means the specific route is matched correctly instead of being captured by the parameterized route.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100