Skip to content
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