public ApiProjectModel ScaffoldModel(OpenApiOptions options) { ApiProjectModel model = new ApiProjectModel { ProjectFile = CreateFile(Generator.WriteProjectFile(options), Path.Combine(options.ApiProjectDir, options.ApiProjectName + ".csproj")), StartupCSFile = CreateFile(Generator.WriteStartupCSFile(options), Path.Combine(options.ApiProjectDir, "Startup.cs")), ProgramCSFile = CreateFile(Generator.WriteProgramCSFile(options), Path.Combine(options.ApiProjectDir, "Program.cs")), ServicesConfigurationCSFile = CreateFile(Generator.WriteServicesConfigurationCSFile(options), Path.Combine(options.ApiProjectDir, "ServicesConfiguration.cs")), AppSettingsDevelopmentJSONFile = CreateFile(Generator.WriteAppSettingsDevelopmentJSONFile(options), Path.Combine(options.ApiProjectDir, "appsettings.Development.json")), AppSettingsJSONFile = CreateFile(Generator.WriteAppSettingsJSONFile(options), Path.Combine(options.ApiProjectDir, "appsettings.json")) }; model.Controllers = ControllerScaffolder.ScaffoldModel(options).Files; return(model); }
public string WriteInterfaceCode(IOpenApiDocument document, OpenApiOptions options) { string @namespace = Dependencies.Namespace.Context(options.RootNamespace); string entityNamespace = Dependencies.Namespace.Entity(options.RootNamespace); Clear(); GenerateFileHeader(); WriteLine("using System;"); WriteLine("using System.Threading;"); WriteLine("using Microsoft.EntityFrameworkCore;"); WriteLine($"using {entityNamespace};"); WriteLine(); WriteLine($"namespace {@namespace}"); using (OpenBlock()) { WriteLine($"public interface {options.ContextInterfaceName}"); using (OpenBlock()) { foreach (var kvp in document.Components.Schemas) { string name = kvp.Key; OpenApiSchema schema = kvp.Value; WriteLine(); WriteLine($@"DbSet<{name}> {name} {{ get; set; }}"); } } } return(GetText()); }
public string WriteProgramCSFile(OpenApiOptions options) { Clear(); GenerateFileHeader(); WriteLine("using Microsoft.AspNetCore;"); WriteLine("using Microsoft.AspNetCore.Hosting;"); WriteLine(); WriteLine($"namespace {options.RootNamespace}"); using (OpenBlock()) { WriteLine("public class Program"); using (OpenBlock()) { WriteLine("public static void Main(string[] args) => BuildWebHost(args).Run();"); WriteLine(); WriteLine("private static IWebHost BuildWebHost(string[] args) =>"); PushIndent(); WriteLine("WebHost.CreateDefaultBuilder(args)"); PushIndent(); WriteLine(".UseStartup<Startup>()"); WriteLine(".Build();"); PopIndent(); PopIndent(); } } return(GetText()); }
public override string WriteProjectFile(OpenApiOptions options) { Clear(); using (OpenProjectBlock()) { using (OpenPropertyGroupBlock()) { WriteProperty("RootNamespace", options.RootNamespace); WriteProperty("TargetFramework", "netcoreapp3.0"); } WriteLine(); WriteSdkElement("Microsoft.NET.Sdk"); WriteLine(); using (OpenItemGroupBlock()) { WriteLine("<PackageReference Include=\"Microsoft.EntityFrameworkCore.Design\" Version=\"3.1.0\">"); WriteLine(" <PrivateAssets>all</PrivateAssets>"); WriteLine(" <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>"); WriteLine("</PackageReference>"); WriteLine("<PackageReference Include=\"Microsoft.EntityFrameworkCore.Abstractions\" Version=\"3.1.0\" />"); WriteLine("<PackageReference Include=\"Microsoft.EntityFrameworkCore.SqlServer\" Version=\"3.1.0\" />"); } using (OpenItemGroupBlock()) { WriteLine($"<ProjectReference Include=\"..\\{options.CoreProjectName}\\{options.CoreProjectName}.csproj\"/>"); } } return(GetText()); }
private ScaffoldedFile CreateProjectFile(OpenApiOptions options) { return(new ScaffoldedFile { Code = Generator.WriteProjectFile(options), Path = Path.Combine(options.DataProjectDir, options.DataProjectName + ".csproj") }); }
public static Dictionary <string, string> Create(OpenApiOptions options) { return(CreateReplacementsDictionary( options.SolutionName, options.Document.Info.Description, options.RootNamespace, options.RepositoryName, TargetFramework.NetCoreApp_2_2)); }
private void ProcessClassFile(OpenApiOptions options, List <ScaffoldedFile> list, string name, OpenApiSchema schema) { var classCode = Generator.WriteClassCode(schema, name, options); var classPath = Dependencies.PathHelper.Repository(options.DataProjectDir, name); var classFile = new ScaffoldedFile { Code = classCode, Path = classPath }; list.Add(classFile); }
private void ProcessInterfaceFile(OpenApiOptions options, List <ScaffoldedFile> list, string name, OpenApiSchema schema) { var interfaceCode = Generator.WriteInterfaceCode(schema, name, options); var interfacePath = Dependencies.PathHelper.RepositoryInterface(options.CoreProjectDir, name); var interfaceFile = new ScaffoldedFile { Code = interfaceCode, Path = interfacePath }; list.Add(interfaceFile); }
public ContentTypeDocumentProcessor( IOptions <OpenApiOptions> openApiOptions, IOptions <ContentOptions> contentOptions, IHttpContextAccessor httpContentAccessor ) { _openApiOptions = openApiOptions.Value; _httpContextAccessor = httpContentAccessor; _contentOptions = contentOptions.Value; }
public HomeController( IOptions <OpenApiOptions> apiOptions, IMemoryCache memoryCache, IHttpClientFactory httpClientFactory, ILogger <HomeController> logger) { _memoryCache = memoryCache; _httpClientFactory = httpClientFactory; _logger = logger; _apiOptions = apiOptions.Value; }
public DataProjectModel ScaffoldModel(OpenApiOptions options) { DataProjectModel model = new DataProjectModel { ProjectFile = CreateProjectFile(options), DataContext = Context.ScaffoldModel(options).Class, Configurations = Configuration.ScaffoldModel(options).Files, RepositoryClasses = Repository.ScaffoldModel(options).Files }; return(model); }
public SupervisorInterfaceModel ScaffoldModel(OpenApiOptions options) { SupervisorInterfaceModel model = new SupervisorInterfaceModel { File = new ScaffoldedFile { Code = Generator.WriteCode(options), Path = Dependencies.PathHelper.SupervisorInterface(options.CoreProjectDir, options.SupervisorInterfaceName) } }; return(model); }
public string WriteAppSettingsDevelopmentJSONFile(OpenApiOptions options) { Clear(); WriteLine("{"); WriteLine(" \"Logging\": {"); WriteLine(" \"IncludeScopes\": false,"); WriteLine(" \"LogLevel\": {"); WriteLine(" \"Default\": \"Debug\","); WriteLine(" \"System\": \"Information\","); WriteLine(" \"Microsoft\": \"Information\""); WriteLine(" }"); WriteLine(" }"); WriteLine("}"); return(GetText()); }
public EntityModel BuildModel(OpenApiOptions options) { foreach (var kvp in options.Document.Components.Schemas.Where(x => x.Value.Type == "object")) { string key = kvp.Key; OpenApiSchema schema = kvp.Value; Entity entity = Model.AddEntity(key); if (entity != null) { Initialize(schema, entity, options); } } return(Model); }
public RepositoryModel ScaffoldModel(OpenApiOptions options) { var model = new RepositoryModel(); var list = new List <ScaffoldedFile>(); foreach (var kvp in options.Document.GetSchemas()) { var name = kvp.Key; var schema = kvp.Value; ProcessClassFile(options, list, name, schema); } model.Files = list; return(model); }
public ContextModel ScaffoldModel(OpenApiOptions options) { var model = new ContextModel(); var classFile = new ScaffoldedFile(); var interfaceFile = new ScaffoldedFile(); classFile.Code = Generator.WriteClassCode(options.Document, options); classFile.Path = Dependencies.PathHelper.Context(options.DataProjectDir, options.ContextClassName); //interfaceFile.Code = Generator.WriteInterfaceCode(options.Document, options); //interfaceFile.Path = Dependencies.PathHelper.Context(options.DataProjectDir, options.ContextInterfaceName); model.Class = classFile; //model.Interface = interfaceFile; return(model); }
public CoreProjectModel ScaffoldModel(OpenApiOptions options) { SupervisorModel supervisorModel = Supervisor.ScaffoldModel(options); SupervisorInterfaceModel supervisorInterfaceModel = SupervisorInterface.ScaffoldModel(options); return(new CoreProjectModel { ProjectFile = CreateProjectFile(options), Supervisor = supervisorModel.File, SupervisorInterface = supervisorInterfaceModel.File, Converters = Converter.ScaffoldModel(options).Files, Entities = Entities.ScaffoldModel(options).Files, ViewModels = ViewModels.ScaffoldModel(options).Files, RepositoryInterfaces = Repositories.ScaffoldModel(options).Files }); }
public ScaffoldedModel ScaffoldModel(OpenApiOptions options) { return(new ScaffoldedModel { Configuration = _configuration.ScaffoldModel(options), Controller = _controller.ScaffoldModel(options), Converter = _converter.ScaffoldModel(options), Entity = _entity.ScaffoldModel(options), Repository = _repository.ScaffoldModel(options), RepoisitoryInterfaces = _repositoryInterface.ScaffoldModel(options), ViewModel = _viewModel.ScaffoldModel(options), Supervisor = _supervisor.ScaffoldModel(options), SupervisorInterface = _supervisorInterface.ScaffoldModel(options), Context = _context.ScaffoldModel(options) }); }
public SolutionModel ScaffoldModel(OpenApiOptions options) { SolutionModel model = new SolutionModel { SolutionFile = new ScaffoldedFile { Code = Generator.WriteProjectFile(options), Path = Path.Combine(options.SolutionDir, $"{options.SolutionName}.sln") }, ApiProject = ApiProject.ScaffoldModel(options), CoreProject = CoreProject.ScaffoldModel(options), DataProject = DataProject.ScaffoldModel(options) }; return(model); }
public override string WriteProjectFile(OpenApiOptions options) { Clear(); using (OpenProjectBlock()) { using (OpenPropertyGroupBlock()) { WriteProperty("RootNamespace", options.RootNamespace); WriteProperty("TargetFramework", "netcoreapp3.0"); } WriteLine(); WriteSdkElement("Microsoft.NET.Sdk"); WriteLine(); } return(GetText()); }
public static string CreateRepository(OpenApiOptions options) { string zipFilePath = Path.Combine(options.OutputDir, "arcade.zip"); string repositoryDirectory = Path.Combine(options.OutputDir, options.SolutionName); string solutionFilePath = Path.Combine(repositoryDirectory, $"{options.SolutionName}.sln"); SlowlyRemoveAndRecreateDirectory(repositoryDirectory); RepositoryDownloader.DownloadFile(DownloadUrls.Arcade, zipFilePath); RepositoryExpander.ExpandFile(zipFilePath, repositoryDirectory); Directory.Delete( Path.Combine(repositoryDirectory, "src", "ArcadeRepo"), true); File.Delete( Path.Combine(repositoryDirectory, "ArcadeRepo.sln")); var replacements = Replacer.Create(options); Process(repositoryDirectory, replacements); return(Path.Combine(repositoryDirectory, "src")); }
private void Initialize(OpenApiSchema schema, Entity entity, OpenApiOptions options) { if (entity.Initialized) { return; } entity.Initialized = true; AddPrimaryKeyProperty(entity, options); foreach (var kvp in schema.Properties) { //if (schema.Type == "array" || schema.Reference != null) //{ // continue; //} string propertyName = CodeIdentifier.MakePascal(kvp.Key); OpenApiSchema propertySchema = kvp.Value; string propertyType = Converter.ConvertToType(propertySchema); Property property = entity.AddProperty(propertyName, propertyType); } foreach (var kvp in schema.Properties) { string propertyName = kvp.Key; OpenApiSchema propertySchema = kvp.Value; if (propertySchema.Type == "array") { Property property = entity.GetProperties().FirstOrDefault(p => p.Name == propertyName); if (propertySchema.Items.Reference?.IsLocal == true) { string findName = propertySchema.Items.Reference.Id; Entity dependentEntity = Model.GetOrAddEntity(findName); OpenApiSchema openApiSchema = options.Document.Components.Schemas[findName]; Initialize(openApiSchema, dependentEntity, options); Key principalKey = entity.FindPrimaryKey(); Entity principalEntity = entity; string foreignKeyName = principalKey.Property.Name; dependentEntity.AddProperty(foreignKeyName, options.PrimaryKeyTypeName); dependentEntity.AddProperty(principalEntity.Name, principalEntity.Name); } } } }
public string WriteCode(OpenApiOptions options) { var document = options.Document; string supervisorNamespace = Dependencies.Namespace.Supervisor(options.RootNamespace); string viewModelNamespace = Dependencies.Namespace.ViewModel(options.RootNamespace); Clear(); GenerateFileHeader(); WriteLine("using System;"); WriteLine("using System.Threading;"); WriteLine("using System.Threading.Tasks;"); WriteLine("using System.Collections.Generic;"); WriteLine($"using {viewModelNamespace};"); WriteLine(); WriteLine($"namespace {supervisorNamespace}"); using (OpenBlock()) { WriteLine($"public interface {options.SupervisorInterfaceName}"); using (OpenBlock()) { foreach (var kvp in document.GetSchemas()) { string name = kvp.Key; string entityName = Dependencies.Namer.Entity(kvp.Key); string viewModelName = Dependencies.Namer.ViewModel(kvp.Key); string primaryKeyTypeName = document.Options.PrimaryKeyTypeName; WriteLine(); WriteLine($"// {name}"); WriteLine(); WriteLine($"Task<List<{viewModelName}>> GetAll{name}Async(CancellationToken ct = default(CancellationToken));"); WriteLine($"Task<{viewModelName}> Get{name}ByIdAsync({primaryKeyTypeName} id, CancellationToken ct = default(CancellationToken));"); WriteLine($"Task<{viewModelName}> Add{name}Async({viewModelName} input, CancellationToken ct = default(CancellationToken));"); WriteLine($"Task<bool> Update{name}Async({viewModelName} input, CancellationToken ct = default(CancellationToken));"); WriteLine($"Task<bool> Delete{name}Async({primaryKeyTypeName} id, CancellationToken ct = default(CancellationToken));"); } } } return(GetText()); }
public static IApplicationBuilder ConfigureOpenApi(this IApplicationBuilder app, IConfiguration configuration) { var openApiOptions = new OpenApiOptions(); configuration.GetSection("openAPi").Bind(openApiOptions); app.UseOpenApi(settings => { settings.DocumentName = openApiOptions.DocumentName; }); app.UseSwaggerUi3(settings => { settings.Path = openApiOptions.Path; settings.OAuth2Client = new OAuth2ClientSettings() { AppName = openApiOptions.AppName, ClientId = openApiOptions.ClientId }; settings.OAuth2Client.AdditionalQueryStringParameters.Add("nonce", StringHelper.Random(6, RandomCharacterSet.AlphanumericAndSpecial)); }); return(app); }
public SupervisorModel ScaffoldModel(OpenApiOptions options) { string supervisorNamespace = Dependencies.Namespace.Supervisor(options.RootNamespace); var model = new SupervisorModel(); var classFile = new ScaffoldedFile { //var interfaceFile = new ScaffoldedFile(); Code = Generator.WriteClassCode(options.Document, options.SupervisorClassName, options.SupervisorInterfaceName, supervisorNamespace), Path = Dependencies.PathHelper.Supervisor(options.CoreProjectDir, options.SupervisorClassName) }; //interfaceFile.Code = Generator.WriteInterfaceCode(options.Document, options.SupervisorInterfaceName, supervisorNamespace); //interfaceFile.Path = Dependencies.PathHelper.Supervisor(options.CoreProjectDir, options.SupervisorInterfaceName); model.File = classFile; //model.Interface = interfaceFile; return(model); }
public ConfigurationModel ScaffoldModel(OpenApiOptions options) { var model = new ConfigurationModel(); List <ScaffoldedFile> list = new List <ScaffoldedFile>(); foreach (var kvp in options.Document.GetSchemas()) { var name = kvp.Key; var schema = kvp.Value; var code = Generator.WriteCode(schema, name, Dependencies.Namespace.Configuration(options.RootNamespace)); var path = Dependencies.PathHelper.Configuration(options.DataProjectDir, name); var file = new ScaffoldedFile { Code = code, Path = path }; list.Add(file); } model.Files = list; return(model); }
public override string WriteProjectFile(OpenApiOptions options) { Clear(); using (OpenProjectBlock()) { using (OpenPropertyGroupBlock()) { WriteProperty("RootNamespace", options.RootNamespace); WriteProperty("TargetFramework", "netcoreapp3.0"); } WriteLine(); WriteSdkElement("Microsoft.NET.Sdk.Web"); WriteLine(); using (OpenItemGroupBlock()) { WriteLine("<Content Update=\"appsettings.json\" CopyToOutputDirectory=\"Always\"/>"); } using (OpenItemGroupBlock()) { WriteLine("<FrameworkReference Include=\"Microsoft.AspNetCore.App\" />"); WriteLine("<PackageReference Include=\"Microsoft.Extensions.Logging\" Version=\"3.1.0\" />"); WriteLine("<PackageReference Include=\"Newtonsoft.Json\" Version=\"12.0.3\" />"); WriteLine("<PackageReference Include=\"Swashbuckle.AspNetCore\" Version=\"5.0.0-rc5\" />"); } using (OpenItemGroupBlock()) { WriteLine("<DotNetCliToolReference Include=\"Microsoft.VisualStudio.Web.CodeGeneration.Tools\" Version=\"2.0.4\" />"); } using (OpenItemGroupBlock()) { WriteLine($"<ProjectReference Include=\"..\\{options.DataProjectName}\\{options.DataProjectName}.csproj\"/>"); WriteLine($"<ProjectReference Include=\"..\\{options.CoreProjectName}\\{options.CoreProjectName}.csproj\"/>"); } } return(GetText()); }
public string WriteAppSettingsJSONFile(OpenApiOptions options) { Clear(); WriteLine("{"); WriteLine(" \"ConnectionStrings\": {"); WriteLine($" \"DefaultDbConnection\": \"Server=.;Database={options.DatabaseName};Trusted_Connection=True\""); WriteLine(" },"); WriteLine(" \"Logging\": {"); WriteLine(" \"IncludeScopes\": false,"); WriteLine(" \"Debug\": {"); WriteLine(" \"LogLevel\": {"); WriteLine(" \"Default\": \"Warning\""); WriteLine(" }"); WriteLine(" },"); WriteLine(" \"Console\": {"); WriteLine(" \"LogLevel\": {"); WriteLine(" \"Default\": \"Warning\""); WriteLine(" }"); WriteLine(" }"); WriteLine(" }"); WriteLine("}"); return(GetText()); }
public static IApplicationBuilder UseConfiguredSwagger( this IApplicationBuilder app, OpenApiOptions openapi, string audience, string pathbase ) { app.UseSwagger(cfg => { cfg.RouteTemplate = "api/{documentName}/openapi.json"; }); app.UseSwaggerUI(cfg => { cfg.RoutePrefix = "api"; cfg.SwaggerEndpoint($"{pathbase}/api/v1/openapi.json", $"{openapi.ApiName} (v1)"); cfg.OAuthClientId(openapi.Client.ClientId); cfg.OAuthAppName(openapi.Client.ClientName ?? openapi.Client.ClientId); cfg.OAuthScopes(audience); }); return(app); }
public string WriteInterfaceCode(OpenApiSchema schema, string name, OpenApiOptions options) { string repositoryNamespace = Dependencies.Namespace.Repository(options.RootNamespace); string entityNamespace = Dependencies.Namespace.Entity(options.RootNamespace); Clear(); GenerateFileHeader(); WriteLine("using System;"); WriteLine("using System.Threading;"); WriteLine("using System.Threading.Tasks;"); WriteLine("using System.Collections.Generic;"); WriteLine($"using {entityNamespace};"); WriteLine(); WriteLine($"namespace {repositoryNamespace}"); using (OpenBlock()) { string className = Dependencies.Namer.Repository(name); string entityName = Dependencies.Namer.Entity(name); WriteLine($"public interface I{className} : IDisposable"); using (OpenBlock()) { WriteLine(); WriteLine($"Task<List<{entityName}>> GetAllAsync(CancellationToken ct = default);"); WriteLine(); WriteLine($"Task<{entityName}> GetByIdAsync({options.PrimaryKeyTypeName} id, CancellationToken ct = default);"); WriteLine(); WriteLine($"Task<{entityName}> AddAsync({entityName} entity, CancellationToken ct = default);"); WriteLine(); WriteLine($"Task<bool> UpdateAsync({entityName} entity, CancellationToken ct = default);"); WriteLine(); WriteLine($"Task<bool> DeleteAsync({options.PrimaryKeyTypeName} id, CancellationToken ct = default);"); } } return(GetText()); }