From 07b739b01d466fa11794e6cdb34dba6ee796b53f Mon Sep 17 00:00:00 2001 From: Elakya Date: Wed, 25 Aug 2021 21:39:33 +0530 Subject: [PATCH 1/3] expose parser options as a seperate type --- lib/parser.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index f5286eaed..98e762cda 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -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} The parsed AsyncAPI document. */ async function parse(asyncapiYAMLorJSON, options = {}) { From 381636c001300bd08009ec43fa4bae61698df3d9 Mon Sep 17 00:00:00 2001 From: Elakya Date: Fri, 27 Aug 2021 13:02:44 +0530 Subject: [PATCH 2/3] feat: use new type parseroptions in other functions as well --- lib/parser.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index 98e762cda..f100a6b5d 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -123,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 {Object} [options] Configuration to pass to the {@link ParserOptions} method. * @returns {Promise} The parsed AsyncAPI document. */ function parseFromUrl(url, fetchOptions, options) { @@ -248,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 {Object} options Configuration options. {@link ParserOptions} */ async function customChannelsOperations(parsedJSON, asyncapiYAMLorJSON, initialFormat, options) { const promisesArray = []; @@ -279,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 {Object} options Configuration options. {@link ParserOptions} */ async function customComponentsMsgOperations(parsedJSON, asyncapiYAMLorJSON, initialFormat, options) { if (!parsedJSON.components || !parsedJSON.components.messages) return; From 4a71fad1ea311ab657f522ef6794c46509520d2e Mon Sep 17 00:00:00 2001 From: Elakya Date: Thu, 2 Sep 2021 11:33:47 +0400 Subject: [PATCH 3/3] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Maciej UrbaƄczyk --- lib/parser.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index f100a6b5d..6a158f052 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -123,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 ParserOptions} method. + * @param {ParserOptions} [options] Configuration to pass to the {@link ParserOptions} method. * @returns {Promise} The parsed AsyncAPI document. */ function parseFromUrl(url, fetchOptions, options) { @@ -248,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. {@link ParserOptions} + * @param {ParserOptions} options Configuration options. {@link ParserOptions} */ async function customChannelsOperations(parsedJSON, asyncapiYAMLorJSON, initialFormat, options) { const promisesArray = []; @@ -279,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. {@link ParserOptions} + * @param {ParserOptions} options Configuration options. {@link ParserOptions} */ async function customComponentsMsgOperations(parsedJSON, asyncapiYAMLorJSON, initialFormat, options) { if (!parsedJSON.components || !parsedJSON.components.messages) return;