diff --git a/src/apitypes/rest/rest.utils.ts b/src/apitypes/rest/rest.utils.ts index b0ebb9c..4ac391d 100644 --- a/src/apitypes/rest/rest.utils.ts +++ b/src/apitypes/rest/rest.utils.ts @@ -27,6 +27,10 @@ export const getOperationBasePath = (servers?: OpenAPIV3.ServerObject[]): string try { const [firstServer] = servers let serverUrl = firstServer.url + if(!serverUrl) { + return '' + } + const { variables = {} } = firstServer for (const param of Object.keys(variables)) { diff --git a/test/bugs.test.ts b/test/bugs.test.ts index 6f1ec8c..dce10d0 100644 --- a/test/bugs.test.ts +++ b/test/bugs.test.ts @@ -342,4 +342,18 @@ describe('Operation Bugs', () => { expect(editor.builder.operationList.every(operation => operation.apiKind === API_KIND.NO_BWC)).toBeTruthy() }) + + test('should correctly calculate operationId for servers with incorrect URL', async () => { + const editor = await Editor.openProject('bugs', bugsPackage) + + const result = await editor.run({ + version: 'v1', + files: [ + { fileId: 'should-correctly-calculate-operation-id-for-servers-with-incorrect-url.yaml', publish: true }, + ], + }) + + const operationKeys = Array.from(result.operations.keys()) + expect(operationKeys[0]).toEqual('paths1-get') + }) }) diff --git a/test/projects/bugs/docs/Markdown_example.md b/test/projects/bugs/docs/Markdown_example.md index c162397..4ec3731 100644 --- a/test/projects/bugs/docs/Markdown_example.md +++ b/test/projects/bugs/docs/Markdown_example.md @@ -8,7 +8,7 @@ Supports OpenAPI and GraphQL specifications processing. - Added cycles support during combiners resolve - Added origins support- it is now possible for any value in the unified JSO to track its origins in the source specification - Store original ref for the object if the object was resolved from ref -- Gathered various API unification adapters from different libraries in the stack to a single place +- Gathered various API unification adapters from different libraries in the stack to a single place - Support data structure hash calculation - Process different phases sequentially (reference resolving, allOf merge, unification) - Support synthetic `any` and `nothing` type for OAS @@ -26,14 +26,14 @@ Supports OpenAPI and GraphQL specifications processing. - Correctly merge additionalProperties, patternProperties and properties taking into account common validations - Correctly merge items and additionalItems taking into account common validations - Supports custom rules to merge other document types and JsonSchema versions -- Supports input with circular references (javaScript references) +- Supports input with circular references (JavaScript references) - Supports $refs and circular $refs either (internal references only) - Correctly merge of $refs with sibling content (optionally) - Correctly merge of combiners (anyOf, oneOf) with sibling content (optionally) -- Typescript syntax support out of the box -- No dependencies (except json-crawl), can be used in NodeJS or browser +- TypeScript syntax support out of the box +- No dependencies (except json-crawl), can be used in Node.js or browser -## Works perfectly with specifications: +## Works perfectly with specifications - [JsonSchema](https://json-schema.org/draft/2020-12/json-schema-core.html) - [OpenApi 3.x](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md) @@ -43,7 +43,7 @@ Supports OpenAPI and GraphQL specifications processing. - ~~AsyncApi 3.x~~ (roadmap) ## Other libraries -There are some libraries that can merge schemas combined with allOf. One of the most popular is [mokkabonna/json-schema-merge-allof](https://www.npmjs.com/package/json-schema-merge-allof), but it has some limitatons: Does not support circular $refs and no Typescript syntax out of the box. +There are some libraries that can merge schemas combined with allOf. One of the most popular is [mokkabonna/json-schema-merge-allof](https://npmjs.com/package/json-schema-merge-allof), but it has some limitatons: Does not support circular $refs and no TypeScript syntax out of the box. ## License diff --git a/test/projects/bugs/should-correctly-calculate-operation-id-for-servers-with-incorrect-url.yaml b/test/projects/bugs/should-correctly-calculate-operation-id-for-servers-with-incorrect-url.yaml new file mode 100644 index 0000000..99174a6 --- /dev/null +++ b/test/projects/bugs/should-correctly-calculate-operation-id-for-servers-with-incorrect-url.yaml @@ -0,0 +1,17 @@ +openapi: 3.0.3 +info: + title: test + version: 1.0.0 +servers: + - url: [] +paths: + /paths1: + get: + description: test + responses: + '200': + description: Success + content: + application/json: + schema: + type: object