コード例 #1
0
        protected override async Task <bool> ProcessInternal()
        {
            var settings = new Settings
            {
                Namespace = await GetValue("namespace") ?? ""
            };

            var files = await ListInputs();

            if (files.Length != 1)
            {
                return(false);
            }

            var content = await ReadFile(files[0]);

            var fs = new MemoryFileSystem();

            fs.WriteAllText(files[0], content);

            var serviceDefinition = SwaggerParser.Parse(fs.ReadAllText(files[0]));
            var modeler           = new SwaggerModeler(settings, true == await GetValue <bool?>("generate-empty-classes"));
            var codeModel         = modeler.Build(serviceDefinition);

            var genericSerializer = new ModelSerializer <CodeModel>();
            var modelAsJson       = genericSerializer.ToJson(codeModel);

            WriteFile("code-model-v1.yaml", modelAsJson, null);

            return(true);
        }
コード例 #2
0
        protected override async Task <bool> ProcessInternal()
        {
            if (true == await this.GetValue <bool?>($"modeler.debugger"))
            {
                AutoRest.Core.Utilities.Debugger.Await();
            }

            var settings = new Settings
            {
                Namespace = await GetValue("namespace") ?? ""
            };

            var files = await ListInputs();

            if (files.Length != 1)
            {
                return(false);
            }

            var content = await ReadFile(files[0]);

            var fs = new MemoryFileSystem();

            fs.WriteAllText(files[0], content);

            var serviceDefinition = SwaggerParser.Parse(fs.ReadAllText(files[0]));
            var modeler           = new SwaggerModeler(settings, true == await GetValue <bool?>("generate-empty-classes"));
            var codeModel         = modeler.Build(serviceDefinition);

            var modelAsJson = JsonConvert.SerializeObject(codeModel, new JsonSerializerSettings
            {
                Converters = { new StringEnumConverter {
                                   CamelCaseText = true
                               } },
                NullValueHandling          = NullValueHandling.Ignore,
                ContractResolver           = CodeModelContractResolver.Instance,
                PreserveReferencesHandling = PreserveReferencesHandling.Objects
            });

            WriteFile("code-model-v1.yaml", modelAsJson, null);

            return(true);
        }