Should not flatten poloymophic class and should not check null for required value type (#1242)
This commit is contained in:
Родитель
fd28025723
Коммит
6efb04ba3a
|
@ -479,7 +479,7 @@ async function handlePayloadFlatteningThreshold(state: State): Promise<void> {
|
|||
const bodyParameterSchema = bodyParameter.schema;
|
||||
if (bodyParameterSchema.type === SchemaType.Object) {
|
||||
const virtualProperties = getAllPublicVirtualProperties(bodyParameterSchema.language.default.virtualProperties).filter(vp => !vp.readOnly && !(vp.required && (vp.property.schema.type === SchemaType.Constant || helper.IsConstantEnumProperty(vp))));
|
||||
if (virtualProperties.length <= payloadFlatteningThreshold) {
|
||||
if (virtualProperties.length <= payloadFlatteningThreshold && !(bodyParameter.schema.type === SchemaType.Object && ((<ObjectSchema>bodyParameter.schema).discriminator || (<ObjectSchema>bodyParameter.schema).discriminatorValue))) {
|
||||
bodyParameter.extensions = bodyParameter.extensions || {};
|
||||
bodyParameter.extensions['x-ms-client-flatten'] = true;
|
||||
}
|
||||
|
|
|
@ -57,14 +57,22 @@ 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).filter(vp => !project.helper.IsConstantEnumProperty(vp) && !vp.readOnly)-%>
|
||||
if(<%-vps.map(vp=>`${vp.property.language.default.name} != null`).join('||')%>)
|
||||
<% 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 vpsWithoutNullCheck = vps.filter(virtualProperty => !project.helper.IsNullCheckRequiredForVirtualProperty(virtualProperty));
|
||||
-%>
|
||||
<% if(vpsWithNullCheck.length > 0) {-%>
|
||||
if(<%-vpsWithNullCheck.map(vp=>`${vp.property.language.default.name} != null`).join('||')%>)
|
||||
{
|
||||
<%vps.forEach(function(vp) {-%>
|
||||
<%vpsWithNullCheck.forEach(function(vp) {-%>
|
||||
<%-parameter.language.default.name%>.<%-vp.property.language.csharp.name%> = <%-vp.property.language.default.name%>;
|
||||
<%});-%>
|
||||
}
|
||||
<%}-%>
|
||||
<%vpsWithoutNullCheck.forEach(function(vp) {-%>
|
||||
<%-parameter.language.default.name%>.<%-vp.property.language.csharp.name%> = <%-vp.property.language.default.name%>;
|
||||
<%});-%>
|
||||
<%}-%>
|
||||
<% });-%>
|
||||
<%}-%>
|
||||
// Tracing
|
||||
|
|
|
@ -304,6 +304,10 @@ export class Helper {
|
|||
return ref + '.SerializationSettings';
|
||||
}
|
||||
|
||||
public IsNullCheckRequiredForVirtualProperty(virtualProperty: VirtualProperty): boolean {
|
||||
return !((this.IsValueType(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));
|
||||
}
|
||||
|
||||
public CamelCase(str: string): string {
|
||||
// str = str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
||||
// return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
||||
|
|
Загрузка…
Ссылка в новой задаче