From c992191f57e090b1c3fffb1779cd8f4eb4c49f98 Mon Sep 17 00:00:00 2001 From: Heinrichs <Heinrichs@itc.rwth-aachen.de> Date: Tue, 14 Sep 2021 10:07:09 +0200 Subject: [PATCH] Docs + small cleanup --- README.md | 17 +++++++++++++- src/CodeGen/CodeGenerator/CodeGenerator.cs | 22 ++++++++++++------- .../CodeGenerator/CoscineCodeGenerator.cs | 7 +++++- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8ed877b..41fe953 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,18 @@ # CodeGen -This project aims to be able to generate Code from our Swagger / OpenAPI definitions. \ No newline at end of file +This project aims to be able to generate Code from our Swagger / OpenAPI definitions. + +## Build + +* .NET 5 SDK has to be installed +* `dotnet build src` + +## Usage + +* Execute the built CodeGen executable +* You should find the output client definitions in the specified output folder (default. `Output`) + +## Implementation + +An abstract `CodeGenerator` has been implemented fully as a `CoscineCodeGenerator`. +The idea is that with this abstraction someone can easily adapt and generate the code they want to produce. diff --git a/src/CodeGen/CodeGenerator/CodeGenerator.cs b/src/CodeGen/CodeGenerator/CodeGenerator.cs index 21a3017..55461b5 100644 --- a/src/CodeGen/CodeGenerator/CodeGenerator.cs +++ b/src/CodeGen/CodeGenerator/CodeGenerator.cs @@ -10,6 +10,7 @@ namespace Coscine.CodeGen.CodeGenerator { public abstract class CodeGenerator { + #region Functionality public async Task GenerateCode() { var jarFileName = await GetClientGenerator(); @@ -36,9 +37,9 @@ namespace Coscine.CodeGen.CodeGenerator foreach (var key in keys) { Console.WriteLine(key); - string swaggerUrl = await GetSwaggerUrl(domainName, hostName, key); - var command = $"java \"-Dio.swagger.parser.util.RemoteUrl.trustAll=true\" \"-Dio.swagger.v3.parser.util.RemoteUrl.trustAll=true\" -jar \"{jarFileName}\" generate -i \"{swaggerUrl}\" -g typescript-axios -o \"{outputPath}/{key}\" --skip-validate-spec"; + var swaggerUrl = await GetSwaggerUrl(domainName, hostName, key); + var command = GetGenerationCommand(outputPath, jarFileName, key, swaggerUrl); await ExecuteCommand(command); } @@ -159,17 +160,22 @@ const apis = implementations(instance); return process.WaitForExitAsync(); } } + #endregion - internal abstract Task<string> GetSwaggerUrl(string domainName, string hostName, string key); - - internal abstract Task<string> GetCustomBasePath(string directoryName); + #region Abstract Methods + public abstract Task<string> GetClientGenerator(); - internal abstract Task<string> GetCustomCodeForCombinationFile(string combinationFileText); + public abstract Task<IEnumerable<string>> GetApiNames(); internal abstract Task<string> GetOutputPath(); - public abstract Task<string> GetClientGenerator(); + internal abstract Task<string> GetSwaggerUrl(string domainName, string hostName, string key); - public abstract Task<IEnumerable<string>> GetApiNames(); + internal abstract string GetGenerationCommand(string outputPath, string jarFileName, string key, string swaggerUrl); + + internal abstract Task<string> GetCustomBasePath(string directoryName); + + internal abstract Task<string> GetCustomCodeForCombinationFile(string combinationFileText); + #endregion } } diff --git a/src/CodeGen/CodeGenerator/CoscineCodeGenerator.cs b/src/CodeGen/CodeGenerator/CoscineCodeGenerator.cs index 232cbfd..f159379 100644 --- a/src/CodeGen/CodeGenerator/CoscineCodeGenerator.cs +++ b/src/CodeGen/CodeGenerator/CoscineCodeGenerator.cs @@ -19,7 +19,6 @@ namespace Coscine.CodeGen.CodeGenerator public async override Task<string> GetClientGenerator() { var jarDownloadLink = await _configuration.GetStringAsync("coscine/local/codegen/jarlink", - //"https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.27/swagger-codegen-cli-3.0.27.jar" "https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.2.1/openapi-generator-cli-5.2.1.jar" ); @@ -43,11 +42,17 @@ namespace Coscine.CodeGen.CodeGenerator { return await _configuration.GetStringAsync("coscine/local/codegen/outputpath", "Output"); } + internal override Task<string> GetSwaggerUrl(string domainName, string hostName, string key) { return Task.FromResult($"https://{hostName}.{domainName}/coscine/api/{key}/swagger/v1/swagger.json"); } + internal override string GetGenerationCommand(string outputPath, string jarFileName, string key, string swaggerUrl) + { + return $"java \"-Dio.swagger.parser.util.RemoteUrl.trustAll=true\" \"-Dio.swagger.v3.parser.util.RemoteUrl.trustAll=true\" -jar \"{jarFileName}\" generate -i \"{swaggerUrl}\" -g typescript-axios -o \"{outputPath}/{key}\" --skip-validate-spec"; + } + internal override Task<string> GetCustomBasePath(string directoryName) { return Task.FromResult($"https://' + getHostName() + '/coscine/api/{directoryName}"); -- GitLab