diff --git a/utils/doclint/documentation.js b/utils/doclint/documentation.js index e2568addf2..8747f4ee0a 100644 --- a/utils/doclint/documentation.js +++ b/utils/doclint/documentation.js @@ -314,8 +314,7 @@ Documentation.Member = class { this.args.set(arg.name, arg); arg.enclosingMethod = this; if (arg.name === 'options') { - arg.type.properties.sort((p1, p2) => p1.name.localeCompare(p2.name)); - arg.type.properties.forEach(p => p.enclosingMethod = this); + arg.type.properties.forEach(p => p.enclosingMethod = this ); } } } @@ -500,6 +499,17 @@ Documentation.Type = class { return []; } + /** + * @returns {Documentation.Member[]} + */ + sortedProperties() { + if (!this.properties) + return this.properties; + const sortedProperties = [...this.properties]; + sortedProperties.sort((p1, p2) => p1.name.localeCompare(p2.name)); + return sortedProperties; + } + /** * @param {string} lang */ diff --git a/utils/doclint/generateApiJson.js b/utils/doclint/generateApiJson.js index 75448bf9a5..8b36ef00f9 100644 --- a/utils/doclint/generateApiJson.js +++ b/utils/doclint/generateApiJson.js @@ -79,7 +79,7 @@ function serializeProperty(arg) { const result = { ...arg }; sanitize(result); if (arg.type) - result.type = serializeType(arg.type) + result.type = serializeType(arg.type, arg.name === 'options') return result; } @@ -92,18 +92,19 @@ function sanitize(result) { /** * @param {Documentation.Type} type + * @param {boolean} sortProperties */ -function serializeType(type) { +function serializeType(type, sortProperties = false) { /** @type {any} */ const result = { ...type }; if (type.properties) - result.properties = type.properties.map(serializeProperty); + result.properties = (sortProperties ? type.sortedProperties() : type.properties).map(serializeProperty); if (type.union) - result.union = type.union.map(serializeType); + result.union = type.union.map(type => serializeType(type)); if (type.templates) - result.templates = type.templates.map(serializeType); + result.templates = type.templates.map(type => serializeType(type)); if (type.args) - result.args = type.args.map(serializeType); + result.args = type.args.map(type => serializeType(type)); if (type.returnType) result.returnType = serializeType(type.returnType); return result; diff --git a/utils/doclint/generateDotnetApi.js b/utils/doclint/generateDotnetApi.js index 8cb5c45a2b..c97e38a2dd 100644 --- a/utils/doclint/generateDotnetApi.js +++ b/utils/doclint/generateDotnetApi.js @@ -480,7 +480,6 @@ function renderMethod(member, parent, output, name) { * @param {Documentation.Member} argument */ const pushArg = (innerArgType, innerArgName, argument) => { - let isEnum = enumTypes.has(innerArgType); let isNullable = nullableTypes.includes(innerArgType); const requiredPrefix = argument.required ? "" : isNullable ? "?" : ""; const requiredSuffix = argument.required ? "" : " = default"; @@ -489,9 +488,7 @@ function renderMethod(member, parent, output, name) { let parseArg = (/** @type {Documentation.Member} */ arg) => { if (arg.name === "options") { - arg.type.properties.forEach(prop => { - parseArg(prop); - }); + arg.type.properties.forEach(parseArg); return; } diff --git a/utils/generate_types/index.js b/utils/generate_types/index.js index fc56ce4e2e..6e63134c0a 100644 --- a/utils/generate_types/index.js +++ b/utils/generate_types/index.js @@ -336,11 +336,12 @@ function stringifySimpleType(type, indent = '', ...namespace) { if (type.name === 'Object' && type.properties && type.properties.length) { const name = namespace.map(n => n[0].toUpperCase() + n.substring(1)).join(''); const shouldExport = exported[name]; - objectDefinitions.push({name, properties: type.properties}); + const properties = namespace[namespace.length -1] === 'options' ? type.sortedProperties() : type.properties; + objectDefinitions.push({name, properties: properties}); if (shouldExport) { out = name; } else { - out = stringifyObjectType(type.properties, name, indent); + out = stringifyObjectType(properties, name, indent); } }