internal static ResourceMatchType GetMatchType()

in src/AutoRest.CSharp/Mgmt/Models/MgmtRestOperation.cs [391:423]


        internal static ResourceMatchType GetMatchType(RequestMethod httpMethod, RequestPath resourcePath, RequestPath requestPath, bool isList)
        {
            //check exact match
            if (resourcePath == requestPath)
                return ResourceMatchType.Exact;

            var requestLastSegment = requestPath.Last();
            //check for a list by a parent or an ancestor
            if (TryGetListMatch(httpMethod, resourcePath, requestPath, isList, out var listMatch))
                return listMatch;

            //check for single value methods after the GET path which are typically POST methods
            if (resourcePath.Count == requestPath.Count - 1 && requestLastSegment.IsConstant && AreEqualBackToProvider(resourcePath, requestPath, 0, 1))
                return isList ? ResourceMatchType.ChildList : ResourceMatchType.Context;

            if (httpMethod == RequestMethod.Get)
                return ResourceMatchType.None;

            var resourceLastSegement = resourcePath.Last();
            //sometimes for singletons the POST methods show up at the same level
            if (resourcePath.Count == requestPath.Count && requestLastSegment.IsConstant && resourceLastSegement.IsConstant && AreEqualBackToProvider(resourcePath, requestPath, 1, 1))
                return ResourceMatchType.Context;

            //catch check name availability where the provider ending matches
            //this one catches a lot so we are narrowing it down to containing "name" dont know all the checknameavailability name types
            if (requestLastSegment.IsConstant &&
                RequestPath.Subscription.IsAncestorOf(requestPath) &&
                requestLastSegment.ToString().Contains("name", StringComparison.OrdinalIgnoreCase) &&
                AreEqualBackToProvider(resourcePath, requestPath, 2, 1))
                return ResourceMatchType.CheckName;

            return ResourceMatchType.None;
        }