Skip to content
Merged
Changes from all commits
Commits
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
21 changes: 13 additions & 8 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ module.exports = {
AsyncAPIDocument,
};

/**
* The complete list of parse configuration options used to parse the given data.
* @typedef {Object} ParserOptions
* @property {String} path - Path to the AsyncAPI document. It will be used to resolve relative references. Defaults to current working dir.
* @property {Object} parse - Options object to pass to {@link https://apidevtools.org/json-schema-ref-parser/docs/options.html|json-schema-ref-parser}.
* @property {Object} resolve - Options object to pass to {@link https://apidevtools.org/json-schema-ref-parser/docs/options.html|json-schema-ref-parser}.
* @property {Boolean} applyTraits - Whether to resolve and apply traits or not. Defaults to true.
*/

/**
* Parses and validate an AsyncAPI document from YAML or JSON.
*
* @param {(String | Object)} asyncapiYAMLorJSON An AsyncAPI document in JSON or YAML format.
* @param {Object} [options] Configuration options.
* @param {String} [options.path] Path to the AsyncAPI document. It will be used to resolve relative references. Defaults to current working dir.
* @param {Object} [options.parse] Options object to pass to {@link https://apidevtools.org/json-schema-ref-parser/docs/options.html|json-schema-ref-parser}.
* @param {Object} [options.resolve] Options object to pass to {@link https://apidevtools.org/json-schema-ref-parser/docs/options.html|json-schema-ref-parser}.
* @param {Object} [options.applyTraits=true] Whether to resolve and apply traits or not.
* @param {ParserOptions} options Configuration options object {@link ParserOptions}
* @returns {Promise<AsyncAPIDocument>} The parsed AsyncAPI document.
*/
async function parse(asyncapiYAMLorJSON, options = {}) {
Expand Down Expand Up @@ -118,7 +123,7 @@ async function parse(asyncapiYAMLorJSON, options = {}) {
*
* @param {String} url URL where the AsyncAPI document is located.
* @param {Object} [fetchOptions] Configuration to pass to the {@link https://developer.mozilla.org/en-US/docs/Web/API/Request|fetch} call.
* @param {Object} [options] Configuration to pass to the {@link module:Parser#parse} method.
* @param {ParserOptions} [options] Configuration to pass to the {@link ParserOptions} method.
* @returns {Promise<AsyncAPIDocument>} The parsed AsyncAPI document.
*/
function parseFromUrl(url, fetchOptions, options) {
Expand Down Expand Up @@ -243,7 +248,7 @@ function applyTraits(js) {
* @param {Object} parsedJSON parsed AsyncAPI document
* @param {String} asyncapiYAMLorJSON AsyncAPI document in string
* @param {String} initialFormat information of the document was originally JSON or YAML
* @param {Object} options Configuration options.
* @param {ParserOptions} options Configuration options. {@link ParserOptions}
*/
async function customChannelsOperations(parsedJSON, asyncapiYAMLorJSON, initialFormat, options) {
const promisesArray = [];
Expand Down Expand Up @@ -274,7 +279,7 @@ async function customChannelsOperations(parsedJSON, asyncapiYAMLorJSON, initialF
* @param {Object} parsedJSON parsed AsyncAPI document
* @param {String} asyncapiYAMLorJSON AsyncAPI document in string
* @param {String} initialFormat information of the document was originally JSON or YAML
* @param {Object} options Configuration options.
* @param {ParserOptions} options Configuration options. {@link ParserOptions}
*/
async function customComponentsMsgOperations(parsedJSON, asyncapiYAMLorJSON, initialFormat, options) {
if (!parsedJSON.components || !parsedJSON.components.messages) return;
Expand Down