Skip to content

Commit bcfcf02

Browse files
committed
fix: do not allow to publish specifications with operations with empty path parameter name
1 parent c85d4f8 commit bcfcf02

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/apitypes/rest/rest.operations.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export const buildRestOperations: OperationsBuilder<OpenAPIV3.Document> = async
6666

6767
const componentsHashMap = new Map<string, string>()
6868
for (const path of Object.keys(paths)) {
69+
// Validate path parameters: empty parameter names are not allowed
70+
if (path.includes('{}')) {
71+
throw new Error(`Invalid path '${path}': path parameter name could not be empty`)
72+
}
73+
6974
const pathData = paths[path]
7075
if (typeof pathData !== 'object' || !pathData) { continue }
7176

test/bugs.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import { API_AUDIENCE_INTERNAL, API_KIND } from '../src'
1818
import { Editor, LocalRegistry } from './helpers'
1919

20+
import { describe, test, expect } from '@jest/globals'
21+
2022
const bugsPackage = LocalRegistry.openPackage('bugs')
2123
const swaggerPackage = LocalRegistry.openPackage('basic_swagger')
2224
const migrationBug = LocalRegistry.openPackage('migration_bug')
@@ -357,4 +359,16 @@ describe('Operation Bugs', () => {
357359
const operationKeys = Array.from(result.operations.keys())
358360
expect(operationKeys[0]).toEqual('paths1-get')
359361
})
362+
363+
test('Should throw error if path parameter name is empty', async () => {
364+
const pkg = LocalRegistry.openPackage('empty-path-parameter')
365+
366+
await expect(pkg.publish(pkg.packageId, {
367+
packageId: pkg.packageId,
368+
version: 'v1',
369+
files: [
370+
{ fileId: 'spec.json' },
371+
],
372+
})).rejects.toThrow('Invalid path \'/res/data/{}\': path parameter name could not be empty')
373+
})
360374
})

0 commit comments

Comments
 (0)