Skip to content

Commit

Permalink
fix: escape < > symbols (#542)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukasz Gornicki <[email protected]>
  • Loading branch information
korifey91 and derberg authored Apr 18, 2024
1 parent eb5cc70 commit 67e0cf3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
20 changes: 10 additions & 10 deletions helpers/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class SchemaHelpers {
if (schema.isBooleanSchema()) {
if (schema.json() === true) {
return SchemaCustomTypes.ANY;
}
}
return SchemaCustomTypes.NEVER;
}
// handle case with `{}` schemas
Expand Down Expand Up @@ -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&lt;${types || SchemaCustomTypes.UNKNOWN}, ...optional&lt;${SchemaCustomTypes.ANY}&gt;&gt;`;
}
if (additionalItems === false) {
return `tuple<${types}>`;
return `tuple&lt;${types}&gt;`;
}
const additionalType = this.toSchemaType(additionalItems);
return `tuple<${types || SchemaCustomTypes.UNKNOWN}, ...optional<${additionalType}>>`;
return `tuple&lt;${types || SchemaCustomTypes.UNKNOWN}, ...optional&lt;${additionalType}&gt;&gt;`;
}
if (!items) {
return `array<${SchemaCustomTypes.ANY}>`;
return `array&lt;${SchemaCustomTypes.ANY}&gt;`;
}
return `array<${this.toSchemaType(items) || SchemaCustomTypes.UNKNOWN}>`;
return `array&lt;${this.toSchemaType(items) || SchemaCustomTypes.UNKNOWN}&gt;`;
}
return type;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -479,4 +479,4 @@ export class SchemaHelpers {
return {};
}
}
}
}
28 changes: 14 additions & 14 deletions test/components/Schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Schema component', () => {
| Name | Type | Description | Value | Constraints | Notes |
|---|---|---|---|---|---|
| (root) | tuple<string, string, integer, ...optional<any>> | - | - | - | **additional items are allowed** |
| (root) | tuple&lt;string, string, integer, ...optional&lt;any&gt;&gt; | - | - | - | **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 | - |
Expand Down Expand Up @@ -225,7 +225,7 @@ describe('Schema component', () => {
| Name | Type | Description | Value | Constraints | Notes |
|---|---|---|---|---|---|
| (root) | array<string> | - | - | [ 1 .. 5 ] unique items | - |
| (root) | array&lt;string&gt; | - | - | [ 1 .. 5 ] unique items | - |
| (single item) | string | - | - | format (\`email\`), [ 3 .. 26 ] characters | - |
| (contains) | string | - | const (\`"[email protected]"\`) | - | - |
`;
Expand Down Expand Up @@ -266,7 +266,7 @@ describe('Schema component', () => {
| Name | Type | Description | Value | Constraints | Notes |
|---|---|---|---|---|---|
| (root) | tuple<string, string, ...optional<integer>> | - | - | [ 1 .. 5 ] unique items | - |
| (root) | tuple&lt;string, string, ...optional&lt;integer&gt;&gt; | - | - | [ 1 .. 5 ] unique items | - |
| 0 (index) | string | - | - | format (\`email\`), [ 3 .. 26 ] characters | - |
| 1 (index) | string | - | - | format (\`email\`), [ 3 .. 26 ] characters | - |
| (contains) | string | - | const (\`"[email protected]"\`) | - | - |
Expand Down Expand Up @@ -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<string> | Tags for the product | - | non-empty | - |
| tags | array&lt;string&gt; | Tags for the product | - | non-empty | - |
| tags (single item) | string | - | - | - | - |
| dimensions | object | - | - | - | **additional properties are allowed** |
| dimensions.length | number | - | - | - | **required** |
Expand Down Expand Up @@ -559,15 +559,15 @@ describe('Schema component', () => {
|---|---|---|---|---|---|
| (root) | object | - | - | - | **additional properties are allowed** |
| RecursiveSelf | object | - | - | - | **additional properties are allowed** |
| RecursiveSelf.selfChildren | array<object> | - | - | - | - |
| RecursiveSelf.selfChildren.selfChildren | array<object> | - | - | - | **circular** |
| RecursiveSelf.selfChildren | array&lt;object&gt; | - | - | - | - |
| RecursiveSelf.selfChildren.selfChildren | array&lt;object&gt; | - | - | - | **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<object> | - | - | - | - |
| RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren.selfChildren | array<object> | - | - | - | **circular** |
| RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren | array&lt;object&gt; | - | - | - | - |
| RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren.selfChildren | array&lt;object&gt; | - | - | - | **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 | - | - | - | - |
Expand All @@ -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<object> | - | - | - | - |
| RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren | array<object> | - | - | - | - |
| RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren.selfChildren | array<object> | - | - | - | **circular** |
| RecursiveSelf.selfSomething.test.ancestorChildren | array&lt;object&gt; | - | - | - | - |
| RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren | array&lt;object&gt; | - | - | - | - |
| RecursiveSelf.selfSomething.test.ancestorChildren.selfChildren.selfChildren | array&lt;object&gt; | - | - | - | **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 | - | - | - | - |
Expand All @@ -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<object> | - | - | - | - |
| RecursiveAncestor.ancestorChildren.selfChildren | array<object> | - | - | - | - |
| RecursiveAncestor.ancestorChildren.selfChildren.selfChildren | array<object> | - | - | - | **circular** |
| RecursiveAncestor.ancestorChildren | array&lt;object&gt; | - | - | - | - |
| RecursiveAncestor.ancestorChildren.selfChildren | array&lt;object&gt; | - | - | - | - |
| RecursiveAncestor.ancestorChildren.selfChildren.selfChildren | array&lt;object&gt; | - | - | - | **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 | - | - | - | - |
Expand Down
16 changes: 8 additions & 8 deletions test/helpers/schema.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import {
SchemaV2 as Schema,
ChannelParameterV2 as ChannelParameter,
} from '@asyncapi/parser';
Expand Down Expand Up @@ -81,15 +81,15 @@ describe('SchemaHelpers', () => {
items: { type: ['string', 'number'] },
});
const result = SchemaHelpers.toSchemaType(schema);
expect(result).toEqual('array<string | number>');
expect(result).toEqual('array&lt;string | number&gt;');
});

test('should handle empty array type', () => {
const schema = new Schema({
type: 'array',
});
const result = SchemaHelpers.toSchemaType(schema);
expect(result).toEqual(`array<${SchemaCustomTypes.ANY}>`);
expect(result).toEqual(`array&lt;${SchemaCustomTypes.ANY}&gt;`);
});

test('should handle tuple types', () => {
Expand All @@ -99,7 +99,7 @@ describe('SchemaHelpers', () => {
});
const result = SchemaHelpers.toSchemaType(schema);
expect(result).toEqual(
`tuple<object, string, ${SchemaCustomTypes.ANY}, ...optional<${SchemaCustomTypes.ANY}>>`,
`tuple&lt;object, string, ${SchemaCustomTypes.ANY}, ...optional&lt;${SchemaCustomTypes.ANY}&gt;&gt;`,
);
});

Expand All @@ -111,7 +111,7 @@ describe('SchemaHelpers', () => {
});
const result = SchemaHelpers.toSchemaType(schema);
expect(result).toEqual(
`tuple<object, string, ${SchemaCustomTypes.ANY}, ...optional<string>>`,
`tuple&lt;object, string, ${SchemaCustomTypes.ANY}, ...optional&lt;string&gt;&gt;`,
);
});

Expand All @@ -123,7 +123,7 @@ describe('SchemaHelpers', () => {
});
const result = SchemaHelpers.toSchemaType(schema);
expect(result).toEqual(
`tuple<object, string, ${SchemaCustomTypes.ANY}, ...optional<${SchemaCustomTypes.ANY}>>`,
`tuple&lt;object, string, ${SchemaCustomTypes.ANY}, ...optional&lt;${SchemaCustomTypes.ANY}&gt;&gt;`,
);
});

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

test('should handle combined types', () => {
Expand Down Expand Up @@ -703,4 +703,4 @@ describe('SchemaHelpers', () => {
expect(result).toEqual(expected);
});
});
});
});
10 changes: 5 additions & 5 deletions test/spec/asyncapi_v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -162,7 +162,7 @@ components:
type: object
properties:
errorCode:
type: integer
type: integer
errorMessage:
type: string
examples:
Expand Down

0 comments on commit 67e0cf3

Please sign in to comment.