Skip to content

Commit 67e0cf3

Browse files
korifey91derberg
andauthored
fix: escape < > symbols (#542)
Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
1 parent eb5cc70 commit 67e0cf3

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

helpers/schema.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class SchemaHelpers {
6464
if (schema.isBooleanSchema()) {
6565
if (schema.json() === true) {
6666
return SchemaCustomTypes.ANY;
67-
}
67+
}
6868
return SchemaCustomTypes.NEVER;
6969
}
7070
// handle case with `{}` schemas
@@ -100,18 +100,18 @@ export class SchemaHelpers {
100100
const types = items.map(item => this.toSchemaType(item)).join(', ');
101101
const additionalItems = schema.additionalItems();
102102
if (additionalItems === true) {
103-
return `tuple<${types || SchemaCustomTypes.UNKNOWN}, ...optional<${SchemaCustomTypes.ANY}>>`;
103+
return `tuple&lt;${types || SchemaCustomTypes.UNKNOWN}, ...optional&lt;${SchemaCustomTypes.ANY}&gt;&gt;`;
104104
}
105105
if (additionalItems === false) {
106-
return `tuple<${types}>`;
106+
return `tuple&lt;${types}&gt;`;
107107
}
108108
const additionalType = this.toSchemaType(additionalItems);
109-
return `tuple<${types || SchemaCustomTypes.UNKNOWN}, ...optional<${additionalType}>>`;
109+
return `tuple&lt;${types || SchemaCustomTypes.UNKNOWN}, ...optional&lt;${additionalType}&gt;&gt;`;
110110
}
111111
if (!items) {
112-
return `array<${SchemaCustomTypes.ANY}>`;
112+
return `array&lt;${SchemaCustomTypes.ANY}&gt;`;
113113
}
114-
return `array<${this.toSchemaType(items) || SchemaCustomTypes.UNKNOWN}>`;
114+
return `array&lt;${this.toSchemaType(items) || SchemaCustomTypes.UNKNOWN}&gt;`;
115115
}
116116
return type;
117117
}
@@ -195,9 +195,9 @@ export class SchemaHelpers {
195195
}
196196

197197
/**
198-
*
199-
* @param {import('@asyncapi/parser').ChannelParametersInterface} parameters
200-
* @returns
198+
*
199+
* @param {import('@asyncapi/parser').ChannelParametersInterface} parameters
200+
* @returns
201201
*/
202202
static parametersToSchema(parameters) {
203203
if (parameters.length === 0) {
@@ -479,4 +479,4 @@ export class SchemaHelpers {
479479
return {};
480480
}
481481
}
482-
}
482+
}

