Skip to content

Commit 2d8b48d

Browse files
committed
fix: Fixed the calculation of the operation name with empty servers
1 parent e26c4ba commit 2d8b48d

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/apitypes/rest/rest.operations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export const buildRestOperations: OperationsBuilder<OpenAPIV3.Document> = async
5555
debugCtx,
5656
)
5757

58-
const { paths, servers } = effectiveDocument
58+
const { paths } = effectiveDocument
59+
const { servers } = document.data
5960

6061
const operations: TYPE.VersionRestOperation[] = []
6162
if (!paths) { return [] }

test/bugs.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,18 @@ describe('Operation Bugs', () => {
342342

343343
expect(editor.builder.operationList.every(operation => operation.apiKind === API_KIND.NO_BWC)).toBeTruthy()
344344
})
345+
346+
test('should correct calculate operationId with empty servers', async () => {
347+
const editor = await Editor.openProject('bugs', bugsPackage)
348+
349+
const result = await editor.run({
350+
version: 'v1',
351+
files: [
352+
{ fileId: 'should-correct-calculate-operation-id-with-empty-servers.yaml', publish: true },
353+
],
354+
})
355+
356+
const operationKeys = Array.from(result.operations.keys())
357+
expect(operationKeys[0]).toEqual('paths1-get')
358+
})
345359
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
version: 1.0.0
5+
servers:
6+
- url: []
7+
paths:
8+
/paths1:
9+
get:
10+
description: test
11+
responses:
12+
'200':
13+
description: Success
14+
content:
15+
application/json:
16+
schema:
17+
type: object

0 commit comments

Comments
 (0)