From 6e4bb84f297f8441beeae0eb5c3909a54b735c1c Mon Sep 17 00:00:00 2001 From: ozippy Date: Fri, 6 Sep 2019 21:22:14 +1000 Subject: [PATCH 1/2] Added TargetOpenAPIVersion CommandOption. It will be v3 unless 2 is specified. Chyanged OpenAPIGenerator to use config.SpecVersion --- .../OData2OpenApi/Configuration.cs | 20 ++++++++++++++++++- .../OData2OpenApi/OpenApiGenerator.cs | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/OpenApi/OData2OpenApi/OData2OpenApi/Configuration.cs b/OpenApi/OData2OpenApi/OData2OpenApi/Configuration.cs index 6c6bcb7..a3afc3b 100644 --- a/OpenApi/OData2OpenApi/OData2OpenApi/Configuration.cs +++ b/OpenApi/OData2OpenApi/OData2OpenApi/Configuration.cs @@ -72,18 +72,31 @@ public class Configuration /// [CommandOption("--PrefixTypeBeforeKey=[true/false] : Enable prefix entity type name before single key.")] public bool PrefixTypeBeforeKey { get; set; } = true; -#endregion + + /// + /// Gets/set the target OpenAPI version. + /// + [CommandOption("--TargetOpenAPIVersion=[value] : Select the target API version")] + public string TargetOpenAPIVersion { get; set; } + + #endregion /// /// Gets the boolean value indicating whether the input is local file or not. /// public bool IsLocalFile { get; private set; } + /// + /// Gets the spec version to convert to format. + /// + public OpenApiSpecVersion SpecVersion { get; private set; } = OpenApiSpecVersion.OpenApi3_0; + /// /// Gets the output format. /// public OpenApiFormat Format { get; private set; } = OpenApiFormat.Json; + /// /// Validate the configuration. /// @@ -104,6 +117,11 @@ public void InitializeAndValidate() } } + if (TargetOpenAPIVersion == "2") + { + SpecVersion = OpenApiSpecVersion.OpenApi2_0; + } + if (String.IsNullOrWhiteSpace(OutputFileName)) { throw new Exception($"'--output=[value]' is required."); diff --git a/OpenApi/OData2OpenApi/OData2OpenApi/OpenApiGenerator.cs b/OpenApi/OData2OpenApi/OData2OpenApi/OpenApiGenerator.cs index 1b92ef2..12549e9 100644 --- a/OpenApi/OData2OpenApi/OData2OpenApi/OpenApiGenerator.cs +++ b/OpenApi/OData2OpenApi/OData2OpenApi/OpenApiGenerator.cs @@ -29,7 +29,7 @@ public static bool Run(Configuration config) using (FileStream fs = File.Create(config.OutputFileName)) { OpenApiDocument document = edmModel.ConvertToOpenApi(settings); - document.Serialize(fs, OpenApi.OpenApiSpecVersion.OpenApi3_0, config.Format); + document.Serialize(fs, config.SpecVersion, config.Format); fs.Flush(); } From 569a7aed06a9246829eabab0187c13bbeafea26b Mon Sep 17 00:00:00 2001 From: ozippy Date: Fri, 6 Sep 2019 21:39:26 +1000 Subject: [PATCH 2/2] Added the options to the description of the command option --- OpenApi/OData2OpenApi/OData2OpenApi/Configuration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenApi/OData2OpenApi/OData2OpenApi/Configuration.cs b/OpenApi/OData2OpenApi/OData2OpenApi/Configuration.cs index a3afc3b..766a612 100644 --- a/OpenApi/OData2OpenApi/OData2OpenApi/Configuration.cs +++ b/OpenApi/OData2OpenApi/OData2OpenApi/Configuration.cs @@ -76,7 +76,7 @@ public class Configuration /// /// Gets/set the target OpenAPI version. /// - [CommandOption("--TargetOpenAPIVersion=[value] : Select the target API version")] + [CommandOption("--TargetOpenAPIVersion=[value] : Select the target API version (2 or 3)")] public string TargetOpenAPIVersion { get; set; } #endregion