test/components/Schema.test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('Schema component', () => {
6262
6363
| Name | Type | Description | Value | Constraints | Notes |
6464
|---|---|---|---|---|---|
65-
| (root) | tuple<string, string, integer, ...optional<any>> | - | - | - | **additional items are allowed** |
65+
| (root) | tuple&lt;string, string, integer, ...optional&lt;any&gt;&gt; | - | - | - | **additional items are allowed** |
6666
| 0 (index) | string | The person's first name. | - | - | - |
6767
| 1 (index) | string | The person's last name. | - | - | - |
6868
| 2 (index) | integer | Age in years which must be equal to or greater than zero. | - | >= 0 | - |
@@ -225,7 +225,7 @@ describe('Schema component', () => {
225225
226226
| Name | Type | Description | Value | Constraints | Notes |
227227
|---|---|---|---|---|---|
228-
| (root) | array<string> | - | - | [ 1 .. 5 ] unique items | - |
228+
| (root) | array&lt;string&gt; | - | - | [ 1 .. 5 ] unique items | - |
229229
| (single item) | string | - | - | format (\`email\`), [ 3 .. 26 ] characters | - |
230230
| (contains) | string | - | const (\`"email@example.com"\`) | - | - |
231231
`;
@@ -266,7 +266,7 @@ describe('Schema component', () => {
266266
267267
| Name | Type | Description | Value | Constraints | Notes |
268268
|---|---|---|---|---|---|
269-
| (root) | tuple<string, string, ...optional<integer>> | - | - | [ 1 .. 5 ] unique items | - |
269+
| (root) | tuple&lt;string, string, ...optional&lt;integer&gt;&gt; | - | - | [ 1 .. 5 ] unique items | - |
270270
| 0 (index) | string | - | - | format (\`email\`), [ 3 .. 26 ] characters | - |
271271
| 1 (index) | string | - | - | format (\`email\`), [ 3 .. 26 ] characters | - |
272272
| (contains) | string | - | const (\`"email@example.com"\`) | - | - |
@@ -334,7 +334,7 @@ describe('Schema component', () => {
334334
| productId | integer | The unique identifier for a product | - | - | **required** |
335335
| productName | string | Name of the product | - | - | **required** |
336336
| price | number | The price of the product | - | > 0 | **required** |
337-
| tags | array<string> | Tags for the product | - | non-empty | - |
337+
| tags | array&lt;string&gt; | Tags for the product | - | non-empty | - |
338338
| tags (single item) | string | - | - | - | - |
339339
| dimensions | object | - | - | - | **additional properties are allowed** |
340340
| dimensions.length | number | - | - | - | **required** |
@@ -559,15 +559,15 @@ describe('Schema component', () => {
559559
|---|---|---|---|---|---|
560560
| (root) | object | - | - | - | **additional properties are allowed** |
561561
| RecursiveSelf | object | - | - | - | **additional properties are allowed** |
562-
| RecursiveSelf.selfChildren | array<object> | - | - | - | - |
563-
| RecursiveSelf.selfChildren.selfChildren | array<object> | - | - | - | **circular** |
562+
| RecursiveSelf.selfChildren | array&lt;object&gt; | - | - | - | - |
563+
| RecursiveSelf.selfChildren.selfChildren | array&lt;object&gt; | - | - | - | **circular** |
564564
| RecursiveSelf.selfChildren.selfObjectChildren | object | - | - | - | **additional properties are allowed** |
565565
| RecursiveSelf.selfChildren.selfObjectChildren.test | object | - | - | - | **circular**, **additional properties are allowed** |
566566
| RecursiveSelf.selfChildren.selfObjectChildren.nonRecursive | string | - | - | - | - |
567567
| RecursiveSelf.selfChildren.selfSomething | object | - | - | - | **additional properties are allowed** |
568568
| RecursiveSelf.selfChildren.selfSomething.test | object | - | - | - | **additional properties are allowed** |
569-
| RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren | array<object> | - | - | - | - |
570-
| RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren.selfChildren | array<object> | - | - | - | **circular** |
569+
| RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren | array&lt;object&gt; | - | - | - | - |
570+
| RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren.selfChildren | array&lt;object&gt; | - | - | - | **circular** |
571571
| RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren.selfObjectChildren | object | - | - | - | **additional properties are allowed** |
572572
| RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren.selfObjectChildren.test | object | - | - | - | **circular**, **additional properties are allowed** |
573573
| RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren.selfObjectChildren.nonRecursive | string | - | - | - | - |
@@ -578,9 +578,9 @@ describe('Schema component', () => {
578578
| RecursiveSelf.selfObjectChildren.nonRecursive | string | - | - | - | - |
579579
| RecursiveSelf.selfSomething | object | - | - | - | **additional properties are allowed** |
580580
| RecursiveSelf.selfSomething.test | object | - | - | - | **additional properties are allowed** |
581-
| RecursiveSelf.selfSomething.test.ancestorChildren | array<object> | - | - | - | - |
582-
| RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren | array<object> | - | - | - | - |
583-
| RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren.selfChildren | array<object> | - | - | - | **circular** |
581+
| RecursiveSelf.selfSomething.test.ancestorChildren | array&lt;object&gt; | - | - | - | - |
582+
| RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren | array&lt;object&gt; | - | - | - | - |
583+
| RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren.selfChildren | array&lt;object&gt; | - | - | - | **circular** |
584584
| RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren.selfObjectChildren | object | - | - | - | **additional properties are allowed** |
585585
| RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren.selfObjectChildren.test | object | - | - | - | **circular**, **additional properties are allowed** |
586586
| RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren.selfObjectChildren.nonRecursive | string | - | - | - | - |
@@ -591,9 +591,9 @@ describe('Schema component', () => {
591591
| RecursiveSelf.selfSomething.test.ancestorChildren.selfSomething | object | - | - | - | **circular**, **additional properties are allowed** |
592592
| RecursiveSelf.selfSomething.test.ancestorSomething | string | - | - | - | - |
593593
| RecursiveAncestor | object | - | - | - | **additional properties are allowed** |
594-
| RecursiveAncestor.ancestorChildren | array<object> | - | - | - | - |
595-
| RecursiveAncestor.ancestorChildren.selfChildren | array<object> | - | - | - | - |
596-
| RecursiveAncestor.ancestorChildren.selfChildren.selfChildren | array<object> | - | - | - | **circular** |
594+
| RecursiveAncestor.ancestorChildren | array&lt;object&gt; | - | - | - | - |
595+
| RecursiveAncestor.ancestorChildren.selfChildren | array&lt;object&gt; | - | - | - | - |
596+
| RecursiveAncestor.ancestorChildren.selfChildren.selfChildren | array&lt;object&gt; | - | - | - | **circular** |
597597
| RecursiveAncestor.ancestorChildren.selfChildren.selfObjectChildren | object | - | - | - | **additional properties are allowed** |
598598
| RecursiveAncestor.ancestorChildren.selfChildren.selfObjectChildren.test | object | - | - | - | **circular**, **additional properties are allowed** |
599599
| RecursiveAncestor.ancestorChildren.selfChildren.selfObjectChildren.nonRecursive | string | - | - | - | - |

test/helpers/schema.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {
1+
import {
22
SchemaV2 as Schema,
33
ChannelParameterV2 as ChannelParameter,
44
} from '@asyncapi/parser';
@@ -81,15 +81,15 @@ describe('SchemaHelpers', () => {
8181
items: { type: ['string', 'number'] },
8282
});
8383
const result = SchemaHelpers.toSchemaType(schema);
84-
expect(result).toEqual('array<string | number>');
84+
expect(result).toEqual('array&lt;string | number&gt;');
8585
});
8686

8787
test('should handle empty array type', () => {
8888
const schema = new Schema({
8989
type: 'array',
9090
});
9191
const result = SchemaHelpers.toSchemaType(schema);
92-
expect(result).toEqual(`array<${SchemaCustomTypes.ANY}>`);
92+
expect(result).toEqual(`array&lt;${SchemaCustomTypes.ANY}&gt;`);
9393
});
9494

9595
test('should handle tuple types', () => {
@@ -99,7 +99,7 @@ describe('SchemaHelpers', () => {
9999
});
100100
const result = SchemaHelpers.toSchemaType(schema);
101101
expect(result).toEqual(
102-
`tuple<object, string, ${SchemaCustomTypes.ANY}, ...optional<${SchemaCustomTypes.ANY}>>`,
102+
`tuple&lt;object, string, ${SchemaCustomTypes.ANY}, ...optional&lt;${SchemaCustomTypes.ANY}&gt;&gt;`,
103103
);
104104
});
105105

@@ -111,7 +111,7 @@ describe('SchemaHelpers', () => {
111111
});
112112
const result = SchemaHelpers.toSchemaType(schema);
113113
expect(result).toEqual(
114-
`tuple<object, string, ${SchemaCustomTypes.ANY}, ...optional<string>>`,
114+
`tuple&lt;object, string, ${SchemaCustomTypes.ANY}, ...optional&lt;string&gt;&gt;`,
115115
);
116116
});
117117

@@ -123,7 +123,7 @@ describe('SchemaHelpers', () => {
123123
});
124124
const result = SchemaHelpers.toSchemaType(schema);
125125
expect(result).toEqual(
126-
`tuple<object, string, ${SchemaCustomTypes.ANY}, ...optional<${SchemaCustomTypes.ANY}>>`,
126+
`tuple&lt;object, string, ${SchemaCustomTypes.ANY}, ...optional&lt;${SchemaCustomTypes.ANY}&gt;&gt;`,
127127
);
128128
});
129129

@@ -134,7 +134,7 @@ describe('SchemaHelpers', () => {
134134
additionalItems: false,
135135
});
136136
const result = SchemaHelpers.toSchemaType(schema);
137-
expect(result).toEqual(`tuple<object, string, ${SchemaCustomTypes.ANY}>`);
137+
expect(result).toEqual(`tuple&lt;object, string, ${SchemaCustomTypes.ANY}&gt;`);
138138
});
139139

140140
test('should handle combined types', () => {
@@ -703,4 +703,4 @@ describe('SchemaHelpers', () => {
703703
expect(result).toEqual(expected);
704704
});
705705
});
706-
});
706+
});

test/spec/asyncapi_v2.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ channels:
4444
operationId: receiveLightMeasurement
4545
tags:
4646
- name: oparation-tag1
47-
externalDocs:
47+
externalDocs:
4848
description: External docs description 1
4949
url: https://www.asyncapi.com/
5050
- name: oparation-tag2
@@ -55,7 +55,7 @@ channels:
5555
- name: oparation-tag4
5656
description: Description 4
5757
- name: message-tag5
58-
externalDocs:
58+
externalDocs:
5959
url: "https://www.asyncapi.com/"
6060
traits:
6161
- $ref: '#/components/operationTraits/kafka'
@@ -111,7 +111,7 @@ components:
111111
contentType: application/json
112112
tags:
113113
- name: message-tag1
114-
externalDocs:
114+
externalDocs:
115115
description: External docs description 1
116116
url: https://www.asyncapi.com/
117117
- name: message-tag2
@@ -122,7 +122,7 @@ components:
122122
- name: message-tag4
123123
description: Description 4
124124
- name: message-tag5
125-
externalDocs:
125+
externalDocs:
126126
url: "https://www.asyncapi.com/"
127127
traits:
128128
- $ref: '#/components/messageTraits/commonHeaders'
@@ -162,7 +162,7 @@ components:
162162
type: object
163163
properties:
164164
errorCode:
165-
type: integer
165+
type: integer
166166
errorMessage:
167167
type: string
168168
examples:

0 commit comments

Comments
 (0)