Exemple #1
0
        public void RefResolvesToInternallyStoredSchema()
        {
            var source = new JsonSchema()
                         .Id("http://schema.org/source")
                         .AllOf(new JsonSchema().Ref("http://schema.org/target"));

            var target = new JsonSchema()
                         .Id("http://schema.org/target")
                         .Property("test", true)
                         .Required("test");

            JsonSchemaRegistry.Register(source);
            JsonSchemaRegistry.Register(target);

            try
            {
                var instance = new JsonObject {
                    ["test"] = "literally anything"
                };

                var results = source.Validate(instance);

                results.AssertValid();
            }
            finally
            {
                JsonSchemaRegistry.Unregister(source);
                JsonSchemaRegistry.Unregister(target);
            }
        }
Exemple #2
0
        public void Issue232_RefsNotResolvedAgainstId()
        {
            var resistanceSchema = new JsonSchema()
                                   .Schema(MetaSchemas.Draft07.Id)
                                   .Id("http://localhost/Resistance.schema.json")
                                   .Type(JsonSchemaType.Object)
                                   .Required("t_PulseTimePeriod")
                                   .Property("t_PulseTimePeriod", new JsonSchema().Ref("./definitions.schema.json#definitions/t_PulseTimePeriod"))
                                   .AdditionalProperties(false);
            var definitionsSchema = new JsonSchema()
                                    .Schema(MetaSchemas.Draft07.Id)
                                    .Id("http://localhost/definitions.schema.json")
                                    .Definition("1DVector", new JsonSchema()
                                                .Id("#1DVector")
                                                .Type(JsonSchemaType.Array)
                                                .MinItems(1)
                                                .Items(new JsonSchema()
                                                       .AnyOf(new JsonSchema().Type(JsonSchemaType.Number),
                                                              new JsonSchema().Type(JsonSchemaType.Null))
                                                       .Default(JsonValue.Null))
                                                .Examples(1.1, 2.3, 4.5))
                                    .Definition("t_PulseTimePeriod", new JsonSchema()
                                                .Id("#t_PulseTimePeriod")
                                                .Type(JsonSchemaType.Object)
                                                .Title("The t_PulseTimePeriod Schema")
                                                .Required("values")
                                                .Property("values", new JsonSchema().Ref("#/definitions/1DVector")));

            JsonSchemaRegistry.Register(resistanceSchema);
            JsonSchemaRegistry.Register(definitionsSchema);

            var instance = new JsonObject {
                ["t_PulseTimePeriod"] = new JsonObject {
                    ["values"] = new JsonArray()
                }
            };

            var format = JsonSchemaOptions.OutputFormat;

            try
            {
                JsonSchemaOptions.OutputFormat = SchemaValidationOutputFormat.Detailed;
                var result = resistanceSchema.Validate(instance);

                result.AssertInvalid();
            }
            finally
            {
                JsonSchemaOptions.OutputFormat = format;
            }
        }
Exemple #3
0
        public void RecursiveRefResolvesOuterAnchor_BrokenChain()
        {
            var source = new JsonSchema()
                         .Id("http://schema.org/source")
                         .RecursiveAnchor(true)
                         .OneOf(new JsonSchema()
                                .Property("nested", new JsonSchema()
                                          .Ref("http://schema.org/middle"))
                                .Required("nested"),
                                new JsonSchema()
                                .Property("test", true)
                                .Required("test"));

            var middle = new JsonSchema()
                         .Id("http://schema.org/middle")
                         .OneOf(new JsonSchema()
                                .Ref("http://schema.org/target"),
                                new JsonSchema()
                                .Property("middle", false)
                                .Required("middle"));

            var target = new JsonSchema()
                         .Id("http://schema.org/target")
                         .RecursiveAnchor(true)
                         .AllOf(new JsonSchema().RecursiveRefRoot());

            JsonSchemaRegistry.Register(source);
            JsonSchemaRegistry.Register(middle);
            JsonSchemaRegistry.Register(target);

            try
            {
                var instance = new JsonObject
                {
                    ["nested"] = new JsonObject
                    {
                        ["test"] = "literally anything"
                    }
                };

                var results = source.Validate(instance);

                results.AssertValid();
            }
            finally
            {
                JsonSchemaRegistry.Unregister(source);
                JsonSchemaRegistry.Unregister(middle);
                JsonSchemaRegistry.Unregister(target);
            }
        }
        public static OpenApiDocument ManateeRegisterJsonSchema(string _specLocation)
        {
            var exFiles = "";

            foreach (var file in Directory.GetFiles(_specLocation))
            {
                //var textFromOpenApiSchemaFile = File.ReadAllText(file);
                try
                {
                    JsonSchemaRegistry.Register(JsonSchemaRegistry.Get(file));
                }
                catch (Exception ex)
                {
                    exFiles += file + "\n\n";
                    exFiles += ex.ToString() + "\n\n";
                }
            }

            return(null);
        }