Ejemplo n.º 1
0
        private SchemaResult CheckSchemaAgainstExamples(SchemaDefinition schemaDefinition, IEnumerable <SchemaExample> examples)
        {
            var example = examples.FirstOrDefault(e => schemaDefinition.SchemaName == e.SchemaName);

            if (example == null)
            {
                return(SchemaResult.CreateFailure(schemaDefinition.SchemaName, $"Cannot find example for {schemaDefinition.SchemaName}"));
            }

            var schemaResult = CheckSchema(example.Example, schemaDefinition);

            return(schemaResult);
        }
Ejemplo n.º 2
0
        private SchemaResult CheckSchema(JObject exampleJson, SchemaDefinition definition)
        {
            var jSchema = JSchema.Parse(definition.Schema.ToString(), settings);

            var isValid = exampleJson.IsValid(jSchema, out IList <string> errors);

            if (isValid)
            {
                return(SchemaResult.CreateSuccess(definition.SchemaName, definition.ConsumerName));
            }

            return(SchemaResult.CreateFailure(definition.SchemaName, definition.ConsumerName, errors.ToArray()));
        }