-
-
Notifications
You must be signed in to change notification settings - Fork 325
chore: add new helper function getInfo()
#1567
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
Changes from 3 commits
629995b
1d7a44e
238d80b
5c8367d
c290aaa
651af4a
1bfaa3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,8 +35,31 @@ const listFiles = async (dir) => { | |
.map(dirE => dirE.name); | ||
}; | ||
|
||
/** | ||
* Validate and retrieve the AsyncAPI info object from an AsyncAPI document. | ||
* | ||
* Throws an error if the provided AsyncAPI document has no `info` section. | ||
* | ||
* @param {object} asyncapi - The AsyncAPI document object. | ||
* @returns {object} The validated info object from the AsyncAPI document. | ||
*/ | ||
const getInfo = (asyncapi) => { | ||
if (!asyncapi) { | ||
throw new Error('Provided AsyncAPI document is invaild.'); | ||
} | ||
if (!asyncapi.info) { | ||
throw new Error('Provided AsyncAPI document doesn\'t contain info.'); | ||
|
||
} | ||
const info = asyncapi.info(); | ||
if (!info) { | ||
throw new Error('AsyncAPI document info object cannot be an empty.'); | ||
} | ||
return info; | ||
}; | ||
|
||
module.exports = { | ||
getClientName, | ||
listFiles | ||
listFiles, | ||
getInfo | ||
}; | ||
|
Uh oh!
There was an error while loading. Please reload this page.