-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: parseFromUrl does not resolve relative references (#504)
- Loading branch information
Showing
13 changed files
with
145 additions
and
42 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ env: | |
node: true | ||
es6: true | ||
mocha: true | ||
browser: true | ||
|
||
plugins: | ||
- sonarjs | ||
|
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
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
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
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
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
type: object | ||
properties: | ||
testing: | ||
$ref: 'refed2.yaml' | ||
$ref: './refed2.yaml' |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,27 +1,58 @@ | ||
<body> | ||
<div id="fromString"> | ||
</div> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>AsyncAPI document parsing test</title> | ||
<script src="bundle.js"></script> | ||
<script> | ||
const convertChars2HTMLEntities = (jsonString) => { | ||
// Some characters in JSON received from the parser, might have special | ||
// meaning for browsers during their tokenization and DOM tree | ||
// construction stages. | ||
// This function allows to convert such characters, which introduce unexpected | ||
// bugs while they shouldn't, to HTML entities before inserting them into DOM. | ||
// During insertion into the DOM, browser converts such HTML entities back | ||
// to chars, inserting into DOM only characters which the next tool needs | ||
// to see (e.g. test automation framework which queries content of an | ||
// element, to assert the element contains exactly needed chars). | ||
jsonString = jsonString.replace(/</g, '<') | ||
jsonString = jsonString.replace(/>/g, '>'); | ||
|
||
return jsonString; | ||
} | ||
|
||
<div style="visibility: hidden;" id="fromUrl"> | ||
</div> | ||
</body> | ||
<script src="bundle.js"></script> | ||
<script defer> | ||
const execute = async() => { | ||
const parser = window.AsyncAPIParser; | ||
const execute = async () => { | ||
const parser = window.AsyncAPIParser; | ||
|
||
try { | ||
const specFromString = '{"asyncapi":"2.4.0","info":{"title":"Account Service","version":"1.0.0","description":"This service is in charge of processing user signups"},"channels":{"user/signedup":{"subscribe":{"message":{"$ref":"#/components/messages/UserSignedUp"}}}},"components":{"messages":{"UserSignedUp":{"payload":{"type":"object","properties":{"displayName":{"type":"string","description":"Name of the user"},"email":{"type":"string","format":"email","description":"Email of the user","test":{"$ref":"../refs/refed.yaml"}}}}}}}}'; | ||
let parsedFromString = await parser.parse(specFromString); | ||
parsedFromString = convertChars2HTMLEntities(JSON.stringify(parsedFromString.json())); | ||
document.getElementById('fromString').innerHTML = parsedFromString; | ||
|
||
try { | ||
const specFromString = '{ "asyncapi": "2.0.0", "info": { "title": "My API", "version": "1.0.0" }, "channels": { "/test/tester": { "subscribe": { "message": { } } } } }'; | ||
const parsedFromString = await parser.parse(specFromString); | ||
document.getElementById('fromString').innerHTML = parsedFromString.version(); | ||
let parsedFromUrl = await parser.parseFromUrl('http://127.0.0.1:8080/main/asyncapi.yaml'); | ||
parsedFromUrl = convertChars2HTMLEntities(JSON.stringify(parsedFromUrl._json)); | ||
const fromUrlElement = document.getElementById('fromUrl'); | ||
fromUrlElement.innerHTML = parsedFromUrl; | ||
fromUrlElement.style.visibility = 'visible'; | ||
|
||
const parsedFromUrl = await parser.parseFromUrl('http://127.0.0.1:8080/asyncapi.yaml'); | ||
const divElement = document.getElementById('fromUrl'); | ||
divElement.style.visibility = 'visible'; | ||
divElement.innerHTML = parsedFromUrl.version(); | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
} | ||
|
||
execute(); | ||
</script> | ||
</script> | ||
</head> | ||
<body> | ||
<p>#fromString</p> | ||
<div id="fromString"> | ||
</div> | ||
<br /> | ||
<p>#fromUrl</p> | ||
<div id="fromUrl" style="visibility: hidden;"> | ||
</div> | ||
</body> | ||
</html> |
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,25 @@ | ||
asyncapi: '2.4.0' | ||
info: | ||
title: Account Service | ||
version: 1.0.0 | ||
description: This service is in charge of processing user signups | ||
channels: | ||
user/signedup: | ||
subscribe: | ||
message: | ||
$ref: '#/components/messages/UserSignedUp' | ||
components: | ||
messages: | ||
UserSignedUp: | ||
payload: | ||
type: object | ||
properties: | ||
displayName: | ||
type: string | ||
description: Name of the user | ||
email: | ||
type: string | ||
format: email | ||
description: Email of the user | ||
test: | ||
$ref: '../refs/refed.yaml' |
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,6 @@ | ||
type: object | ||
properties: | ||
testing1: | ||
$ref: "./refed2.yaml" | ||
testing2: | ||
$ref: "http://localhost:8080/refs/refed2.yaml" |
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 @@ | ||
type: string |
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,14 @@ | ||
const chai = require('chai'); | ||
const chaiAsPromised = require('chai-as-promised'); | ||
const { getBaseUrl } = require('../lib/utils'); | ||
|
||
chai.use(chaiAsPromised); | ||
const expect = chai.expect; | ||
|
||
describe('getBaseUrl()', function () { | ||
it('should accept totally valid absolute URL of an AsyncAPI document', async function () { | ||
await expect( | ||
getBaseUrl('https://asyncapi.com/good/asyncapi.yaml') | ||
).to.equal('https://asyncapi.com/good/'); | ||
}); | ||
}); |