示例#1
0
 public JsonSchemaBuilder(JsonSchemaResolver resolver)
 {
     _stack = new List<JsonSchema>();
     _documentSchemas = new Dictionary<string, JsonSchema>();
     _resolver = resolver;
 }
示例#2
0
 public JsonSchemaWriter(JsonWriter writer, JsonSchemaResolver resolver)
 {
     ValidationUtils.ArgumentNotNull(writer, "writer");
     _writer = writer;
     _resolver = resolver;
 }
示例#3
0
        /// <summary>
        /// Writes this schema to a <see cref="JsonWriter"/> using the specified <see cref="JsonSchemaResolver"/>.
        /// </summary>
        /// <param name="writer">A <see cref="JsonWriter"/> into which this method will write.</param>
        /// <param name="resolver">The resolver used.</param>
        public void WriteTo(JsonWriter writer, JsonSchemaResolver resolver)
        {
            ValidationUtils.ArgumentNotNull(writer, "writer");
            ValidationUtils.ArgumentNotNull(resolver, "resolver");

            JsonSchemaWriter schemaWriter = new JsonSchemaWriter(writer, resolver);
            schemaWriter.WriteSchema(this);
        }
示例#4
0
 public JsonSchemaWriter(JsonWriter writer, JsonSchemaResolver resolver)
 {
     ValidationUtils.ArgumentNotNull(writer, "writer");
     _writer   = writer;
     _resolver = resolver;
 }
示例#5
0
        /// <summary>
        /// Reads a <see cref="JsonSchema"/> from the specified <see cref="JsonReader"/>.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> containing the JSON Schema to read.</param>
        /// <param name="resolver">The <see cref="JsonSchemaResolver"/> to use when resolving schema references.</param>
        /// <returns>The <see cref="JsonSchema"/> object representing the JSON Schema.</returns>
        public static JsonSchema Read(JsonReader reader, JsonSchemaResolver resolver)
        {
            ValidationUtils.ArgumentNotNull(reader, "reader");
            ValidationUtils.ArgumentNotNull(resolver, "resolver");

            JsonSchemaBuilder builder = new JsonSchemaBuilder(resolver);
            return builder.Read(reader);
        }
示例#6
0
        /// <summary>
        /// Parses the specified json.
        /// </summary>
        /// <param name="json">The json.</param>
        /// <param name="resolver">The resolver.</param>
        /// <returns>A <see cref="JsonSchema"/> populated from the string that contains JSON.</returns>
        public static JsonSchema Parse(string json, JsonSchemaResolver resolver)
        {
            ValidationUtils.ArgumentNotNull(json, "json");

            using (JsonReader reader = new JsonTextReader(new StringReader(json)))
            {
                return Read(reader, resolver);
            }
        }
示例#7
0
 /// <summary>
 /// Generate a <see cref="JsonSchema"/> from the specified type.
 /// </summary>
 /// <param name="type">The type to generate a <see cref="JsonSchema"/> from.</param>
 /// <param name="resolver">The <see cref="JsonSchemaResolver"/> used to resolve schema references.</param>
 /// <returns>A <see cref="JsonSchema"/> generated from the specified type.</returns>
 public JsonSchema Generate(Type type, JsonSchemaResolver resolver)
 {
     return(Generate(type, resolver, false));
 }
示例#8
0
        /// <summary>
        /// Generate a <see cref="JsonSchema"/> from the specified type.
        /// </summary>
        /// <param name="type">The type to generate a <see cref="JsonSchema"/> from.</param>
        /// <param name="resolver">The <see cref="JsonSchemaResolver"/> used to resolve schema references.</param>
        /// <param name="rootSchemaNullable">Specify whether the generated root <see cref="JsonSchema"/> will be nullable.</param>
        /// <returns>A <see cref="JsonSchema"/> generated from the specified type.</returns>
        public JsonSchema Generate(Type type, JsonSchemaResolver resolver, bool rootSchemaNullable)
        {
            ValidationUtils.ArgumentNotNull(type, "type");
            ValidationUtils.ArgumentNotNull(resolver, "resolver");

            _resolver = resolver;

            return GenerateInternal(type, (!rootSchemaNullable) ? Required.Always : Required.Default, false);
        }
示例#9
0
 /// <summary>
 /// Generate a <see cref="JsonSchema"/> from the specified type.
 /// </summary>
 /// <param name="type">The type to generate a <see cref="JsonSchema"/> from.</param>
 /// <param name="resolver">The <see cref="JsonSchemaResolver"/> used to resolve schema references.</param>
 /// <returns>A <see cref="JsonSchema"/> generated from the specified type.</returns>
 public JsonSchema Generate(Type type, JsonSchemaResolver resolver)
 {
     return Generate(type, resolver, false);
 }