/// <summary>
        /// Verify that mutability values are valid in context of Read Only property.
        /// </summary>
        /// <param name="mutable">mutability extension object.</param>
        /// <param name="context">Rule context.</param>
        /// <param name="formatParameters">array of invalid parameters to be returned.</param>
        /// <returns><c>true</c> if all values for x-ms-mutability are valid in context of Read Only property, otherwise <c>false</c>.</returns>
        private bool ValidateMutabilityValuesWithReadOnlyProperty(object mutable, RuleContext context, out object[] formatParameters)
        {
            string[] values        = ((Newtonsoft.Json.Linq.JArray)mutable).ToObject <string[]>();
            string[] invalidValues = null;

            var    resolver = new SchemaResolver(context?.GetServiceDefinition());
            Schema schema   = resolver.Unwrap(context?.GetFirstAncestor <Schema>());

            if (schema.ReadOnly)
            {
                // Property with "readOnly": true must only have "read" value in x-ms-mutability extension.
                invalidValues = values.Except(ValidValuesForReadOnlyProperty, StringComparer.OrdinalIgnoreCase).ToArray();
            }
            else
            {
                // Property with "readOnly": false must have more than "read" value in x-ms-mutability extension.
                if (values.Length == 1)
                {
                    invalidValues = values.Contains(ValidValuesForReadOnlyProperty[0], StringComparer.OrdinalIgnoreCase) ?
                                    ValidValuesForReadOnlyProperty : new string[0];
                }
            }

            bool isValid = invalidValues == null || invalidValues.Length == 0;

            formatParameters = isValid ? new object[0] : new string[] { String.Join(",", invalidValues) };

            return(isValid);
        }
Beispiel #2
0
        protected static Schema Get200ResponseSchema(RuleContext context)
        {
            OperationResponse response = context?.GetFirstAncestor <Operation>()?.Responses?.GetValueOrNull("200");

            if (response == null)
            {
                return(null);
            }
            var resolver = new SchemaResolver(context?.GetServiceDefinition());

            return(resolver.Unwrap(response.Schema));
        }