This commit is contained in:
Xiaogang 2023-09-19 18:33:19 +08:00 коммит произвёл GitHub
Родитель 6efb04ba3a
Коммит 0a80e267aa
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 31 добавлений и 8 удалений

Просмотреть файл

@ -66,7 +66,7 @@ if (item.language.default.description) {
/// <%-choice.language.default.description%>
/// </summary>
<%}-%>
public const string <%-choice.language.default.name%> = "<%-choice.value%>";
public const string <%-project.helper.GetValidCsharpName(choice.language.default.name)%> = "<%-choice.value%>";
<%});-%>
}
<% } -%>

Просмотреть файл

@ -9,7 +9,7 @@
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
<% if(method.parameters && !method.language.default.pageable?.nextPageOperation) { method.parameters.filter(p => p.implementation != 'Client' && !project.helper.IsConstantParameter(p)).forEach(function (parameter) {-%>
<% if(method.parameters && !method.language.default.pageable?.nextPageOperation) { method.parameters.filter(p => p.implementation != 'Client' && !project.helper.IsConstantParameter(p) && !(p.extensions && p.extensions['x-ms-parameter-grouping'])).forEach(function (parameter) {-%>
/// <param name='<%-parameter.language.default.name%>'>
/// <%=parameter.language.default.description%>
/// </param>
@ -39,7 +39,7 @@
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
<% if(method.parameters && !method.language.default.pageable?.nextPageOperation) { method.parameters.filter(p => p.implementation != 'Client' && !project.helper.IsConstantParameter(p)).forEach(function (parameter) {-%>
<% if(method.parameters && !method.language.default.pageable?.nextPageOperation) { method.parameters.filter(p => p.implementation != 'Client' && !project.helper.IsConstantParameter(p) && !p.readOnly).forEach(function (parameter) {-%>
/// <param name='<%-parameter.language.default.name%>'>
/// <%=parameter.language.default.description%>
/// </param>

Просмотреть файл

@ -55,10 +55,13 @@ if (method.extensions && method.extensions['x-ms-request-id']) {
<%});-%>
<%# ToDo: add support for BuildInputMappings -%>
<% (method.requests[0].parameters || []).filter(p=>p.protocol.http.in == 'body').forEach(function(parameter){-%>
<%if(parameter.extensions && parameter.extensions['x-ms-client-flatten']) {-%>
<%if(parameter.extensions && parameter.extensions['x-ms-client-flatten']) {
var vps = project.helper.GetAllPublicVirtualProperties(parameter.schema.language.default.virtualProperties).filter(vp => !project.helper.IsConstantEnumProperty(vp) && !vp.readOnly);
parameter.language.default.name = project.helper.GetUniqueName(parameter.language.default.name, vps.map(function(vp) {return vp.property.language.default.name;}));
-%>
<%-parameter.schema.language.default.name%> <%-parameter.language.default.name%> = new <%-parameter.schema.language.default.name%>();
<% var vps = project.helper.GetAllPublicVirtualProperties(parameter.schema.language.default.virtualProperties).filter(vp => !project.helper.IsConstantEnumProperty(vp) && !vp.readOnly)
var vpsWithNullCheck = vps.filter(virtualProperty => project.helper.IsNullCheckRequiredForVirtualProperty(virtualProperty));
<% var vpsWithNullCheck = vps.filter(virtualProperty => project.helper.IsNullCheckRequiredForVirtualProperty(virtualProperty));
var vpsWithoutNullCheck = vps.filter(virtualProperty => !project.helper.IsNullCheckRequiredForVirtualProperty(virtualProperty));
-%>
<% if(vpsWithNullCheck.length > 0) {-%>

Просмотреть файл

@ -10,14 +10,14 @@
/// </remarks>
<% };-%>
<% if(!method.language.default.pageable?.nextPageOperation) {-%>
<% method.parameters.filter(p=>p.implementation != 'Client' && !project.helper.IsConstantParameter(p)).forEach(function(parameter){-%>
<% method.parameters.filter(p=>p.implementation != 'Client' && !project.helper.IsConstantParameter(p) && !(p.extensions && p.extensions['x-ms-parameter-grouping'])).forEach(function(parameter){-%>
/// <param name='<%-parameter.language.default.name%>'>
/// <%= parameter.language.default.description%>
/// </param>
<% }); -%>
<% (method.requests[0].parameters || []).filter(p=>p.protocol.http.in == 'body' && !project.helper.IsConstantEnumParameter(p)).forEach(function(parameter){-%>
<%if(parameter.extensions && parameter.extensions['x-ms-client-flatten'] ) {-%>
<%project.helper.GetAllPublicVirtualProperties(parameter.schema.language.default.virtualProperties).filter(p => !project.helper.IsConstantEnumProperty(p)).forEach(function(vp) {-%>
<%project.helper.GetAllPublicVirtualProperties(parameter.schema.language.default.virtualProperties).filter(p => !project.helper.IsConstantEnumProperty(p) && !p.readOnly).forEach(function(vp) {-%>
/// <param name='<%-vp.property.language.default.name%>'>
/// <%= vp.property.language.default.description%>
/// </param>

Просмотреть файл

@ -395,6 +395,26 @@ export class Helper {
return false;
}
public GetUniqueName(name: string, usedNames: Array<string>) : string {
let uniqueName = name;
let i = 0;
while (usedNames.includes(uniqueName)) {
uniqueName = `${name}${++i}`;
}
return uniqueName;
}
public GetValidCsharpName(name : string) : string {
let validChars = name.replace(/[^a-zA-Z0-9_]/g, '');
// prepend '_' if the name starts with a digit
if (!/^[a-zA-Z_]/.test(validChars)) {
validChars = '_' + validChars;
}
return validChars;
}
public IsEnum(schema: Schema): boolean {
if (schema.type === SchemaType.SealedChoice && (<SealedChoiceSchema>schema).choiceType.type === SchemaType.String && schema.extensions && !schema.extensions['x-ms-model-as-string']) {
return true;