Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: escape < > symbols #542

Merged
merged 32 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
eb8b9d5
feat: common helpers with tests
korifey91 Apr 1, 2024
c3dd464
chore: update `@asyncapi/cli` and `@asyncapi/parser` versions
korifey91 Apr 1, 2024
7b2f685
fix: show operation reply messages
korifey91 Apr 1, 2024
400b4d0
fix(table of contents): correctly show all operations
korifey91 Apr 1, 2024
deaa2eb
feat(table of contents): use new `CommonHelpers` class for `Operation…
korifey91 Apr 9, 2024
a7e0ffc
fix: adjust `v2` operation types constants
korifey91 Apr 10, 2024
4182d41
feat(test): handle v3 `request` operation type
korifey91 Apr 10, 2024
eea544d
feat: move `isV3` helper into `CommonHelpers`
korifey91 Apr 10, 2024
0cb2e29
feat: show short operation type for v2
korifey91 Apr 10, 2024
2ab0ff8
chore: add comment to v2 operation types
korifey91 Apr 10, 2024
5b9c7f3
feat(test): add `CommonHelpers.isV3` unit tests
korifey91 Apr 10, 2024
9dcdd1e
feat: common helpers with tests
korifey91 Apr 1, 2024
130daed
chore: update `@asyncapi/cli` and `@asyncapi/parser` versions
korifey91 Apr 1, 2024
916ac2a
fix: show operation reply messages
korifey91 Apr 1, 2024
73bf5ed
fix(table of contents): correctly show all operations
korifey91 Apr 1, 2024
3de2a03
feat(table of contents): use new `CommonHelpers` class for `Operation…
korifey91 Apr 9, 2024
3b87982
fix: adjust `v2` operation types constants
korifey91 Apr 10, 2024
9199903
feat(test): handle v3 `request` operation type
korifey91 Apr 10, 2024
0e75817
feat: move `isV3` helper into `CommonHelpers`
korifey91 Apr 10, 2024
414da8a
feat: show short operation type for v2
korifey91 Apr 10, 2024
09da43e
chore: add comment to v2 operation types
korifey91 Apr 10, 2024
2839be0
feat(test): add `CommonHelpers.isV3` unit tests
korifey91 Apr 10, 2024
e5acf7a
Merge remote-tracking branch 'origin/master'
korifey91 Apr 11, 2024
24182cd
fix(test): create asyncapi doc with version using `createAsyncAPIDocu…
korifey91 Apr 11, 2024
0839c64
fix(test): use valid `bindingVersion` in `Operations` test in case `s…
korifey91 Apr 11, 2024
47b462b
fix(test): update snapshots
korifey91 Apr 11, 2024
225d428
Merge remote-tracking branch 'origin/master'
korifey91 Apr 18, 2024
d49f6b1
fix(schema): escape `< >` symbols in schema types
korifey91 Apr 18, 2024
21f8d89
Merge branch 'master' into master
korifey91 Apr 18, 2024
b530b5b
fix(schema): use `&lt;` and `&gt;` for `< >` symbols escaping
korifey91 Apr 18, 2024
4528ee2
Merge branch 'master' into master
derberg Apr 18, 2024
1f41bd6
Merge branch 'master' into master
derberg Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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\\<${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;
}
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\\<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 | - |
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\\<string\\> | - | - | [ 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\\<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 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\\<string\\> | 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\\<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<object> | - | - | - | - |
| RecursiveSelf.selfChildren.selfSomething.test.ancestorChildren.selfChildren | array<object> | - | - | - | **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 | - | - | - | - |
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\\<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 | - | - | - | - |
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\\<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 | - | - | - | - |
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\\<string | number\\>');
});

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\\<${SchemaCustomTypes.ANY}\\>`);
});

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\\<object, string, ${SchemaCustomTypes.ANY}, ...optional\\<${SchemaCustomTypes.ANY}\\>\\>`,
);
});

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

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\\<object, string, ${SchemaCustomTypes.ANY}, ...optional\\<${SchemaCustomTypes.ANY}\\>\\>`,
);
});

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\\<object, string, ${SchemaCustomTypes.ANY}\\>`);
});

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
Loading