public JSchemaDiscovery(List <KnownSchema> knownSchemas, KnownSchemaState state) { _state = state; _pathStack = new Stack <SchemaPath>(); _knownSchemas = knownSchemas ?? new List <KnownSchema>(); }
public JSchemaDiscovery(KnownSchemaCollection knownSchemas, KnownSchemaState state) { _state = state; _pathStack = new List <SchemaPath>(); _knownSchemas = knownSchemas ?? new KnownSchemaCollection(); }
public JSchemaDiscovery(List<KnownSchema> knownSchemas, KnownSchemaState state) { _state = state; _pathStack = new Stack<SchemaPath>(); _knownSchemas = knownSchemas ?? new List<KnownSchema>(); }
private void DiscoverInternal(JSchema schema, string latestPath, bool isDefinitionSchema = false) { if (schema.Reference != null) { return; } // give schemas that are dependencies a special state so they are written as a dependency and not inline KnownSchemaState resolvedSchemaState = (_state == KnownSchemaState.InlinePending && isDefinitionSchema) ? KnownSchemaState.DefinitionPending : _state; string scopePath = latestPath; Uri schemaKnownId = GetSchemaIdAndNewScopeId(schema, ref scopePath, out Uri newScopeId); if (_knownSchemas.Contains(schema)) { KnownSchema alreadyDiscoveredSchema = _knownSchemas[schema]; // schema was previously discovered but exists in definitions if (alreadyDiscoveredSchema.State == KnownSchemaState.InlinePending && resolvedSchemaState == KnownSchemaState.DefinitionPending && _rootSchema != schema) { int existingKnownSchemaIndex = _knownSchemas.IndexOf(alreadyDiscoveredSchema); _knownSchemas[existingKnownSchemaIndex] = new KnownSchema(schemaKnownId, schema, resolvedSchemaState); } return; } // check whether a schema with the resolved id is already known // this will be hit when a schema contains duplicate ids or references a schema with a duplicate id bool existingSchema = _knownSchemas.GetById(schemaKnownId) != null; // add schema to known schemas whether duplicate or not to avoid multiple errors // the first schema with a duplicate id will be used _knownSchemas.Add(new KnownSchema(schemaKnownId, schema, resolvedSchemaState)); if (existingSchema) { if (ValidationErrors != null) { ValidationError error = ValidationError.CreateValidationError($"Duplicate schema id '{schemaKnownId.OriginalString}' encountered.", ErrorType.Id, schema, null, schemaKnownId, null, schema, schema.Path); ValidationErrors.Add(error); } } _pathStack.Add(new SchemaPath(newScopeId, scopePath)); // discover should happen in the same order as writer except extension data (e.g. definitions) if (schema._extensionData != null) { foreach (KeyValuePair <string, JToken> valuePair in schema._extensionData) { DiscoverTokenSchemas(schema, EscapePath(valuePair.Key), valuePair.Value); } } DiscoverSchema(Constants.PropertyNames.AdditionalProperties, schema.AdditionalProperties); DiscoverSchema(Constants.PropertyNames.AdditionalItems, schema.AdditionalItems); DiscoverDictionarySchemas(Constants.PropertyNames.Properties, schema._properties); DiscoverDictionarySchemas(Constants.PropertyNames.PatternProperties, schema._patternProperties); DiscoverDictionarySchemas(Constants.PropertyNames.Dependencies, schema._dependencies); if (schema.ItemsPositionValidation) { DiscoverArraySchemas(Constants.PropertyNames.Items, schema._items); } else if (schema._items != null && schema._items.Count > 0) { DiscoverSchema(Constants.PropertyNames.Items, schema._items[0]); } DiscoverArraySchemas(Constants.PropertyNames.AllOf, schema._allOf); DiscoverArraySchemas(Constants.PropertyNames.AnyOf, schema._anyOf); DiscoverArraySchemas(Constants.PropertyNames.OneOf, schema._oneOf); DiscoverSchema(Constants.PropertyNames.Not, schema.Not); DiscoverSchema(Constants.PropertyNames.PropertyNamesSchema, schema.PropertyNames); DiscoverSchema(Constants.PropertyNames.Contains, schema.Contains); DiscoverSchema(Constants.PropertyNames.If, schema.If); DiscoverSchema(Constants.PropertyNames.Then, schema.Then); DiscoverSchema(Constants.PropertyNames.Else, schema.Else); _pathStack.RemoveAt(_pathStack.Count - 1); }
public JSchemaDiscovery(JSchema rootSchema, KnownSchemaCollection knownSchemas, KnownSchemaState state) { _rootSchema = rootSchema; _state = state; _pathStack = new List <SchemaPath>(); KnownSchemas = knownSchemas ?? new KnownSchemaCollection(); }
public KnownSchema(Uri id, JSchema schema, KnownSchemaState state) { Id = id; Schema = schema; State = state; }