Ejemplo n.º 1
0
 public JsonSchemaBuilder(JsonSchemaResolver resolver)
 {
     _stack = new List<JsonSchema>();
     _documentSchemas = new Dictionary<string, JsonSchema>();
     _resolver = resolver;
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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, nameof(type));
            ValidationUtils.ArgumentNotNull(resolver, nameof(resolver));

            _resolver = resolver;

            return GenerateInternal(type, (!rootSchemaNullable) ? Required.Always : Required.Default, false);
        }
Ejemplo n.º 4
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, nameof(writer));
            ValidationUtils.ArgumentNotNull(resolver, nameof(resolver));

            JsonSchemaWriter schemaWriter = new JsonSchemaWriter(writer, resolver);
            schemaWriter.WriteSchema(this);
        }
Ejemplo n.º 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, nameof(reader));
            ValidationUtils.ArgumentNotNull(resolver, nameof(resolver));

            JsonSchemaBuilder builder = new JsonSchemaBuilder(resolver);
            return builder.Read(reader);
        }
Ejemplo n.º 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, nameof(json));

            using (JsonReader reader = new JsonTextReader(new StringReader(json)))
            {
                return Read(reader, resolver);
            }
        }
Ejemplo n.º 7
0
 public JsonSchemaWriter(JsonWriter writer, JsonSchemaResolver resolver)
 {
     ValidationUtils.ArgumentNotNull(writer, nameof(writer));
     _writer = writer;
     _resolver = resolver;
 }
Ejemplo n.º 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>
 /// <returns>A <see cref="JsonSchema"/> generated from the specified type.</returns>
 public JsonSchema Generate(Type type, JsonSchemaResolver resolver)
 {
     return(Generate(type, resolver, false));
 }