Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added TargetOpenAPIVersion CommandOption. #98

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion OpenApi/OData2OpenApi/OData2OpenApi/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,31 @@ public class Configuration
/// </summary>
[CommandOption("--PrefixTypeBeforeKey=[true/false] : Enable prefix entity type name before single key.")]
public bool PrefixTypeBeforeKey { get; set; } = true;
#endregion

/// <summary>
/// Gets/set the target OpenAPI version.
/// </summary>
[CommandOption("--TargetOpenAPIVersion=[value] : Select the target API version (2 or 3)")]
public string TargetOpenAPIVersion { get; set; }

#endregion

/// <summary>
/// Gets the boolean value indicating whether the input is local file or not.
/// </summary>
public bool IsLocalFile { get; private set; }

/// <summary>
/// Gets the spec version to convert to format.
/// </summary>
public OpenApiSpecVersion SpecVersion { get; private set; } = OpenApiSpecVersion.OpenApi3_0;

/// <summary>
/// Gets the output format.
/// </summary>
public OpenApiFormat Format { get; private set; } = OpenApiFormat.Json;


/// <summary>
/// Validate the configuration.
/// </summary>
Expand All @@ -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.");
Expand Down
2 changes: 1 addition & 1 deletion OpenApi/OData2OpenApi/OData2OpenApi/OpenApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down