public static async Task CreateClassfromJsonSchema(string url)
        {
            JsonSchema jsonSchema = await JsonSchema.FromUrlAsync(url);

            CSharpGenerator generator = new CSharpGenerator(jsonSchema);
            string          file      = generator.GenerateFile();
        }
Пример #2
0
        public async Task When_azure_schema_is_loaded_then_no_exception()
        {
            // Issue: https://github.com/RicoSuter/NJsonSchema/issues/588

            var schema = await JsonSchema.FromUrlAsync(
                @"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json");

            var json = schema.ToJson();

            //// Assert
            Assert.NotNull(schema);
            Assert.Contains("The identity type.", json);
        }
Пример #3
0
        public async Task When_json_schema_is_loaded_then_no_collection_modified_exception_is_thrown()
        {
            // https://github.com/NJsonSchema/NJsonSchema/issues/288

            //// Arrange


            //// Act
            var schema = await JsonSchema.FromUrlAsync("http://schemas.sportradar.com/bsa/json/v1/endpoints/soccer/team_profile.json");

            var json = schema.ToJson();

            //// Assert
            Assert.NotNull(json);
        }
Пример #4
0
 private static async Task <JsonSchema> GetSchemaAsync(string uri)
 {
     if (uri.StartsWith("http://") || uri.StartsWith("https://"))
     {
         return(await JsonSchema.FromUrlAsync(uri));
     }
     else
     {
         var path = Path.GetFullPath(Path.Combine(System.Environment.CurrentDirectory, uri));
         if (!File.Exists(path))
         {
             throw new Exception($"The specified schema, {uri}, can not be found as a relative file or a url.");
         }
         return(await JsonSchema.FromJsonAsync(File.ReadAllText(path)));
     }
 }
        /// <summary>
        /// Download the json schemas from cdn
        /// </summary>
        private async Task <JsonSchema[]> GetJsonSchema()
        {
            var urls = new string[]
            {
                // "https://altinncdn.no/schemas/json/component/number-format.schema.v1.json",
                // "https://altinncdn.no/schemas/json/layout/layout-sets.schema.v1.json",
                "https://altinncdn.no/schemas/json/layout/layout.schema.v1.json",
                "https://altinncdn.no/schemas/json/layout/layoutSettings.schema.v1.json",
                "https://altinncdn.no/schemas/json/policy/policy.schema.v1.json",
                "https://altinncdn.no/schemas/json/prefill/prefill.schema.v1.json",
                "https://altinncdn.no/schemas/json/widget/widget.schema.v1.json"
            };
            var tasks  = urls.Select(url => JsonSchema.FromUrlAsync(url));
            var result = await Task.WhenAll(tasks);

            return(result);
        }
Пример #6
0
        /// <exception cref="ArgumentException">The argument 'Input' was empty.</exception>
        protected async Task <JsonSchema> GetJsonSchemaAsync()
        {
            var input = Input.ToString();

            if (string.IsNullOrEmpty(input))
            {
                throw new ArgumentException("The argument 'Input' was empty.");
            }

            if (IsJson(input))
            {
                return(await JsonSchema.FromJsonAsync(input).ConfigureAwait(false));
            }

            if (DynamicApis.FileExists(input))
            {
                return(await JsonSchema.FromFileAsync(input).ConfigureAwait(false));
            }

            return(await JsonSchema.FromUrlAsync(input).ConfigureAwait(false));
        }
Пример #7
0
        public async ValueTask ExecuteAsync(IConsole console)
        {
            await console.Output.WriteLineAsync("Downloading recent jsonschema for asp.net core default appsettings json.");

            var defaultSettingsJsonSchema = await JsonSchema.FromUrlAsync("https://json.schemastore.org/appsettings");

            await console.Output.WriteLineAsync("Create appsettings json for localizer");

            var settingSchema = JsonSchema.FromType <AppSettingsJson>();

            await console.Output.WriteLineAsync("Combining schema..");

            settingSchema.AllOf.Add(defaultSettingsJsonSchema);

            await console.Output.WriteLineAsync("Create file for schmea");

            var outputFilePath = Path.Join(Directory.GetCurrentDirectory(), Output ?? "", "localizer.schema.json");

            await using var fileStream = File.Create(outputFilePath);
            await fileStream.WriteAsync(Encoding.UTF8.GetBytes(settingSchema.ToJson()));

            await console.Output.WriteLineAsync("Done");
        }