From 67e0cf31aae41a547f0337725538cc982909cb52 Mon Sep 17 00:00:00 2001 From: Kirill Efimov <40362351+korifey91@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:25:26 +0300 Subject: [PATCH] fix: escape `< >` symbols (#542) Co-authored-by: Lukasz Gornicki --- helpers/schema.js | 20 ++++++++++---------- test/components/Schema.test.js | 28 ++++++++++++++-------------- test/helpers/schema.test.js | 16 ++++++++-------- test/spec/asyncapi_v2.yml | 10 +++++----- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/helpers/schema.js b/helpers/schema.js index 190df43a5..d084f8f05 100644 --- a/helpers/schema.js +++ b/helpers/schema.js @@ -64,7 +64,7 @@ export class SchemaHelpers { if (schema.isBooleanSchema()) { if (schema.json() === true) { return SchemaCustomTypes.ANY; - } + } return SchemaCustomTypes.NEVER; } // handle case with `{}` schemas @@ -100,18 +100,18 @@ export class SchemaHelpers { const types = items.map(item => this.toSchemaType(item)).join(', '); const additionalItems = schema.additionalItems(); if (additionalItems === true) { - return `tuple<${types || SchemaCustomTypes.UNKNOWN}, ...optional<${SchemaCustomTypes.ANY}>>`; + return `tuple<${types || SchemaCustomTypes.UNKNOWN}, ...optional<${SchemaCustomTypes.ANY}>>`; } if (additionalItems === false) { - return `tuple<${types}>`; + return `tuple<${types}>`; } const additionalType = this.toSchemaType(additionalItems); - return `tuple<${types || SchemaCustomTypes.UNKNOWN}, ...optional<${additionalType}>>`; + return `tuple<${types || SchemaCustomTypes.UNKNOWN}, ...optional<${additionalType}>>`; } if (!items) { - return `array<${SchemaCustomTypes.ANY}>`; + return `array<${SchemaCustomTypes.ANY}>`; } - return `array<${this.toSchemaType(items) || SchemaCustomTypes.UNKNOWN}>`; + return `array<${this.toSchemaType(items) || SchemaCustomTypes.UNKNOWN}>`; } return type; } @@ -195,9 +195,9 @@ export class SchemaHelpers { } /** - * - * @param {import('@asyncapi/parser').ChannelParametersInterface} parameters - * @returns + * + * @param {import('@asyncapi/parser').ChannelParametersInterface} parameters + * @returns */ static parametersToSchema(parameters) { if (parameters.length === 0) { @@ -479,4 +479,4 @@ export class SchemaHelpers { return {}; } } -} \ No newline at end of file +} diff --git a/test/components/Schema.test.js b/test/components/Schema.test.js index eaa6b5bb1..4a199f6e0 100644 --- a/test/components/Schema.test.js +++ b/test/components/Schema.test.js @@ -62,7 +62,7 @@ describe('Schema component', () => { | Name | Type | Description | Value | Constraints | Notes | |---|---|---|---|---|---| -| (root) | tuple> | - | - | - | **additional items are allowed** | +| (root) | tuple<string, string, integer, ...optional<any>> | - | - | - | **additional items are allowed** | | 0 (index) | string | The person's first name. | - | - | - | | 1 (index) | string | The person's last name. | - | - | - | | 2 (index) | integer | Age in years which must be equal to or greater than zero. | - | >= 0 | - | @@ -225,7 +225,7 @@ describe('Schema component', () => { | Name | Type | Description | Value | Constraints | Notes | |---|---|---|---|---|---| -| (root) | array | - | - | [ 1 .. 5 ] unique items | - | +| (root) | array<string> | - | - | [ 1 .. 5 ] unique items | - | | (single item) | string | - | - | format (\`email\`), [ 3 .. 26 ] characters | - | | (contains) | string | - | const (\`"email@example.com"\`) | - | - | `; @@ -266,7 +266,7 @@ describe('Schema component', () => { | Name | Type | Description | Value | Constraints | Notes | |---|---|---|---|---|---| -| (root) | tuple> | - | - | [ 1 .. 5 ] unique items | - | +| (root) | tuple<string, string, ...optional<integer>> | - | - | [ 1 .. 5 ] unique items | - | | 0 (index) | string | - | - | format (\`email\`), [ 3 .. 26 ] characters | - | | 1 (index) | string | - | - | format (\`email\`), [ 3 .. 26 ] characters | - | | (contains) | string | - | const (\`"email@example.com"\`) | - | - | @@ -334,7 +334,7 @@ describe('Schema component', () => { | productId | integer | The unique identifier for a product | - | - | **required** | | productName | string | Name of the product | - | - | **required** | | price | number | The price of the product | - | > 0 | **required** | -| tags | array | Tags for the product | - | non-empty | - | +| tags | array<string> | Tags for the product | - | non-empty | - | | tags (single item) | string | - | - | - | - | | dimensions | object | - | - | - | **additional properties are allowed** | | dimensions.length | number | - | - | - | **required** | @@ -559,15 +559,15 @@ describe('Schema component', () => { |---|---|---|---|---|---| | (root) | object | - | - | - | **additional properties are allowed** | | RecursiveSelf | object | - | - | - | **additional properties are allowed** | -| RecursiveSelf.selfChildren | array | - | - | - | - | -| RecursiveSelf.selfChildren.selfChildren | array | - | - | - | **circular** | +| RecursiveSelf.selfChildren | array<object> | - | - | - | - | +| RecursiveSelf.selfChildren.selfChildren | array<object> | - | - | - | **circular** | | RecursiveSelf.selfChildren.selfObjectChildren | object | - | - | - | **additional properties are allowed** | | RecursiveSelf.selfChildren.selfObjectChildren.test | object | - | - | - | **circular**, **additional properties are allowed** | | RecursiveSelf.selfChildren.selfObjectChildren.nonRecursive | string | - | - | - | - | | RecursiveSelf.selfChildren.selfSomething | object | - | - | - | **additional properties are allowed** | | RecursiveSelf.selfChildren.selfSomething.test | object | - | - | - | **additional properties are allowed** | -| RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren | array | - | - | - | - | -| RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren.selfChildren | array | - | - | - | **circular** | +| RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren | array<object> | - | - | - | - | +| RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren.selfChildren | array<object> | - | - | - | **circular** | | RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren.selfObjectChildren | object | - | - | - | **additional properties are allowed** | | RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren.selfObjectChildren.test | object | - | - | - | **circular**, **additional properties are allowed** | | RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren.selfObjectChildren.nonRecursive | string | - | - | - | - | @@ -578,9 +578,9 @@ describe('Schema component', () => { | RecursiveSelf.selfObjectChildren.nonRecursive | string | - | - | - | - | | RecursiveSelf.selfSomething | object | - | - | - | **additional properties are allowed** | | RecursiveSelf.selfSomething.test | object | - | - | - | **additional properties are allowed** | -| RecursiveSelf.selfSomething.test.ancestorChildren | array | - | - | - | - | -| RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren | array | - | - | - | - | -| RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren.selfChildren | array | - | - | - | **circular** | +| RecursiveSelf.selfSomething.test.ancestorChildren | array<object> | - | - | - | - | +| RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren | array<object> | - | - | - | - | +| RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren.selfChildren | array<object> | - | - | - | **circular** | | RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren.selfObjectChildren | object | - | - | - | **additional properties are allowed** | | RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren.selfObjectChildren.test | object | - | - | - | **circular**, **additional properties are allowed** | | RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren.selfObjectChildren.nonRecursive | string | - | - | - | - | @@ -591,9 +591,9 @@ describe('Schema component', () => { | RecursiveSelf.selfSomething.test.ancestorChildren.selfSomething | object | - | - | - | **circular**, **additional properties are allowed** | | RecursiveSelf.selfSomething.test.ancestorSomething | string | - | - | - | - | | RecursiveAncestor | object | - | - | - | **additional properties are allowed** | -| RecursiveAncestor.ancestorChildren | array | - | - | - | - | -| RecursiveAncestor.ancestorChildren.selfChildren | array | - | - | - | - | -| RecursiveAncestor.ancestorChildren.selfChildren.selfChildren | array | - | - | - | **circular** | +| RecursiveAncestor.ancestorChildren | array<object> | - | - | - | - | +| RecursiveAncestor.ancestorChildren.selfChildren | array<object> | - | - | - | - | +| RecursiveAncestor.ancestorChildren.selfChildren.selfChildren | array<object> | - | - | - | **circular** | | RecursiveAncestor.ancestorChildren.selfChildren.selfObjectChildren | object | - | - | - | **additional properties are allowed** | | RecursiveAncestor.ancestorChildren.selfChildren.selfObjectChildren.test | object | - | - | - | **circular**, **additional properties are allowed** | | RecursiveAncestor.ancestorChildren.selfChildren.selfObjectChildren.nonRecursive | string | - | - | - | - | diff --git a/test/helpers/schema.test.js b/test/helpers/schema.test.js index 26917e136..61ff3e0da 100644 --- a/test/helpers/schema.test.js +++ b/test/helpers/schema.test.js @@ -1,4 +1,4 @@ -import { +import { SchemaV2 as Schema, ChannelParameterV2 as ChannelParameter, } from '@asyncapi/parser'; @@ -81,7 +81,7 @@ describe('SchemaHelpers', () => { items: { type: ['string', 'number'] }, }); const result = SchemaHelpers.toSchemaType(schema); - expect(result).toEqual('array'); + expect(result).toEqual('array<string | number>'); }); test('should handle empty array type', () => { @@ -89,7 +89,7 @@ describe('SchemaHelpers', () => { type: 'array', }); const result = SchemaHelpers.toSchemaType(schema); - expect(result).toEqual(`array<${SchemaCustomTypes.ANY}>`); + expect(result).toEqual(`array<${SchemaCustomTypes.ANY}>`); }); test('should handle tuple types', () => { @@ -99,7 +99,7 @@ describe('SchemaHelpers', () => { }); const result = SchemaHelpers.toSchemaType(schema); expect(result).toEqual( - `tuple>`, + `tuple<object, string, ${SchemaCustomTypes.ANY}, ...optional<${SchemaCustomTypes.ANY}>>`, ); }); @@ -111,7 +111,7 @@ describe('SchemaHelpers', () => { }); const result = SchemaHelpers.toSchemaType(schema); expect(result).toEqual( - `tuple>`, + `tuple<object, string, ${SchemaCustomTypes.ANY}, ...optional<string>>`, ); }); @@ -123,7 +123,7 @@ describe('SchemaHelpers', () => { }); const result = SchemaHelpers.toSchemaType(schema); expect(result).toEqual( - `tuple>`, + `tuple<object, string, ${SchemaCustomTypes.ANY}, ...optional<${SchemaCustomTypes.ANY}>>`, ); }); @@ -134,7 +134,7 @@ describe('SchemaHelpers', () => { additionalItems: false, }); const result = SchemaHelpers.toSchemaType(schema); - expect(result).toEqual(`tuple`); + expect(result).toEqual(`tuple<object, string, ${SchemaCustomTypes.ANY}>`); }); test('should handle combined types', () => { @@ -703,4 +703,4 @@ describe('SchemaHelpers', () => { expect(result).toEqual(expected); }); }); -}); \ No newline at end of file +}); diff --git a/test/spec/asyncapi_v2.yml b/test/spec/asyncapi_v2.yml index d35f2c3ad..ee578452f 100644 --- a/test/spec/asyncapi_v2.yml +++ b/test/spec/asyncapi_v2.yml @@ -44,7 +44,7 @@ channels: operationId: receiveLightMeasurement tags: - name: oparation-tag1 - externalDocs: + externalDocs: description: External docs description 1 url: https://www.asyncapi.com/ - name: oparation-tag2 @@ -55,7 +55,7 @@ channels: - name: oparation-tag4 description: Description 4 - name: message-tag5 - externalDocs: + externalDocs: url: "https://www.asyncapi.com/" traits: - $ref: '#/components/operationTraits/kafka' @@ -111,7 +111,7 @@ components: contentType: application/json tags: - name: message-tag1 - externalDocs: + externalDocs: description: External docs description 1 url: https://www.asyncapi.com/ - name: message-tag2 @@ -122,7 +122,7 @@ components: - name: message-tag4 description: Description 4 - name: message-tag5 - externalDocs: + externalDocs: url: "https://www.asyncapi.com/" traits: - $ref: '#/components/messageTraits/commonHeaders' @@ -162,7 +162,7 @@ components: type: object properties: errorCode: - type: integer + type: integer errorMessage: type: string examples: