Example #1
0
        /// <summary>Serializes the <see cref="JsonSchema4" /> to a JSON string.</summary>
        /// <returns>The JSON string.</returns>
        public string ToJson()
        {
            var oldSchema = SchemaVersion;

            SchemaVersion = "http://json-schema.org/draft-04/schema#";
            JsonSchemaReferenceUtilities.UpdateSchemaReferencePaths(this, false);
            var json = JsonSchemaReferenceUtilities.ConvertPropertyReferences(JsonConvert.SerializeObject(this, Formatting.Indented));

            SchemaVersion = oldSchema;
            return(json);
        }
Example #2
0
        /// <summary>Serializes the <see cref="JsonSchema4" /> to a JSON string.</summary>
        /// <param name="typeNameGenerator">The type name generator.</param>
        /// <returns>The JSON string.</returns>
        public string ToJson(ITypeNameGenerator typeNameGenerator)
        {
            var oldSchema = SchemaVersion;

            SchemaVersion = "http://json-schema.org/draft-04/schema#";

            JsonSchemaReferenceUtilities.UpdateSchemaReferencePaths(this, new JsonSchemaDefinitionAppender(this, typeNameGenerator));
            var data = JsonConvert.SerializeObject(this, Formatting.Indented);

            JsonSchemaReferenceUtilities.UpdateSchemaReferences(this, new JsonReferenceResolver());

            SchemaVersion = oldSchema;
            return(JsonSchemaReferenceUtilities.ConvertPropertyReferences(data));
        }
Example #3
0
        /// <summary>Serializes the <see cref="JsonSchema4" /> to a JSON string.</summary>
        /// <returns>The JSON string.</returns>
        public string ToJson()
        {
            var oldSchema = SchemaVersion;

            SchemaVersion = "http://json-schema.org/draft-04/schema#";

            var contractResolver = CreateJsonSerializerContractResolver(SchemaType.JsonSchema);

            JsonSchemaSerializationContext.CurrentSchemaType = SchemaType.JsonSchema;
            JsonSchemaReferenceUtilities.UpdateSchemaReferencePaths(this, false, contractResolver);
            var json = JsonConvert.SerializeObject(this, Formatting.Indented, new JsonSerializerSettings
            {
                ContractResolver = contractResolver
            });

            SchemaVersion = oldSchema;
            return(JsonSchemaReferenceUtilities.ConvertPropertyReferences(json));
        }