docs(dotnet): generate arguments in a consistent order (#5800)
This commit is contained in:
parent
632ff111d4
commit
e82b546085
|
|
@ -314,8 +314,7 @@ Documentation.Member = class {
|
||||||
this.args.set(arg.name, arg);
|
this.args.set(arg.name, arg);
|
||||||
arg.enclosingMethod = this;
|
arg.enclosingMethod = this;
|
||||||
if (arg.name === 'options') {
|
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 [];
|
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
|
* @param {string} lang
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ function serializeProperty(arg) {
|
||||||
const result = { ...arg };
|
const result = { ...arg };
|
||||||
sanitize(result);
|
sanitize(result);
|
||||||
if (arg.type)
|
if (arg.type)
|
||||||
result.type = serializeType(arg.type)
|
result.type = serializeType(arg.type, arg.name === 'options')
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,18 +92,19 @@ function sanitize(result) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Documentation.Type} type
|
* @param {Documentation.Type} type
|
||||||
|
* @param {boolean} sortProperties
|
||||||
*/
|
*/
|
||||||
function serializeType(type) {
|
function serializeType(type, sortProperties = false) {
|
||||||
/** @type {any} */
|
/** @type {any} */
|
||||||
const result = { ...type };
|
const result = { ...type };
|
||||||
if (type.properties)
|
if (type.properties)
|
||||||
result.properties = type.properties.map(serializeProperty);
|
result.properties = (sortProperties ? type.sortedProperties() : type.properties).map(serializeProperty);
|
||||||
if (type.union)
|
if (type.union)
|
||||||
result.union = type.union.map(serializeType);
|
result.union = type.union.map(type => serializeType(type));
|
||||||
if (type.templates)
|
if (type.templates)
|
||||||
result.templates = type.templates.map(serializeType);
|
result.templates = type.templates.map(type => serializeType(type));
|
||||||
if (type.args)
|
if (type.args)
|
||||||
result.args = type.args.map(serializeType);
|
result.args = type.args.map(type => serializeType(type));
|
||||||
if (type.returnType)
|
if (type.returnType)
|
||||||
result.returnType = serializeType(type.returnType);
|
result.returnType = serializeType(type.returnType);
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -480,7 +480,6 @@ function renderMethod(member, parent, output, name) {
|
||||||
* @param {Documentation.Member} argument
|
* @param {Documentation.Member} argument
|
||||||
*/
|
*/
|
||||||
const pushArg = (innerArgType, innerArgName, argument) => {
|
const pushArg = (innerArgType, innerArgName, argument) => {
|
||||||
let isEnum = enumTypes.has(innerArgType);
|
|
||||||
let isNullable = nullableTypes.includes(innerArgType);
|
let isNullable = nullableTypes.includes(innerArgType);
|
||||||
const requiredPrefix = argument.required ? "" : isNullable ? "?" : "";
|
const requiredPrefix = argument.required ? "" : isNullable ? "?" : "";
|
||||||
const requiredSuffix = argument.required ? "" : " = default";
|
const requiredSuffix = argument.required ? "" : " = default";
|
||||||
|
|
@ -489,9 +488,7 @@ function renderMethod(member, parent, output, name) {
|
||||||
|
|
||||||
let parseArg = (/** @type {Documentation.Member} */ arg) => {
|
let parseArg = (/** @type {Documentation.Member} */ arg) => {
|
||||||
if (arg.name === "options") {
|
if (arg.name === "options") {
|
||||||
arg.type.properties.forEach(prop => {
|
arg.type.properties.forEach(parseArg);
|
||||||
parseArg(prop);
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -336,11 +336,12 @@ function stringifySimpleType(type, indent = '', ...namespace) {
|
||||||
if (type.name === 'Object' && type.properties && type.properties.length) {
|
if (type.name === 'Object' && type.properties && type.properties.length) {
|
||||||
const name = namespace.map(n => n[0].toUpperCase() + n.substring(1)).join('');
|
const name = namespace.map(n => n[0].toUpperCase() + n.substring(1)).join('');
|
||||||
const shouldExport = exported[name];
|
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) {
|
if (shouldExport) {
|
||||||
out = name;
|
out = name;
|
||||||
} else {
|
} else {
|
||||||
out = stringifyObjectType(type.properties, name, indent);
|
out = stringifyObjectType(properties, name, indent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue