コード例 #1
0
ファイル: RubyCodeGenerator.cs プロジェクト: azhe127/autorest
        /// <summary>
        /// Initializes a new instance of the class RubyCodeGenerator.
        /// </summary>
        /// <param name="settings">The settings.</param>
        public RubyCodeGenerator(Settings settings) : base(settings)
        {
            CodeNamer           = new RubyCodeNamer();
            this.packageVersion = Settings.PackageVersion;
            this.packageName    = Settings.PackageName;

            if (Settings.CustomSettings.ContainsKey("Name"))
            {
                this.sdkName = Settings.CustomSettings["Name"].ToString();
            }

            if (sdkName == null)
            {
                this.sdkName = Path.GetFileNameWithoutExtension(Settings.Input);
            }

            if (sdkName == null)
            {
                sdkName = "client";
            }

            this.sdkName    = RubyCodeNamer.UnderscoreCase(CodeNamer.RubyRemoveInvalidCharacters(this.sdkName));
            this.sdkPath    = this.packageName ?? this.sdkName;
            this.modelsPath = Path.Combine(this.sdkPath, "models");

            // AutoRest generated code for Ruby and Azure.Ruby generator will live inside "generated" sub-folder
            settings.OutputDirectory = Path.Combine(settings.OutputDirectory, GeneratedFolderName);
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the class RubyCodeGenerator.
        /// </summary>
        /// <param name="settings">The settings.</param>
        public RubyCodeGenerator(Settings settings) : base(settings)
        {
            CodeNamer = new RubyCodeNamer();
            this.packageVersion = Settings.PackageVersion;
            this.packageName = Settings.PackageName;

            if (Settings.CustomSettings.ContainsKey("Name"))
            {
                this.sdkName = Settings.CustomSettings["Name"].ToString();
            }

            if (sdkName == null)
            {
                this.sdkName = Path.GetFileNameWithoutExtension(Settings.Input);
            }

            if (sdkName == null)
            {
                sdkName = "client";
            }

            this.sdkName = RubyCodeNamer.UnderscoreCase(CodeNamer.RubyRemoveInvalidCharacters(this.sdkName));
            this.sdkPath = this.packageName ?? this.sdkName;
            this.modelsPath = Path.Combine(this.sdkPath, "models");

            // AutoRest generated code for Ruby and Azure.Ruby generator will live inside "generated" sub-folder
            settings.OutputDirectory = Path.Combine(settings.OutputDirectory, GeneratedFolderName);
        }
コード例 #3
0
ファイル: ExtensionsTests.cs プロジェクト: devigned/autorest
        public void TestClientNameRubyNormalization()
        {
            var setting = new Settings
            {
                Namespace = "Test",
                Input = Path.Combine("Swagger", "swagger-x-ms-client-name.json")
            };

            var modeler = new SwaggerModeler(setting);
            var clientModel = modeler.Build();
            SwaggerExtensions.NormalizeClientModel(clientModel, setting);
            var namer = new RubyCodeNamer();
            namer.NormalizeClientModel(clientModel);

            Assert.NotNull(clientModel);
            Assert.Equal(2, clientModel.Methods.Count);

            Assert.Equal(2, clientModel.Methods[0].Parameters.Where(p => !p.IsClientProperty).Count());

            Assert.Equal("subscription", clientModel.Methods[0].Parameters[0].GetClientName());
            Assert.Equal("version", clientModel.Methods[0].Parameters[1].GetClientName());
            Assert.Equal("subscription", clientModel.Methods[0].Parameters[0].Name);
            Assert.Equal("version", clientModel.Methods[0].Parameters[1].Name);

            Assert.Equal(2, clientModel.Properties.Count);
            Assert.Equal(0, clientModel.Methods[1].Parameters.Where(p => !p.IsClientProperty).Count());

            Assert.Equal("subscription", clientModel.Properties[0].GetClientName());
            Assert.Equal("_version", clientModel.Properties[1].GetClientName());
            Assert.Equal("subscription", clientModel.Properties[0].Name);
            Assert.Equal("_version", clientModel.Properties[1].Name);

            var type = clientModel.ModelTypes.First();

            Assert.Equal("error_code", type.Properties[0].Name);
            Assert.Equal("error_message", type.Properties[1].Name);
            Assert.Equal("parent_error", type.Properties[2].Name);
        }
コード例 #4
0
ファイル: RubyCodeGenerator.cs プロジェクト: azhe127/autorest
        /// <summary>
        /// Generates Ruby code for service client.
        /// </summary>
        /// <param name="serviceClient">The service client.</param>
        /// <returns>Async task for generating SDK files.</returns>
        public override async Task Generate(ServiceClient serviceClient)
        {
            // Service client
            var serviceClientTemplate = new ServiceClientTemplate
            {
                Model = new ServiceClientTemplateModel(serviceClient),
            };

            await Write(serviceClientTemplate,
                        Path.Combine(sdkPath, RubyCodeNamer.UnderscoreCase(serviceClient.Name) + ImplementationFileExtension));

            // Method groups
            foreach (var group in serviceClient.MethodGroups)
            {
                var groupTemplate = new MethodGroupTemplate
                {
                    Model = new MethodGroupTemplateModel(serviceClient, group),
                };
                await Write(groupTemplate,
                            Path.Combine(sdkPath, RubyCodeNamer.UnderscoreCase(group) + ImplementationFileExtension));
            }

            // Models
            foreach (var model in serviceClient.ModelTypes)
            {
                var modelTemplate = new ModelTemplate
                {
                    Model = new ModelTemplateModel(model, serviceClient.ModelTypes)
                };
                await Write(modelTemplate,
                            Path.Combine(modelsPath, RubyCodeNamer.UnderscoreCase(model.Name) + ImplementationFileExtension));
            }

            // Enums
            foreach (var enumType in serviceClient.EnumTypes)
            {
                var enumTemplate = new EnumTemplate
                {
                    Model = new EnumTemplateModel(enumType),
                };
                await Write(enumTemplate,
                            Path.Combine(modelsPath, RubyCodeNamer.UnderscoreCase(enumTemplate.Model.TypeDefinitionName) + ImplementationFileExtension));
            }

            // Requirements
            var requirementsTemplate = new RequirementsTemplate
            {
                Model = new RequirementsTemplateModel(serviceClient, this.packageName ?? this.sdkName, this.ImplementationFileExtension, this.Settings.Namespace),
            };

            await Write(requirementsTemplate, RubyCodeNamer.UnderscoreCase(this.packageName ?? this.sdkName) + ImplementationFileExtension);

            // Version File
            if (!string.IsNullOrEmpty(this.packageVersion))
            {
                var versionTemplate = new VersionTemplate
                {
                    Model = new VersionTemplateModel(packageVersion),
                };
                await Write(versionTemplate, Path.Combine(sdkPath, "version" + ImplementationFileExtension));
            }

            // Module Definition File
            if (!string.IsNullOrEmpty(Settings.Namespace))
            {
                var modTemplate = new ModuleDefinitionTemplate
                {
                    Model = new ModuleDefinitionTemplateModel(Settings.Namespace),
                };
                await Write(modTemplate, Path.Combine(sdkPath, "module_definition" + ImplementationFileExtension));
            }
        }