diff --git a/OpenApi/OData2OpenApi/OData2OpenApi/Configuration.cs b/OpenApi/OData2OpenApi/OData2OpenApi/Configuration.cs index 6c6bcb7..766a612 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 (2 or 3)")] + 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(); }