/// <summary>
        /// Parses the specified json.
        /// </summary>
        /// <param name="json">The json.</param>
        /// <param name="resolver">The resolver.</param>
        /// <returns>A <see cref="JSchema"/> populated from the string that contains JSON.</returns>
        public static JSchema Parse(string json, JSchemaResolver resolver)
        {
            ValidationUtils.ArgumentNotNull(json, "json");

            using (JsonReader reader = new JsonTextReader(new StringReader(json)))
            {
                return(Load(reader, resolver));
            }
        }
        /// <summary>
        /// Loads a <see cref="JSchema"/> from the specified <see cref="JsonReader"/>.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> containing the JSON Schema to load.</param>
        /// <param name="resolver">The <see cref="JSchemaResolver"/> to use when resolving schema references.</param>
        /// <returns>The <see cref="JSchema"/> object representing the JSON Schema.</returns>
        public static JSchema Load(JsonReader reader, JSchemaResolver resolver)
        {
            ValidationUtils.ArgumentNotNull(reader, "reader");
            ValidationUtils.ArgumentNotNull(resolver, "resolver");

            JSchemaReader schemaReader = new JSchemaReader(resolver);

            return(schemaReader.ReadRoot(reader));
        }
        /// <summary>
        /// Load a <see cref="JSchema"/> from a string that contains schema JSON using the given <see cref="JSchemaResolver"/>.
        /// </summary>
        /// <param name="json">The JSON.</param>
        /// <param name="resolver">The <see cref="JSchemaResolver"/> to use when resolving schema references.</param>
        /// <returns>A <see cref="JSchema"/> populated from the string that contains JSON.</returns>
        public static JSchema Parse(string json, JSchemaResolver resolver)
        {
            ValidationUtils.ArgumentNotNull(json, nameof(json));
            ValidationUtils.ArgumentNotNull(resolver, nameof(resolver));

            return(Parse(json, new JSchemaReaderSettings
            {
                Resolver = resolver
            }));
        }
        /// <summary>
        /// Loads a <see cref="JSchema"/> from a <see cref="JsonReader"/> using the given <see cref="JSchemaResolver"/>.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> containing the JSON Schema to load.</param>
        /// <param name="resolver">The <see cref="JSchemaResolver"/> to use when resolving schema references.</param>
        /// <returns>The <see cref="JSchema"/> object representing the JSON Schema.</returns>
        public static JSchema Load(JsonReader reader, JSchemaResolver resolver)
        {
            ValidationUtils.ArgumentNotNull(reader, nameof(reader));
            ValidationUtils.ArgumentNotNull(resolver, nameof(resolver));

            return(Load(reader, new JSchemaReaderSettings
            {
                Resolver = resolver
            }));
        }
        /// <summary>
        /// Generate a <see cref="JSchema"/> from the specified type.
        /// </summary>
        /// <param name="type">The type to generate a <see cref="JSchema"/> from.</param>
        /// <param name="resolver">The <see cref="JSchemaResolver"/> used to resolve schema references.</param>
        /// <param name="rootSchemaNullable">Specify whether the generated root <see cref="JSchema"/> will be nullable.</param>
        /// <returns>A <see cref="JSchema"/> generated from the specified type.</returns>
        public JSchema Generate(Type type, JSchemaResolver resolver, bool rootSchemaNullable)
        {
            ValidationUtils.ArgumentNotNull(type, "type");
            ValidationUtils.ArgumentNotNull(resolver, "resolver");

            _resolver = resolver;

            LicenseHelpers.IncrementAndCheckGenerationCount();

            return(GenerateInternal(type, (!rootSchemaNullable) ? Required.Always : Required.Default, null, null));
        }
 /// <summary>
 /// Generate a <see cref="JSchema"/> from the specified type.
 /// </summary>
 /// <param name="type">The type to generate a <see cref="JSchema"/> from.</param>
 /// <param name="resolver">The <see cref="JSchemaResolver"/> used to resolve schema references.</param>
 /// <returns>A <see cref="JSchema"/> generated from the specified type.</returns>
 public JSchema Generate(Type type, JSchemaResolver resolver)
 {
     return(Generate(type, resolver, false));
 }
        /// <summary>
        /// Load a <see cref="JSchema"/> from a string that contains schema JSON using the given <see cref="JSchemaResolver"/>.
        /// </summary>
        /// <param name="json">The JSON.</param>
        /// <param name="resolver">The <see cref="JSchemaResolver"/> to use when resolving schema references.</param>
        /// <returns>A <see cref="JSchema"/> populated from the string that contains JSON.</returns>
        public static JSchema Parse(string json, JSchemaResolver resolver)
        {
            ValidationUtils.ArgumentNotNull(json, "json");
            ValidationUtils.ArgumentNotNull(resolver, "resolver");

            return Parse(json, new JSchemaReaderSettings
            {
                Resolver = resolver
            });
        }
        /// <summary>
        /// Loads a <see cref="JSchema"/> from a <see cref="JsonReader"/> using the given <see cref="JSchemaResolver"/>.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> containing the JSON Schema to load.</param>
        /// <param name="resolver">The <see cref="JSchemaResolver"/> to use when resolving schema references.</param>
        /// <returns>The <see cref="JSchema"/> object representing the JSON Schema.</returns>
        public static JSchema Load(JsonReader reader, JSchemaResolver resolver)
        {
            ValidationUtils.ArgumentNotNull(reader, "reader");
            ValidationUtils.ArgumentNotNull(resolver, "resolver");

            return Load(reader, new JSchemaReaderSettings
            {
                Resolver = resolver
            });
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="JSchemaPreloadedResolver"/> class with the specified fallback resolver.
 /// </summary>
 /// <param name="resolver">The fallback resolver used when no cached schema was found.</param>
 public JSchemaPreloadedResolver(JSchemaResolver resolver)
     : this()
 {
     _resolver = resolver;
 }
Exemple #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JSchemaPreloadedResolver"/> class with the specified fallback resolver.
 /// </summary>
 /// <param name="resolver">The fallback resolver used when no cached schema was found.</param>
 public JSchemaPreloadedResolver(JSchemaResolver resolver)
     : this()
 {
     _resolver = resolver;
 }