Fixed a few bugs related to readonly parameter and const enum (#1240)

This commit is contained in:
Xiaogang 2023-09-15 20:41:13 +08:00 коммит произвёл GitHub
Родитель bb0308efc9
Коммит fd28025723
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 17 добавлений и 7 удалений

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

@ -88,6 +88,8 @@ function tweakSchema(model: SdkModel) {
for (const obj of values(model.schemas.objects)) {
const optionalParameters = Array<string>();
const requiredParameters = Array<string>();
const optionalParametersWithoutReadOnly = Array<string>();
const requiredParametersWithoutReadOnly = Array<string>();
for (const property of values(obj.properties)) {
property.language.csharp = <any>{
name: property.language.default.name.substring(0, 1).toUpperCase() + property.language.default.name.substring(1),
@ -110,6 +112,9 @@ function tweakSchema(model: SdkModel) {
type = (valueType(virtualProperty.property.schema.type) || (virtualProperty.property.schema.type === SchemaType.SealedChoice && ((<SealedChoiceSchema>virtualProperty.property.schema).choiceType.type !== SchemaType.String || (virtualProperty.property.schema.extensions && !virtualProperty.property.schema.extensions['x-ms-model-as-string'])))) && !virtualProperty.required && virtualProperty.property.nullable != false ? `${type}?` : type;
const CamelName = camelCase(virtualProperty.name);
virtualProperty.required ? requiredParameters.push(`${type} ${CamelName}`) : optionalParameters.push(`${type} ${CamelName} = default(${type})`);
if (!virtualProperty.readOnly) {
virtualProperty.required ? requiredParametersWithoutReadOnly.push(`${type} ${CamelName}`) : optionalParametersWithoutReadOnly.push(`${type} ${CamelName} = default(${type})`);
}
}
if (obj.parents && (obj.parents.immediate.length === 1 && !(obj.extensions && obj.extensions['x-ms-azure-resource']))) {
// If there is only one direct parent parameter and extension x-ms-azure-resource is not set, will implement it as base class
@ -130,6 +135,7 @@ function tweakSchema(model: SdkModel) {
}
}
obj.language.default.constructorParametersDeclaration = [...requiredParameters, ...optionalParameters].join(', ');
obj.language.default.constructorParametersDeclarationWithoutReadOnly = [...requiredParametersWithoutReadOnly, ...optionalParametersWithoutReadOnly].join(', ');
}
}
@ -185,8 +191,8 @@ function addNormalMethodParameterDeclaration(operation: Operation, state: State)
&& !(p.required && p.schema.type === SchemaType.Choice && (<ChoiceSchema>p.schema).choices.length === 1)
&& !(p.required && p.schema.type === SchemaType.SealedChoice && (<SealedChoiceSchema>p.schema).choices.length === 1)).forEach(function (parameter) {
if (parameter.extensions && parameter.extensions['x-ms-client-flatten']) {
const constructorParametersDeclaration = <string>parameter.schema.language.default.constructorParametersDeclaration;
splitStringWithExclusion(constructorParametersDeclaration, ',').forEach(function (p) {
const constructorParametersDeclarationWithoutReadOnly = <string>parameter.schema.language.default.constructorParametersDeclarationWithoutReadOnly;
splitStringWithExclusion(constructorParametersDeclarationWithoutReadOnly, ',').forEach(function (p) {
requiredDeclarations.push(p);
requiredArgs.push(splitStringWithExclusion(p, ' ')[1]);
});

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

@ -5,7 +5,7 @@
/// </summary>
<% };-%>
<%# ToDo: add remark if both description and summary is provided, question here is in m4, there is no summary provided-%>
<% 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) {-%>
<%# ToDo: should use camel name instead of pascal name here -%>
/// <param name='<%-parameter.language.default.name%>'>
/// <%=parameter.language.default.description%>
@ -14,7 +14,7 @@
<% if(!method.language.default.pageable?.nextPageOperation) {-%>
<% (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>

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

@ -5,7 +5,7 @@
/// </summary>
<% };-%>
<%# ToDo: add remark if both description and summary is provided, question here is in m4, there is no summary provided-%>
<% 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) {-%>
<%# ToDo: should use camel name instead of pascal name here -%>
/// <param name='<%-parameter.language.default.name%>'>
/// <%=parameter.language.default.description%>
@ -14,7 +14,7 @@
<% if(!method.language.default.pageable?.nextPageOperation) {-%>
<% (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>

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

@ -57,7 +57,7 @@ if (method.extensions && method.extensions['x-ms-request-id']) {
<% (method.requests[0].parameters || []).filter(p=>p.protocol.http.in == 'body').forEach(function(parameter){-%>
<%if(parameter.extensions && parameter.extensions['x-ms-client-flatten']) {-%>
<%-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)-%>
<% var vps = project.helper.GetAllPublicVirtualProperties(parameter.schema.language.default.virtualProperties).filter(vp => !project.helper.IsConstantEnumProperty(vp) && !vp.readOnly)-%>
if(<%-vps.map(vp=>`${vp.property.language.default.name} != null`).join('||')%>)
{
<%vps.forEach(function(vp) {-%>
@ -157,7 +157,11 @@ var prefix = parameter.implementation == 'Client' ? `this${clientPrefix}.` : ''-
{
_httpRequest.Headers.Remove("<%-parameter.language.default.serializedName%>");
}
<% if (parameter.schema.type == 'uuid') { -%>
_httpRequest.Headers.TryAddWithoutValidation("<%-parameter.language.default.serializedName%>", Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(<%-prefix%><%-parameter.language.default.name%>, this.Client.SerializationSettings).Trim('"'));
<% } else {-%>
_httpRequest.Headers.TryAddWithoutValidation("<%-parameter.language.default.serializedName%>", <%-prefix%><%-parameter.language.default.name%>);
<% } -%>
}
<% });-%>