-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0501206
commit 9d5f7ac
Showing
2 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { AsyncAPIDocumentV2 } from '../../src/models'; | ||
import { Parser } from '../../src/parser'; | ||
|
||
import type { v2 } from '../../src/spec-types'; | ||
|
||
describe('custom operations for v2 - parse schemas', function() { | ||
const parser = new Parser(); | ||
|
||
it('should parse valid schema format', async function() { | ||
const documentRaw = { | ||
asyncapi: '2.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0', | ||
}, | ||
channels: { | ||
channel: { | ||
publish: { | ||
operationId: 'operationId', | ||
message: { | ||
schemaFormat: 'application/vnd.aai.asyncapi;version=2.0.0', | ||
payload: { | ||
type: 'object', | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const { document, diagnostics } = await parser.parse(documentRaw); | ||
|
||
expect(document).toBeInstanceOf(AsyncAPIDocumentV2); | ||
expect(diagnostics.length > 0).toEqual(true); | ||
|
||
expect((document?.json()?.channels?.channel?.publish?.message as v2.MessageObject)?.payload).toEqual({ type: 'object', 'x-parser-schema-id': '<anonymous-schema-1>' }); | ||
}); | ||
|
||
it('should parse valid default schema format', async function() { | ||
const documentRaw = { | ||
asyncapi: '2.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0', | ||
}, | ||
channels: { | ||
channel: { | ||
publish: { | ||
operationId: 'operationId', | ||
message: { | ||
payload: { | ||
type: 'object', | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const { document, diagnostics } = await parser.parse(documentRaw); | ||
|
||
expect(document).toBeInstanceOf(AsyncAPIDocumentV2); | ||
expect(diagnostics.length > 0).toEqual(true); | ||
|
||
expect((document?.json()?.channels?.channel?.publish?.message as v2.MessageObject)?.payload).toEqual({ type: 'object', 'x-parser-schema-id': '<anonymous-schema-1>' }); | ||
}); | ||
|
||
it('should preserve this same references', async function() { | ||
const documentRaw = { | ||
asyncapi: '2.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0', | ||
}, | ||
channels: { | ||
channel: { | ||
publish: { | ||
operationId: 'operationId', | ||
message: { | ||
$ref: '#/components/messages/message' | ||
} | ||
} | ||
} | ||
}, | ||
components: { | ||
messages: { | ||
message: { | ||
payload: { | ||
type: 'object', | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const { document, diagnostics } = await parser.parse(documentRaw); | ||
|
||
expect(document).toBeInstanceOf(AsyncAPIDocumentV2); | ||
expect(diagnostics.length > 0).toEqual(true); | ||
|
||
expect((document?.json()?.channels?.channel?.publish?.message as v2.MessageObject)?.payload).toEqual({ type: 'object', 'x-parser-schema-id': '<anonymous-schema-1>' }); | ||
expect((document?.json().components?.messages?.message as v2.MessageObject)?.payload).toEqual({ type: 'object', 'x-parser-schema-id': '<anonymous-schema-1>' }); | ||
// check if logic preserves references | ||
expect((document?.json()?.channels?.channel?.publish?.message as v2.MessageObject)?.payload === (document?.json().components?.messages?.message as v2.MessageObject)?.payload).toEqual(true); | ||
}); | ||
|
||
it('should parse invalid schema format', async function() { | ||
const documentRaw = { | ||
asyncapi: '2.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0', | ||
}, | ||
channels: { | ||
channel: { | ||
publish: { | ||
operationId: 'operationId', | ||
message: { | ||
schemaFormat: 'not existing', | ||
payload: { | ||
type: 'object', | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const { document, diagnostics } = await parser.parse(documentRaw); | ||
|
||
expect(document).toBeUndefined(); | ||
expect(diagnostics.length > 0).toEqual(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import { AsyncAPIDocumentV3 } from '../../src/models'; | ||
import { Parser } from '../../src/parser'; | ||
|
||
import type { v3 } from '../../src/spec-types'; | ||
|
||
describe('custom operations for v3 - parse schemas', function() { | ||
const parser = new Parser(); | ||
|
||
it('should parse valid schema format', async function() { | ||
const documentRaw = { | ||
asyncapi: '3.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0' | ||
}, | ||
channels: { | ||
channel: { | ||
address: 'channel', | ||
messages: { | ||
message: { | ||
payload: { | ||
schemaFormat: 'application/vnd.aai.asyncapi;version=2.0.0', | ||
schema: { | ||
type: 'object' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const { document, diagnostics } = await parser.parse(documentRaw); | ||
|
||
expect(document).toBeInstanceOf(AsyncAPIDocumentV3); | ||
expect(diagnostics.length === 0).toEqual(true); | ||
|
||
expect(((document?.json()?.channels?.channel as v3.ChannelObject).messages?.message as v3.MessageObject)?.payload?.schema).toEqual({ type: 'object', 'x-parser-schema-id': '<anonymous-schema-1>' }); | ||
}); | ||
|
||
it('should parse valid default schema format', async function() { | ||
const documentRaw = { | ||
asyncapi: '3.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0' | ||
}, | ||
channels: { | ||
channel: { | ||
address: 'channel', | ||
messages: { | ||
message: { | ||
payload: { | ||
type: 'object' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const { document, diagnostics } = await parser.parse(documentRaw); | ||
|
||
expect(document).toBeInstanceOf(AsyncAPIDocumentV3); | ||
expect(diagnostics.length === 0).toEqual(true); | ||
|
||
expect(((document?.json()?.channels?.channel as v3.ChannelObject).messages?.message as v3.MessageObject)?.payload).toEqual({ type: 'object', 'x-parser-schema-id': '<anonymous-schema-1>' }); | ||
}); | ||
|
||
it('should preserve this same references', async function() { | ||
const documentRaw = { | ||
asyncapi: '3.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0' | ||
}, | ||
channels: { | ||
channel: { | ||
address: 'channel', | ||
messages: { | ||
message: { | ||
$ref: '#/components/messages/message' | ||
} | ||
} | ||
} | ||
}, | ||
operations: { | ||
operationId: { | ||
action: 'receive', | ||
channel: { | ||
$ref: '#/channels/channel' | ||
}, | ||
messages: [ | ||
{ | ||
$ref: '#/components/messages/message' | ||
} | ||
] | ||
} | ||
}, | ||
components: { | ||
messages: { | ||
message: { | ||
payload: { | ||
type: 'object' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const { document, diagnostics } = await parser.parse(documentRaw); | ||
console.log(diagnostics) | ||
Check failure on line 109 in test/custom-operations/parse-schema-v3.spec.ts GitHub Actions / Test NodeJS PR - ubuntu-latest
|
||
expect(document).toBeInstanceOf(AsyncAPIDocumentV3); | ||
expect(diagnostics.length === 0).toEqual(true); | ||
|
||
expect(((document?.json()?.channels?.channel as v3.ChannelObject).messages?.message as v3.MessageObject)?.payload).toEqual({ type: 'object', 'x-parser-schema-id': '<anonymous-schema-1>' }); | ||
expect((document?.json().components?.messages?.message as v3.MessageObject)?.payload).toEqual({ type: 'object', 'x-parser-schema-id': '<anonymous-schema-1>' }); | ||
// check if logic preserves references | ||
expect(((document?.json()?.channels?.channel as v3.ChannelObject).messages?.message as v3.MessageObject)?.payload === (document?.json().components?.messages?.message as v3.MessageObject)?.payload).toEqual(true); | ||
}); | ||
|
||
it('should parse invalid schema format', async function() { | ||
const documentRaw = { | ||
asyncapi: '3.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0' | ||
}, | ||
channels: { | ||
channel: { | ||
address: 'channel', | ||
messages: { | ||
message: { | ||
payload: { | ||
schemaFormat: 'not existing', | ||
schema: { | ||
type: 'object' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const { document, diagnostics } = await parser.parse(documentRaw); | ||
|
||
expect(document).toBeUndefined(); | ||
expect(diagnostics.length > 0).toEqual(true); | ||
}); | ||
}); |