fix: merge paths with non-conflicting HTTP methods instead of prefixing#3436
fix: merge paths with non-conflicting HTTP methods instead of prefixing#3436
Conversation
|
|
🦋 Changeset detectedLatest commit: b1a419a The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…prefix Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
|
Leaping into action... |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3436 +/- ##
==========================================
+ Coverage 39.37% 40.11% +0.74%
==========================================
Files 476 476
Lines 17452 17459 +7
Branches 5278 5287 +9
==========================================
+ Hits 6871 7004 +133
+ Misses 8500 8414 -86
+ Partials 2081 2041 -40
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@hey-api/codegen-core
@hey-api/json-schema-ref-parser
@hey-api/nuxt
@hey-api/openapi-ts
@hey-api/shared
@hey-api/types
@hey-api/vite-plugin
commit: |

When merging multiple OpenAPI specs, path collisions were resolved by always adding a source prefix to the path — even when the colliding paths had completely different HTTP methods that could safely coexist under the same path key.
Changes
packages/json-schema-ref-parser/src/index.ts: InmergeMany(), path collision handling now checks whether the incoming path's HTTP methods actually overlap with the already-merged path before prefixing. Non-conflicting methods are merged in-place viaObject.assign; only true method conflicts fall back to the prefix strategy.packages/json-schema-ref-parser/src/__tests__/bundle.test.ts: Added twomergeManytest cases — one confirming non-conflicting methods (e.g.POST+DELETE) merge under the same path, and one confirming genuine method conflicts still produce a prefixed path.Example
Given two specs both defining
/pet/{petId}— one withpost, one withdelete— the merged result is now:{ "/pet/{petId}": { "post": { ... }, "delete": { ... } } }Previously, the second spec's path was incorrectly renamed to
/{prefix}/pet/{petId}.Original prompt
This section details on the original issue you should resolve
<issue_title>path collision are adding prefix without checking the method</issue_title>
<issue_description>### Description
When there is collision in paths, it will automatically append the prefix (code) however, it doesn't check if the methods collide too, sometimes different method might be in different spec:
input:
{ "swagger": "2.0", "info": { "version": "1.0.7", "title": "Swagger Petstore", "description": "Filtered spec containing only POST /pet/{petId}" }, "host": "petstore.swagger.io", "basePath": "/v2", "schemes": ["https", "http"], "paths": { "/pet/{petId}": { "post": { "tags": ["pet"], "summary": "Updates a pet in the store with form data", "description": "", "operationId": "updatePetWithForm", "consumes": ["application/x-www-form-urlencoded"], "produces": ["application/json", "application/xml"], "parameters": [ { "name": "petId", "in": "path", "description": "ID of pet that needs to be updated", "required": true, "type": "integer", "format": "int64" }, { "name": "name", "in": "formData", "description": "Updated name of the pet", "required": false, "type": "string" }, { "name": "status", "in": "formData", "description": "Updated status of the pet", "required": false, "type": "string" } ], "responses": { "405": { "description": "Invalid input" } }, "security": [ { "petstore_auth": ["write:pets", "read:pets"] } ] } } }, "securityDefinitions": { "petstore_auth": { "type": "oauth2", "authorizationUrl": "https://petstore.swagger.io/oauth/authorize", "flow": "implicit", "scopes": { "read:pets": "read your pets", "write:pets": "modify pets in your account" } } } }{ "swagger": "2.0", "info": { "version": "1.0.7", "title": "Swagger Petstore", "description": "Filtered spec containing only GET and DELETE for /pet/{petId}" }, "host": "petstore.swagger.io", "basePath": "/v2", "schemes": ["https", "http"], "paths": { "/pet/{petId}": { "delete": { "tags": ["pet"], "summary": "Deletes a pet", "description": "", "operationId": "deletePet", "produces": ["application/json", "application/xml"], "parameters": [ { "name": "api_key", "in": "header", "required": false, "type": "string" }, { "name": "petId", "in": "path", "description": "Pet id to delete", "required": true, "type": "integer", "format": "int64" } ], "responses": { "400": { "description": "Invalid ID supplied" }, "404": { "description": "Pet not found" } }, "security": [ { "petstore_auth": ["write:pets", "read:pets"] } ] } } }, "securityDefinitions": { "api_key": { "type": "apiKey", "name": "api_key", "in": "header" }, "petstore_auth": { "type": "oauth2", "authorizationUrl": "https://petstore.swagger.io/oauth/authorize", "flow": "implicit", "scopes": { "read:pets": "read your pets", "write:pets": "modify pets in your account" } } }, "definitions": { "Category": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" } } }, "Pet": { "type": "object", "required": ["name", "photoUrls"], "properties": { "id": { "type": "integer", "format": "int64" }, "category": { "$ref": "#/definitions/Category" }, "name": { "type": "string", "example": "doggie" }, "photoUrls": { "type": "array", "items": { "type": "string" } }, "tags": { "type": "array", "items": { "$ref": "#/definitions/Tag" } }, "status": { "type": "string", "enum": ["available", "pending", "sold"] } } }, "Tag": { "type": "object", "properties": { "id": { ... </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes hey-api/openapi-ts#3428 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).