public static string GetDefinitionName(this UriOrFragment reference) { Match match = s_definitionRegex.Match(reference.Fragment); if (!match.Success) { throw Error.CreateException( Resources.ErrorOnlyDefinitionFragmentsSupported, reference.Fragment); } return(match.Groups["definitionName"].Captures[0].Value); }
/// <summary> /// Initializes a new instance of the <see cref="JsonSchema"/> class from the /// specified instance. /// </summary> /// <param name="other"> /// The instance used to initialize the new instance. /// </param> public JsonSchema(JsonSchema other) { if (other.Id != null) { Id = new UriOrFragment(other.Id); } if (other.SchemaVersion != null) { SchemaVersion = new Uri(other.SchemaVersion.OriginalString); } Title = other.Title; Description = other.Description; if (other.Type != null) { Type = new List <SchemaType>(other.Type); } if (other.Enum != null) { // A shallow copy is fine for now since Enum will be checked to ensure that it // contain only primitive types. // But it won't do if we want to pass the JSON Schema validation suite. Enum = new List <object>(other.Enum); } if (other.Items != null) { Items = new Items(other.Items); } if (other.Properties != null) { Properties = new Dictionary <string, JsonSchema>(); foreach (string key in other.Properties.Keys) { Properties.Add(key, new JsonSchema(other.Properties[key])); } } if (other.Required != null) { Required = new List <string>(other.Required); } if (other.Definitions != null) { Definitions = new Dictionary <string, JsonSchema>(); foreach (string key in other.Definitions.Keys) { Definitions.Add(key, new JsonSchema(other.Definitions[key])); } } if (other.AdditionalItems != null) { AdditionalItems = new AdditionalItems(other.AdditionalItems); } if (other.AdditionalProperties != null) { AdditionalProperties = new AdditionalProperties(other.AdditionalProperties); } if (other.Dependencies != null) { Dependencies = new Dictionary <string, Dependency>(other.Dependencies); } if (other.PatternProperties != null) { PatternProperties = new Dictionary <string, JsonSchema>(other.PatternProperties); } Default = other.Default; Pattern = other.Pattern; MaxLength = other.MaxLength; MinLength = other.MinLength; Format = other.Format; MultipleOf = other.MultipleOf; Maximum = other.Maximum; ExclusiveMaximum = other.ExclusiveMaximum; MinItems = other.MinItems; MaxItems = other.MaxItems; UniqueItems = other.UniqueItems; if (other.Reference != null) { Reference = new UriOrFragment(other.Reference); } if (other.AllOf != null) { AllOf = new List <JsonSchema>(other.AllOf); } if (other.AnyOf != null) { AnyOf = new List <JsonSchema>(other.AnyOf); } if (other.OneOf != null) { OneOf = new List <JsonSchema>(other.OneOf); } if (other.Not != null) { Not = new JsonSchema(other.Not); } }