in src/AutoRest.CSharp/Mgmt/Decorator/Transformer/DuplicateSchemaResolver.cs [47:110]
private static void ReplaceSchemas(HashSet<Schema> schemas, Schema replaceSchema, CodeModel codeModel)
{
// remove the things that should be replaced by the replaceSchmea
foreach (var schema in schemas)
{
if (schema == replaceSchema)
continue;
switch (schema)
{
case ChoiceSchema choiceSchema:
codeModel.Schemas.Choices.Remove(choiceSchema);
break;
case SealedChoiceSchema sealedChoiceSchema:
codeModel.Schemas.SealedChoices.Remove(sealedChoiceSchema);
break;
default:
throw new InvalidOperationException("This will never happen");
}
}
// we have to iterate everything on the code model
foreach (var schema in codeModel.AllSchemas)
{
// only change things in ObjectSchema because we only change ChoiceSchema and SealedChoiceSchema
// they could only appear as properties of ObjectSchemas
if (schema is ObjectSchema objectSchema)
{
foreach (var property in objectSchema.Properties)
{
if (schemas.Contains(property.Schema))
property.Schema = replaceSchema;
}
}
}
// we also have to iterate all operations
foreach (var operationGroup in codeModel.OperationGroups)
{
foreach (var operation in operationGroup.Operations)
{
foreach (var operationResponse in operation.Responses)
{
ReplaceResponseSchema(schemas, operationResponse as SchemaResponse, replaceSchema);
}
foreach (var operationResponse in operation.Exceptions)
{
ReplaceResponseSchema(schemas, operationResponse as SchemaResponse, replaceSchema);
}
foreach (var parameter in operation.Parameters)
{
ReplaceRequestParamSchema(schemas, parameter, replaceSchema);
}
foreach (var request in operation.Requests)
{
foreach (var parameter in request.Parameters)
{
ReplaceRequestParamSchema(schemas, parameter, replaceSchema);
}
}
}
}
}