private JsonSchemaType?ProcessType(JToken token) { switch (token.Type) { case JTokenType.Array: // ensure type is in blank state before ORing values JsonSchemaType?type = JsonSchemaType.None; foreach (JToken typeToken in token) { if (typeToken.Type != JTokenType.String) { throw JsonException.Create(typeToken, typeToken.Path, "Expected JSON schema type string token, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } type = type | MapType((string)typeToken); } return(type); case JTokenType.String: return(MapType((string)token)); default: throw JsonException.Create(token, token.Path, "Expected array or JSON schema type string token, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } }
private void ProcessItems(JToken token) { this.CurrentSchema.Items = new List <JsonSchema>(); switch (token.Type) { case JTokenType.Object: this.CurrentSchema.Items.Add(this.BuildSchema(token)); this.CurrentSchema.PositionalItemsValidation = false; return; case JTokenType.Array: this.CurrentSchema.PositionalItemsValidation = true; using (IEnumerator <JToken> enumerator = ((IEnumerable <JToken>)token).GetEnumerator()) { while (enumerator.MoveNext()) { JToken current = enumerator.Current; this.CurrentSchema.Items.Add(this.BuildSchema(current)); } return; } break; } throw JsonException.Create(token, token.Path, "Expected array or JSON schema object, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); }
private void EnsureToken(JsonReader reader, string name, List <JsonToken> tokenTypes) { EnsureRead(reader, name); if (!tokenTypes.Contains(reader.TokenType)) { throw JsonException.Create(reader as IJsonLineInfo, reader.Path, "Unexpected token encountered when reading value for '{0}'. Expected {1}, got {2}.".FormatWith(CultureInfo.InvariantCulture, name, string.Join(", ", tokenTypes), reader.TokenType)); } }
private IDictionary <string, JsonSchema> ProcessDependencies(JToken token) { IDictionary <string, JsonSchema> dependencies = new Dictionary <string, JsonSchema>(); foreach (JProperty dependencyToken in token) { if (dependencies.ContainsKey(dependencyToken.Name)) { throw new JsonException("Dependency {0} has already been defined in schema.".FormatWith(CultureInfo.InvariantCulture, dependencyToken.Name)); } switch (dependencyToken.Value.Type) { case JTokenType.String: JsonSchema singleProperty = new JsonSchema { Type = JsonSchemaType.Object }; singleProperty.Required = new List <string> { (string)dependencyToken.Value }; singleProperty.Properties = new Dictionary <string, JsonSchema>(); singleProperty.Properties.Add((string)dependencyToken.Value, new JsonSchema() { Type = JsonSchemaType.Any }); dependencies.Add(dependencyToken.Name, singleProperty); break; case JTokenType.Array: JsonSchema multipleProperty = new JsonSchema { Type = JsonSchemaType.Object }; multipleProperty.Required = new List <string>(); multipleProperty.Properties = new Dictionary <string, JsonSchema>(); foreach (JToken schemaToken in dependencyToken.Value) { multipleProperty.Required.Add((string)schemaToken); multipleProperty.Properties.Add((string)schemaToken, new JsonSchema() { Type = JsonSchemaType.Any }); } dependencies.Add(dependencyToken.Name, multipleProperty); break; case JTokenType.Object: dependencies.Add(dependencyToken.Name, BuildSchema(dependencyToken.Value)); break; default: throw JsonException.Create(token, token.Path, "Expected string, array or JSON schema object, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } } return(dependencies); }
private void ValidateRequiredArrayToken(JToken token) { if (token.Count() == 0 || token.Any(x => x.Type != JTokenType.String) || token.GroupBy(x => x).All(x => x.Count() != 1) || token.Any(x => !CurrentSchema.Properties.ContainsKey((string)x))) { throw JsonException.Create(token, token.Path, "Expected array of valid property name strings for Required token, got {0}.".FormatWith(CultureInfo.InvariantCulture, token)); } }
private JsonSchemaLink ProcessLink(JObject schemaObject) { JsonSchemaLink currentLink = new JsonSchemaLink(); foreach (KeyValuePair <string, JToken> property in schemaObject) { switch (property.Key) { case JsonSchemaConstants.HrefPropertyName: currentLink.Href = (string)property.Value; break; case JsonSchemaConstants.RelationPropertyName: currentLink.Relation = (string)property.Value; break; case JsonSchemaConstants.TitlePropertyName: currentLink.Title = (string)property.Value; break; case JsonSchemaConstants.TargetSchemaPropertyName: currentLink.TargetSchema = BuildSchema(property.Value); break; case JsonSchemaConstants.MediaTypePropertyName: currentLink.MediaType = (string)property.Value; break; case JsonSchemaConstants.MethodPropertyName: currentLink.Method = (string)property.Value; break; case JsonSchemaConstants.EncodingTypePropertyName: currentLink.EncodingType = (string)property.Value; break; case JsonSchemaConstants.SchemaPropertyName: currentLink.Schema = BuildSchema(property.Value); break; } } if (string.IsNullOrEmpty(currentLink.Href)) { throw JsonException.Create(schemaObject, schemaObject.Path, "Missing required link property: href"); } if (string.IsNullOrEmpty(currentLink.Relation)) { throw JsonException.Create(schemaObject, schemaObject.Path, "Missing required link property: rel"); } return(currentLink); }
// Token: 0x0600116F RID: 4463 RVA: 0x00060FC4 File Offset: 0x0005F1C4 private void ProcessEnum(JToken token) { if (token.Type != JTokenType.Array) { throw JsonException.Create(token, token.Path, "Expected Array token while parsing enum values, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } this.CurrentSchema.Enum = new List <JToken>(); foreach (JToken jtoken in ((IEnumerable <JToken>)token)) { this.CurrentSchema.Enum.Add(jtoken.DeepClone()); } }
// Token: 0x06000AE4 RID: 2788 RVA: 0x00039CCC File Offset: 0x00037ECC private void method_9(JToken jtoken_0) { if (jtoken_0.Type != JTokenType.Array) { throw JsonException.Create(jtoken_0, jtoken_0.Path, "Expected Array token while parsing enum values, got {0}.".smethod_0(CultureInfo.InvariantCulture, jtoken_0.Type)); } this.method_2().Enum = new List <JToken>(); foreach (JToken jtoken in ((IEnumerable <JToken>)jtoken_0)) { this.method_2().Enum.Add(jtoken.DeepClone()); } }
private JsonSchema BuildSchema(JToken token) { if (!(token is JObject schemaObject)) { throw JsonException.Create( token, token.Path, "Expected object while parsing schema object, got {0}.".FormatWith( CultureInfo.InvariantCulture, token.Type ) ); } if ( schemaObject.TryGetValue( JsonTypeReflector.RefPropertyName, out JToken referenceToken ) ) { JsonSchema deferredSchema = new JsonSchema(); deferredSchema.DeferredReference = (string)referenceToken; return(deferredSchema); } string location = token.Path .Replace(".", "/") .Replace("[", "/") .Replace("]", string.Empty); if (!StringUtils.IsNullOrEmpty(location)) { location = "/" + location; } location = "#" + location; if (_documentSchemas.TryGetValue(location, out JsonSchema existingSchema)) { return(existingSchema); } Push(new JsonSchema { Location = location }); ProcessSchemaProperties(schemaObject); return(Pop()); }
private void ProcessLinks(JToken token) { if (token.Type != JTokenType.Array) { throw JsonException.Create(token, token.Path, "Expected Array token while parsing links values, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } CurrentSchema.Links = new List <JsonSchemaLink>(); foreach (JObject linkValue in token) { CurrentSchema.Links.Add(ProcessLink(linkValue)); } }
private void ProcessCodeBlocks(JToken token) { if (token.Type != JTokenType.Array) { throw JsonException.Create(token, token.Path, "Expected Array token while parsing x-code-blocks values, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } CurrentSchema.CodeBlocks = new List <JToken>(); foreach (JToken codeBlock in token) { CurrentSchema.CodeBlocks.Add(codeBlock.DeepClone()); } }
private IDictionary <string, JsonSchema> ProcessProperties(JToken token) { IDictionary <string, JsonSchema> strs = new Dictionary <string, JsonSchema>(); if (token.Type != JTokenType.Object) { throw JsonException.Create(token, token.Path, "Expected Object token while parsing schema properties, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } foreach (JProperty jProperty in (IEnumerable <JToken>)token) { if (strs.ContainsKey(jProperty.Name)) { throw new JsonException("Property {0} has already been defined in schema.".FormatWith(CultureInfo.InvariantCulture, jProperty.Name)); } strs.Add(jProperty.Name, this.BuildSchema(jProperty.Value)); } return(strs); }
// Token: 0x06000AE7 RID: 2791 RVA: 0x00039D64 File Offset: 0x00037F64 private IDictionary <string, JsonSchema> method_12(JToken jtoken_0) { IDictionary <string, JsonSchema> dictionary = new Dictionary <string, JsonSchema>(); if (jtoken_0.Type != JTokenType.Object) { throw JsonException.Create(jtoken_0, jtoken_0.Path, "Expected Object token while parsing schema properties, got {0}.".smethod_0(CultureInfo.InvariantCulture, jtoken_0.Type)); } foreach (JToken jtoken in ((IEnumerable <JToken>)jtoken_0)) { JProperty jproperty = (JProperty)jtoken; if (dictionary.ContainsKey(jproperty.Name)) { throw new JsonException("Property {0} has already been defined in schema.".smethod_0(CultureInfo.InvariantCulture, jproperty.Name)); } dictionary.Add(jproperty.Name, this.method_6(jproperty.Value)); } return(dictionary); }
private IDictionary <string, JsonSchema> ProcessProperties(JToken token) { var properties = new Dictionary <string, JsonSchema>(); if (token.Type != JTokenType.Object) { throw JsonException.Create(token, token.Path, "Expected Object token while parsing schema properties, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } foreach (JProperty propertyToken in token) { if (properties.ContainsKey(propertyToken.Name)) { throw new JsonException("Property {0} has already been defined in schema.".FormatWith(CultureInfo.InvariantCulture, propertyToken.Name)); } properties.Add(propertyToken.Name, BuildSchema(propertyToken.Value)); } return(properties); }
private void ProcessRequired(JToken token) { // Most common breaking change for draft v3 -> draft v4 if (token.Type == JTokenType.Boolean) { throw JsonException.Create(token, token.Path, "Expected Array token while parsing required properties, got Boolean. Possible draft v3 schema."); } if (token.Type != JTokenType.Array) { throw JsonException.Create(token, token.Path, "Expected Array token while parsing required properties, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } CurrentSchema.Required = new List <string>(); foreach (JToken propValue in token) { CurrentSchema.Required.Add((string)propValue); } }
private void ProcessRequired(JToken token) { if (token.Type == JTokenType.Boolean) { CurrentSchema.Required = (bool)token; } else if (token.Type == JTokenType.Array) { ValidateRequiredArrayToken(token); foreach (var typeToken in token) { CurrentSchema.Properties[(string)typeToken].Required = true; } } else { throw JsonException.Create(token, token.Path, "Expected Boolean or array while processing Required token, got {0}".FormatWith(CultureInfo.InvariantCulture, token.Type)); } }
private IList <JsonSchema> ProcessSchemaGroup(JToken token) { if (token.Type != JTokenType.Array) { throw JsonException.Create(token, token.Path, "Expected Array token while parsing schema group, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } IList <JsonSchema> schemas = new List <JsonSchema>(); foreach (JToken schemaObject in token) { schemas.Add(BuildSchema(schemaObject)); } if (schemas.Count > 0) { return(schemas); } return(null); }
private void ProcessItems(JToken token) { CurrentSchema.Items = new List<JsonSchema>(); switch (token.Type) { case JTokenType.Object: CurrentSchema.Items.Add(BuildSchema(token)); CurrentSchema.PositionalItemsValidation = false; break; case JTokenType.Array: CurrentSchema.PositionalItemsValidation = true; foreach (JToken schemaToken in token) { CurrentSchema.Items.Add(BuildSchema(schemaToken)); } break; default: throw JsonException.Create(token, token.Path, "Expected array or JSON schema object, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } }
private void ProcessItems(JToken token) { this.CurrentSchema.Items = new List <JsonSchema>(); JTokenType type = token.Type; if (type == JTokenType.Object) { this.CurrentSchema.Items.Add(this.BuildSchema(token)); this.CurrentSchema.PositionalItemsValidation = false; return; } if (type != JTokenType.Array) { throw JsonException.Create(token, token.Path, "Expected array or JSON schema object, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } this.CurrentSchema.PositionalItemsValidation = true; foreach (JToken jTokens in (IEnumerable <JToken>)token) { this.CurrentSchema.Items.Add(this.BuildSchema(jTokens)); } }
private void ReadItems(JsonReader reader, JSchema schema) { EnsureRead(reader, Constants.PropertyNames.Items); EnsureList(ref schema._items); switch (reader.TokenType) { case JsonToken.StartObject: LoadAndSetSchema(reader, s => SetAtIndex(schema._items, 0, s)); schema.ItemsPositionValidation = false; break; case JsonToken.StartArray: PopulateSchemaArray(reader, Constants.PropertyNames.Items, schema._items); schema.ItemsPositionValidation = true; break; default: throw JsonException.Create(reader as IJsonLineInfo, reader.Path, "Expected array or JSON schema object for '{0}', got {1}.".FormatWith(CultureInfo.InvariantCulture, Constants.PropertyNames.Items, reader.TokenType)); } }
// Token: 0x06000AE8 RID: 2792 RVA: 0x00039E28 File Offset: 0x00038028 private void method_13(JToken jtoken_0) { this.method_2().Items = new List <JsonSchema>(); JTokenType type = jtoken_0.Type; if (type == JTokenType.Object) { this.method_2().Items.Add(this.method_6(jtoken_0)); this.method_2().PositionalItemsValidation = false; return; } if (type != JTokenType.Array) { throw JsonException.Create(jtoken_0, jtoken_0.Path, "Expected array or JSON schema object, got {0}.".smethod_0(CultureInfo.InvariantCulture, jtoken_0.Type)); } this.method_2().PositionalItemsValidation = true; foreach (JToken jtoken_ in ((IEnumerable <JToken>)jtoken_0)) { this.method_2().Items.Add(this.method_6(jtoken_)); } }
private JsonSchema BuildSchema(JToken token) { JObject schemaObject = token as JObject; if (schemaObject == null) { throw JsonException.Create((IJsonLineInfo)token, token.Path, "Expected object while parsing schema object, got {0}.".FormatWith( (IFormatProvider)CultureInfo.InvariantCulture, (object)token.Type)); } JToken jtoken; if (schemaObject.TryGetValue("$ref", out jtoken)) { return new JsonSchema() { DeferredReference = (string)jtoken } } ; string str = token.Path.Replace(".", "/").Replace("[", "/").Replace("]", string.Empty); if (!string.IsNullOrEmpty(str)) { str = "/" + str; } string key = "#" + str; JsonSchema jsonSchema; if (this._documentSchemas.TryGetValue(key, out jsonSchema)) { return(jsonSchema); } this.Push(new JsonSchema() { Location = key }); this.ProcessSchemaProperties(schemaObject); return(this.Pop()); }
private IDictionary <string, JsonSchema> ProcessProperties(JToken token) { IDictionary <string, JsonSchema> dictionary = new Dictionary <string, JsonSchema>(); if (token.Type != JTokenType.Object) { throw JsonException.Create(token, token.Path, "Expected Object token while parsing schema properties, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } using (IEnumerator <JToken> enumerator = ((IEnumerable <JToken>)token).GetEnumerator()) { while (enumerator.MoveNext()) { JProperty jProperty = (JProperty)enumerator.Current; if (dictionary.ContainsKey(jProperty.Name)) { throw new JsonException("Property {0} has already been defined in schema.".FormatWith(CultureInfo.InvariantCulture, jProperty.Name)); } dictionary.Add(jProperty.Name, this.BuildSchema(jProperty.Value)); } } return(dictionary); }
// Token: 0x06001174 RID: 4468 RVA: 0x000612A4 File Offset: 0x0005F4A4 private JsonSchemaType?ProcessType(JToken token) { JTokenType type = token.Type; if (type == JTokenType.Array) { JsonSchemaType?jsonSchemaType = new JsonSchemaType?(JsonSchemaType.None); foreach (JToken jtoken in ((IEnumerable <JToken>)token)) { if (jtoken.Type != JTokenType.String) { throw JsonException.Create(jtoken, jtoken.Path, "Expected JSON schema type string token, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } jsonSchemaType |= JsonSchemaBuilder.MapType((string)jtoken); } return(jsonSchemaType); } if (type != JTokenType.String) { throw JsonException.Create(token, token.Path, "Expected array or JSON schema type string token, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } return(new JsonSchemaType?(JsonSchemaBuilder.MapType((string)token))); }
// Token: 0x06000AE9 RID: 2793 RVA: 0x00039EF8 File Offset: 0x000380F8 private JsonSchemaType?method_14(JToken jtoken_0) { JTokenType type = jtoken_0.Type; if (type == JTokenType.Array) { JsonSchemaType?jsonSchemaType = new JsonSchemaType?(JsonSchemaType.None); foreach (JToken jtoken in ((IEnumerable <JToken>)jtoken_0)) { if (jtoken.Type != JTokenType.String) { throw JsonException.Create(jtoken, jtoken.Path, "Expected JSON schema type string token, got {0}.".smethod_0(CultureInfo.InvariantCulture, jtoken_0.Type)); } jsonSchemaType |= Class130.smethod_0((string)jtoken); } return(jsonSchemaType); } if (type != JTokenType.String) { throw JsonException.Create(jtoken_0, jtoken_0.Path, "Expected array or JSON schema type string token, got {0}.".smethod_0(CultureInfo.InvariantCulture, jtoken_0.Type)); } return(new JsonSchemaType?(Class130.smethod_0((string)jtoken_0))); }
private void ProcessMedia(JToken token) { if (token.Type != JTokenType.Object) { throw JsonException.Create(token, token.Path, "Expected Object token while parsing media values, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } CurrentSchema.Media = new JsonSchemaMedia(); foreach (KeyValuePair <string, JToken> property in (JObject)token) { switch (property.Key) { case JsonSchemaConstants.TypePropertyName: CurrentSchema.Media.Type = (string)property.Value; break; case JsonSchemaConstants.BinaryEncodingPropertyName: CurrentSchema.Media.BinaryEncoding = (string)property.Value; break; } } }
// Token: 0x0600116C RID: 4460 RVA: 0x0006062C File Offset: 0x0005E82C private JsonSchema BuildSchema(JToken token) { JObject jobject = token as JObject; if (jobject == null) { throw JsonException.Create(token, token.Path, "Expected object while parsing schema object, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } JToken value; if (jobject.TryGetValue("$ref", out value)) { return(new JsonSchema { DeferredReference = (string)value }); } string text = token.Path.Replace(".", "/").Replace("[", "/").Replace("]", string.Empty); if (!StringUtils.IsNullOrEmpty(text)) { text = "/" + text; } text = "#" + text; JsonSchema result; if (this._documentSchemas.TryGetValue(text, out result)) { return(result); } this.Push(new JsonSchema { Location = text }); this.ProcessSchemaProperties(jobject); return(this.Pop()); }
private JsonSchema BuildSchema(JToken token) { JToken jTokens; JsonSchema jsonSchema; JObject jObjects = token as JObject; JObject jObjects1 = jObjects; if (jObjects == null) { throw JsonException.Create(token, token.Path, "Expected object while parsing schema object, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } if (jObjects1.TryGetValue("$ref", out jTokens)) { return(new JsonSchema() { DeferredReference = (string)jTokens }); } string str = token.Path.Replace(".", "/").Replace("[", "/").Replace("]", string.Empty); if (!string.IsNullOrEmpty(str)) { str = string.Concat("/", str); } str = string.Concat("#", str); if (this._documentSchemas.TryGetValue(str, out jsonSchema)) { return(jsonSchema); } this.Push(new JsonSchema() { Location = str }); this.ProcessSchemaProperties(jObjects1); return(this.Pop()); }
// Token: 0x06000AE1 RID: 2785 RVA: 0x00039464 File Offset: 0x00037664 private JsonSchema method_6(JToken jtoken_0) { JObject jobject; if ((jobject = (jtoken_0 as JObject)) == null) { throw JsonException.Create(jtoken_0, jtoken_0.Path, "Expected object while parsing schema object, got {0}.".smethod_0(CultureInfo.InvariantCulture, jtoken_0.Type)); } JToken value; if (jobject.TryGetValue("$ref", out value)) { JsonSchema jsonSchema = new JsonSchema(); jsonSchema.method_2((string)value); return(jsonSchema); } string text = jtoken_0.Path.Replace(".", "/").Replace("[", "/").Replace("]", string.Empty); if (!string.IsNullOrEmpty(text)) { text = "/" + text; } text = "#" + text; JsonSchema result; if (this.idictionary_0.TryGetValue(text, out result)) { return(result); } this.method_0(new JsonSchema { Location = text }); this.method_7(jobject); return(this.method_1()); }
private JsonSchema BuildSchema(JToken token) { JObject schemaObject = token as JObject; if (schemaObject == null) { throw JsonException.Create(token, token.Path, "Expected object while parsing schema object, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); } // Check for change of scope before processing JToken idToken; bool hasPushedScope = false; if (schemaObject.TryGetValue(JsonSchemaConstants.IdPropertyName, out idToken)) { string subScope = (string)idToken; Uri scopeUri; hasPushedScope = true; if (string.IsNullOrEmpty(_currentResolutionScope)) { PushScope(subScope); } else { scopeUri = new Uri(_currentResolutionScope, UriKind.RelativeOrAbsolute); Uri subScopeUri = new Uri(subScope, UriKind.RelativeOrAbsolute); if (subScopeUri.IsAbsoluteUri) { PushScope(subScopeUri.ToString()); } else { Uri combinedUri = new Uri(scopeUri, subScope); PushScope(combinedUri.ToString()); } } } JToken referenceToken; if (schemaObject.TryGetValue(JsonTypeReflector.RefPropertyName, out referenceToken)) { JsonSchema deferredSchema = new JsonSchema(); deferredSchema.DeferredReference = (string)referenceToken; deferredSchema.ResolutionScope = _currentResolutionScope; return(deferredSchema); } string location = token.Path.Replace(".", "/").Replace("[", "/").Replace("]", string.Empty); if (!string.IsNullOrEmpty(location)) { location = "/" + location; } location = _currentResolutionScope + "#" + location; JsonSchema existingSchema; if (_documentSchemas.TryGetValue(location, out existingSchema)) { return(existingSchema); } Push(new JsonSchema { Location = location }); ProcessSchemaProperties(schemaObject); if (hasPushedScope) { PopScope(); } return(Pop()); }