Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ public IEnumerable<ODataPath> AllPaths
/// <summary>
/// Gets all tags.
/// </summary>
public ISet<OpenApiTag>? Tags { get; private set; }
public HashSet<OpenApiTag>? Tags { get; private set; }

/// <summary>
/// Append tag.
/// </summary>
/// <param name="tagItem">The tag item.</param>
internal void AppendTag(OpenApiTag tagItem)
{
Tags ??= new HashSet<OpenApiTag>();
Tags ??= [];

if (tagItem.Name is not null && FindTagByName(tagItem.Name) is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models.References;
using Microsoft.OpenApi.Models.Interfaces;
using System.Globalization;

namespace Microsoft.OpenApi.OData.Generator
{
Expand Down Expand Up @@ -127,15 +128,15 @@ public static IOpenApiSchema CreateSchema(this ODataContext context, IEdmPrimiti
// The precision is represented with the maximum and minimum keywords and a value of ±(10^ (precision - scale) - 10^ scale).
double tmp = Math.Pow(10, decimalTypeReference.Precision.Value - decimalTypeReference.Scale.Value)
- Math.Pow(10, -decimalTypeReference.Scale.Value);
openApiSchema.Minimum = (decimal?)(tmp * -1.0);
openApiSchema.Maximum = (decimal?)(tmp);
openApiSchema.Minimum = (tmp * -1.0).ToString(CultureInfo.InvariantCulture);
openApiSchema.Maximum = tmp.ToString(CultureInfo.InvariantCulture);
}
else
{
// If the scale facet has a numeric value, and ±(10^precision - 1) if the scale is variable
double tmp = Math.Pow(10, decimalTypeReference.Precision.Value) - 1;
openApiSchema.Minimum = (decimal?)(tmp * -1.0);
openApiSchema.Maximum = (decimal?)(tmp);
openApiSchema.Minimum = (tmp * -1.0).ToString(CultureInfo.InvariantCulture);
openApiSchema.Maximum = tmp.ToString(CultureInfo.InvariantCulture);
}
}

Expand Down Expand Up @@ -246,14 +247,14 @@ public static IOpenApiSchema CreateSchema(this ODataContext context, IEdmPrimiti
case EdmPrimitiveTypeKind.Int16:
schema.Type = JsonSchemaType.Number;
schema.Format = "int16";
schema.Minimum = Int16.MinValue; // -32768
schema.Maximum = Int16.MaxValue; // 32767
schema.Minimum = short.MinValue.ToString(CultureInfo.InvariantCulture); // -32768
schema.Maximum = short.MaxValue.ToString(CultureInfo.InvariantCulture); // 32767
break;
case EdmPrimitiveTypeKind.Int32:
schema.Type = JsonSchemaType.Number;
schema.Format = "int32";
schema.Minimum = Int32.MinValue; // -2147483648
schema.Maximum = Int32.MaxValue; // 2147483647
schema.Minimum = int.MinValue.ToString(CultureInfo.InvariantCulture); // -2147483648
schema.Maximum = int.MaxValue.ToString(CultureInfo.InvariantCulture); // 2147483647
break;
case EdmPrimitiveTypeKind.Int64 when emitIEEECompatibleTypes:
schema.OneOf =
Expand All @@ -269,8 +270,8 @@ public static IOpenApiSchema CreateSchema(this ODataContext context, IEdmPrimiti
case EdmPrimitiveTypeKind.SByte:
schema.Type = JsonSchemaType.Number;
schema.Format = "int8";
schema.Minimum = SByte.MinValue; // -128
schema.Maximum = SByte.MaxValue; // 127
schema.Minimum = sbyte.MinValue.ToString(CultureInfo.InvariantCulture); // -128
schema.Maximum = sbyte.MaxValue.ToString(CultureInfo.InvariantCulture); // 127
break;
case EdmPrimitiveTypeKind.String: // string
schema.Type = JsonSchemaType.String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal static class OpenApiLinkGenerator
/// <param name="parameters">"Optional: The list of parameters of the incoming operation.</param>
/// <param name="navPropOperationId">Optional: The operation id of the source of the NavigationProperty object.</param>
/// <returns>The created dictionary of <see cref="OpenApiLink"/> object.</returns>
public static IDictionary<string, IOpenApiLink> CreateLinks(this ODataContext context,
public static Dictionary<string, IOpenApiLink> CreateLinks(this ODataContext context,
IEdmEntityType entityType, string entityName, string entityKind, ODataPath path,
IList<IOpenApiParameter>? parameters = null, string? navPropOperationId = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ public static void AppendParameter(this IList<IOpenApiParameter> parameters, IOp
return null;
}

IList<JsonNode> expandItems = [ "*" ];
List<JsonNode> expandItems = [ "*" ];

foreach (var property in structuredType.NavigationProperties())
{
Expand Down Expand Up @@ -902,7 +902,7 @@ private static OpenApiParameter CreateTop(int topExample)
{
Type = JsonSchemaType.Number,
Format = "int64",
Minimum = 0,
Minimum = "0",
},
Example = topExample,
Style = ParameterStyle.Form,
Expand All @@ -922,7 +922,7 @@ private static OpenApiParameter CreateSkip()
{
Type = JsonSchemaType.Number,
Format = "int64",
Minimum = 0,
Minimum = "0",
},
Style = ParameterStyle.Form,
Explode = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,19 @@ public static OpenApiResponses CreateResponses(this ODataContext context, IEdmOp
}
else if (operation.IsDeltaFunction())
{
baseSchema.Properties.Add(ODataConstants.OdataNextLink);
baseSchema.Properties.Add(ODataConstants.OdataDeltaLink);
baseSchema.Properties.Add(ODataConstants.OdataNextLink.Key, ODataConstants.OdataNextLink.Value);
baseSchema.Properties.Add(ODataConstants.OdataDeltaLink.Key, ODataConstants.OdataDeltaLink.Value);
schema = baseSchema;
}
else
{
if (context.Settings.EnablePagination)
{
baseSchema.Properties.Add(ODataConstants.OdataNextLink);
baseSchema.Properties.Add(ODataConstants.OdataNextLink.Key, ODataConstants.OdataNextLink.Value);
}
if (context.Settings.EnableCount)
{
baseSchema.Properties.Add(ODataConstants.OdataCount);
baseSchema.Properties.Add(ODataConstants.OdataCount.Key, ODataConstants.OdataCount.Value);
}
schema = baseSchema;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@
};
document.AddComponent(Constants.BaseCollectionPaginationCountResponse, responseSchema);

responseSchema.Properties ??= new Dictionary<string, IOpenApiSchema>();
responseSchema.Properties ??= [];
if (context.Settings.EnableCount)
responseSchema.Properties.Add(ODataConstants.OdataCount);
responseSchema.Properties.Add(ODataConstants.OdataCount.Key, ODataConstants.OdataCount.Value);
if (context.Settings.EnablePagination)
responseSchema.Properties.Add(ODataConstants.OdataNextLink);
responseSchema.Properties.Add(ODataConstants.OdataNextLink.Key, ODataConstants.OdataNextLink.Value);
}

// @odata.nextLink + @odata.deltaLink
Expand Down Expand Up @@ -265,10 +265,10 @@
else
{
if (context.Settings.EnablePagination)
baseSchema.Properties.Add(ODataConstants.OdataNextLink);
baseSchema.Properties.Add(ODataConstants.OdataNextLink.Key, ODataConstants.OdataNextLink.Value);

if (context.Settings.EnableCount)
baseSchema.Properties.Add(ODataConstants.OdataCount);
baseSchema.Properties.Add(ODataConstants.OdataCount.Key, ODataConstants.OdataCount.Value);

collectionSchema = baseSchema;
}
Expand Down Expand Up @@ -420,7 +420,7 @@
/// <param name="structuredType">The Edm structured type.</param>
/// <param name="document">The Open API document to lookup references.</param>
/// <returns>The created map of <see cref="OpenApiSchema"/>.</returns>
public static IDictionary<string, IOpenApiSchema> CreateStructuredTypePropertiesSchema(this ODataContext context, IEdmStructuredType structuredType, OpenApiDocument document)
public static Dictionary<string, IOpenApiSchema> CreateStructuredTypePropertiesSchema(this ODataContext context, IEdmStructuredType structuredType, OpenApiDocument document)
{
Utils.CheckArgumentNull(context, nameof(context));
Utils.CheckArgumentNull(structuredType, nameof(structuredType));
Expand Down Expand Up @@ -545,10 +545,9 @@
OpenApiDiscriminator? discriminator = null;
if (context.Settings.EnableDiscriminatorValue && derivedTypes is not null && derivedTypes.Any())
{
Dictionary<string, string> mapping = derivedTypes
.Select(x => ($"#{x.FullTypeName()}", new OpenApiSchemaReference(x.FullTypeName(), document).Reference.ReferenceV3))
.Where(x => x.Item2 != null)
.ToDictionary(x => x.Item1, x => x.Item2!);
Dictionary<string, OpenApiSchemaReference> mapping = derivedTypes
.Select(x => ($"#{x.FullTypeName()}", new OpenApiSchemaReference(x.FullTypeName(), document)))
.ToDictionary(x => x.Item1, x => x.Item2);

discriminator = new OpenApiDiscriminator
{
Expand Down Expand Up @@ -754,7 +753,7 @@
// The type 'System.Double' is not supported in Open API document.
case EdmPrimitiveTypeKind.Double:
/*
{

Check warning on line 756 in src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this commented out code. (https://rules.sonarsource.com/csharp/RSPEC-125)
double result;
if (Double.TryParse(property.DefaultValueString, out result))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static class OpenApiServerGenerator
/// </summary>
/// <param name="context">The OData context.</param>
/// <returns>The created collection of <see cref="OpenApiServer"/> object.</returns>
public static IList<OpenApiServer> CreateServers(this ODataContext context)
public static List<OpenApiServer> CreateServers(this ODataContext context)
{
Utils.CheckArgumentNull(context, nameof(context));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal static class OpenApiTagGenerator
/// </summary>
/// <param name="context">The OData context.</param>
/// <returns>The created collection of <see cref="OpenApiTag"/> object.</returns>
public static ISet<OpenApiTag> CreateTags(this ODataContext context)
public static HashSet<OpenApiTag> CreateTags(this ODataContext context)
{
Utils.CheckArgumentNull(context, nameof(context));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.OData.Edm" Version="8.2.3" />
<PackageReference Include="Microsoft.OpenApi" Version="2.0.0-preview.15" />
<PackageReference Include="Microsoft.OpenApi" Version="2.0.0-preview.17" />
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.13.61">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected override void SetParameters(OpenApiOperation operation)
protected override void SetResponses(OpenApiOperation operation)
{
IOpenApiSchema? schema = null;
IDictionary<string, IOpenApiLink>? links = null;
Dictionary<string, IOpenApiLink>? links = null;

if (EntitySet is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected override void AppendCustomParameters(OpenApiOperation operation)
/// Get the entity content description.
/// </summary>
/// <returns>The entity content description.</returns>
private IDictionary<string, OpenApiMediaType> GetContentDescription()
private Dictionary<string, OpenApiMediaType> GetContentDescription()
{
var schema = GetEntitySchema();
var content = new Dictionary<string, OpenApiMediaType>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected override void SetRequestBody(OpenApiOperation operation)
base.SetRequestBody(operation);
}

protected IDictionary<string, OpenApiMediaType> GetContent()
protected Dictionary<string, OpenApiMediaType> GetContent()
{
var schema = GetOpenApiSchema();
var content = new Dictionary<string, OpenApiMediaType>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected string GetOperationId(string prefix, string identifier)
/// Gets a media entity content description.
/// </summary>
/// <returns>The entity content description.</returns>
protected IDictionary<string, OpenApiMediaType> GetContentDescription()
protected Dictionary<string, OpenApiMediaType> GetContentDescription()
{
// Fetch the respective AcceptableMediaTypes
(_, var property) = GetStreamElements();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected override void SetExtensions(OpenApiOperation operation)
/// <inheritdoc/>
protected override void SetResponses(OpenApiOperation operation)
{
IDictionary<string, IOpenApiLink>? links = null;
Dictionary<string, IOpenApiLink>? links = null;
if (Context is { Settings.ShowLinks: true } && NavigationProperty is not null && Path is not null)
{
var operationId = GetOperationId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected override void SetResponses(OpenApiOperation operation)
// $ref returns string for the Uri?
Type = JsonSchemaType.String
};
IDictionary<string, IOpenApiLink>? links = null;
Dictionary<string, IOpenApiLink>? links = null;
if (Context is {Settings.ShowLinks: true} && NavigationProperty is not null && Path is not null)
{
var operationId = GetOperationId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected override void SetResponses(OpenApiOperation operation)
if (Singleton is not null)
{
IOpenApiSchema? schema = null;
IDictionary<string, IOpenApiLink>? links = null;
Dictionary<string, IOpenApiLink>? links = null;

if (Context is {Settings.EnableDerivedTypesReferencesForResponses: true})
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ namespace OoasUtil
/// <summary>
/// Command line arguments processer.
/// </summary>
internal class ComLineProcesser
internal class ComLineProcessor
{
private IList<string> _args;
private bool _continue;
public static Version version = new Version(1, 0, 0, 0);

/// <summary>
/// Initializes a new instance of the <see cref="ComLineProcesser"/> class.
/// Initializes a new instance of the <see cref="ComLineProcessor"/> class.
/// </summary>
/// <param name="args">The command line arguments.</param>
public ComLineProcesser(string[] args)
public ComLineProcessor(string[] args)
{
_args = args;
}
Expand All @@ -43,7 +43,9 @@ public ComLineProcesser(string[] args)
/// <summary>
/// Output format.
/// </summary>
public OpenApiFormat? Format { get; private set; }
#nullable enable
public string? Format { get; private set; }
#nullable restore

/// <summary>
/// Whether KeyAsSegment is used.
Expand Down Expand Up @@ -145,15 +147,15 @@ public bool Process()

case "--yaml":
case "-y":
if (!ProcessTarget(OpenApiFormat.Yaml))
if (!ProcessTarget("yaml"))
{
return false;
}
break;

case "--json":
case "-j":
if (!ProcessTarget(OpenApiFormat.Json))
if (!ProcessTarget("json"))
{
return false;
}
Expand Down Expand Up @@ -240,7 +242,7 @@ public bool Process()
// by default.
if (Format == null)
{
Format = OpenApiFormat.Json;
Format = "json";
}

if (Version == null)
Expand Down Expand Up @@ -313,7 +315,7 @@ private bool ProcessOutput(string file)
return true;
}

private bool ProcessTarget(OpenApiFormat format)
private bool ProcessTarget(string format)
{
if (Format != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/OoasUtil/FileOpenApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal class FileOpenApiGenerator : OpenApiGenerator
/// <param name="output">The output.</param>
/// <param name="format">The format.</param>
/// <param name="settings">Conversion settings.</param>
public FileOpenApiGenerator(string input, string output, OpenApiFormat format, OpenApiConvertSettings settings)
public FileOpenApiGenerator(string input, string output, string format, OpenApiConvertSettings settings)
: base(output, format, settings)
{
Input = input;
Expand Down
4 changes: 2 additions & 2 deletions src/OoasUtil/OpenApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal abstract class OpenApiGenerator
/// <summary>
/// Output format.
/// </summary>
public OpenApiFormat Format { get; }
public string Format { get; }

/// <summary>
/// Output file.
Expand All @@ -42,7 +42,7 @@ internal abstract class OpenApiGenerator
/// <param name="output">The output.</param>
/// <param name="format">The output format.</param>
/// <param name="settings">Conversion settings.</param>
protected OpenApiGenerator(string output, OpenApiFormat format, OpenApiConvertSettings settings)
protected OpenApiGenerator(string output, string format, OpenApiConvertSettings settings)
{
Output = output;
Format = format;
Expand Down
Loading
Loading