diff --git a/docs/migrations/v3-to-v4.md b/docs/migrations/v3-to-v4.md new file mode 100644 index 000000000..58fb5b39f --- /dev/null +++ b/docs/migrations/v3-to-v4.md @@ -0,0 +1,24 @@ +# Migrating from v2 to v3 + +The ONLY thing that changes between v3 and v4 has to do with the standalone browser bundle. + +## New browser bundle + +In the old browser bundle you only had access to the parser. + +```js +const parser = new window.AsyncAPIParser(); +const spec = '{ ... }'; +const { document: parsedDocument, diagnostics } = await parser.parse(spec); +``` + +With the new browser bundle, you have access a bunch of support functions such as `fromURL`, `convertToOldAPI`, `unstringify`, `stringify`. + +```js +const parser = new window.AsyncAPIParser.Parser(); +const spec = '{ ... }'; +const { document: parsedDocument, diagnostics } = await parser.parse(spec); +... +const result = window.AsyncAPIParser.fromURL(parser, 'http://localhost:8080/asyncapi.json'); +const {document: parsedDocument, diagnostics} = await result.parse(); +``` diff --git a/test/browser/browser.spec.ts b/test/browser/browser.spec.ts index 091641e33..360bfcdcb 100644 --- a/test/browser/browser.spec.ts +++ b/test/browser/browser.spec.ts @@ -16,11 +16,16 @@ describe('Test browser Parser in the node env', function() { console.info('start server'); server = http.createServer((req, res) => { - res.writeHead(200, { 'content-type': 'text/html' }); if (req.url === '/') { + res.writeHead(200, { 'content-type': 'text/html' }); return fs.createReadStream(htmlPath).pipe(res); } else if (req.url === '/parser.js') { + res.writeHead(200, { 'content-type': 'text/html' }); return fs.createReadStream(parserScript).pipe(res); + } else if (req.url === '/asyncapi.json') { + res.writeHead(200, { 'content-type': 'application/json' }); + res.write(JSON.stringify({ asyncapi: '2.0.0', info: { title: 'My API', version: '1.0.0' }, channels: { '/test/tester': { subscribe: { operationId: 'subscribeOperation', message: { } } } } })); + res.end(); } }); server.listen(8080); @@ -40,11 +45,11 @@ describe('Test browser Parser in the node env', function() { console.info('navigating to localhost'); await page.goto('http://localhost:8080', { waitUntil: 'networkidle0' }); - }); + }, 10000); afterAll(async function() { await browser.close(); - await server.close(); + server.close(); }); it('should parse spec in the browser', async function() { @@ -58,4 +63,4 @@ describe('Test browser Parser in the node env', function() { const diagnostics = await page.evaluate(element => element && element.textContent, diagnosticsDiv); expect(Number(diagnostics)).toBeGreaterThanOrEqual(0); }, 5000); -}); \ No newline at end of file +}); diff --git a/test/browser/sample-page.html b/test/browser/sample-page.html index 50e8402b4..b03ab84e5 100644 --- a/test/browser/sample-page.html +++ b/test/browser/sample-page.html @@ -14,10 +14,9 @@