Skip to content

Commit

Permalink
fix(schema): use &lt; and &gt; for < > symbols escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
korifey91 committed Apr 18, 2024
1 parent 21f8d89 commit b530b5b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
10 changes: 5 additions & 5 deletions helpers/schema.js
Original file line number Diff line number Diff line change
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
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
12 changes: 6 additions & 6 deletions test/helpers/schema.test.js
Original file line number Diff line number Diff line change
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

0 comments on commit b530b5b

Please sign in to comment.