Skip to content

Commit 6e38b40

Browse files
committed
feat: upgrades to OAI.net preview17
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
1 parent 70a0604 commit 6e38b40

File tree

51 files changed

+260
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+260
-228
lines changed

src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ public IEnumerable<ODataPath> AllPaths
136136
/// <summary>
137137
/// Gets all tags.
138138
/// </summary>
139-
public ISet<OpenApiTag>? Tags { get; private set; }
139+
public HashSet<OpenApiTag>? Tags { get; private set; }
140140

141141
/// <summary>
142142
/// Append tag.
143143
/// </summary>
144144
/// <param name="tagItem">The tag item.</param>
145145
internal void AppendTag(OpenApiTag tagItem)
146146
{
147-
Tags ??= new HashSet<OpenApiTag>();
147+
Tags ??= [];
148148

149149
if (tagItem.Name is not null && FindTagByName(tagItem.Name) is not null)
150150
{

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiEdmTypeSchemaGenerator.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.OpenApi.Extensions;
1616
using Microsoft.OpenApi.Models.References;
1717
using Microsoft.OpenApi.Models.Interfaces;
18+
using System.Globalization;
1819

1920
namespace Microsoft.OpenApi.OData.Generator
2021
{
@@ -127,15 +128,15 @@ public static IOpenApiSchema CreateSchema(this ODataContext context, IEdmPrimiti
127128
// The precision is represented with the maximum and minimum keywords and a value of ±(10^ (precision - scale) - 10^ scale).
128129
double tmp = Math.Pow(10, decimalTypeReference.Precision.Value - decimalTypeReference.Scale.Value)
129130
- Math.Pow(10, -decimalTypeReference.Scale.Value);
130-
openApiSchema.Minimum = (decimal?)(tmp * -1.0);
131-
openApiSchema.Maximum = (decimal?)(tmp);
131+
openApiSchema.Minimum = (tmp * -1.0).ToString(CultureInfo.InvariantCulture);
132+
openApiSchema.Maximum = tmp.ToString(CultureInfo.InvariantCulture);
132133
}
133134
else
134135
{
135136
// If the scale facet has a numeric value, and ±(10^precision - 1) if the scale is variable
136137
double tmp = Math.Pow(10, decimalTypeReference.Precision.Value) - 1;
137-
openApiSchema.Minimum = (decimal?)(tmp * -1.0);
138-
openApiSchema.Maximum = (decimal?)(tmp);
138+
openApiSchema.Minimum = (tmp * -1.0).ToString(CultureInfo.InvariantCulture);
139+
openApiSchema.Maximum = tmp.ToString(CultureInfo.InvariantCulture);
139140
}
140141
}
141142

@@ -246,14 +247,14 @@ public static IOpenApiSchema CreateSchema(this ODataContext context, IEdmPrimiti
246247
case EdmPrimitiveTypeKind.Int16:
247248
schema.Type = JsonSchemaType.Number;
248249
schema.Format = "int16";
249-
schema.Minimum = Int16.MinValue; // -32768
250-
schema.Maximum = Int16.MaxValue; // 32767
250+
schema.Minimum = short.MinValue.ToString(CultureInfo.InvariantCulture); // -32768
251+
schema.Maximum = short.MaxValue.ToString(CultureInfo.InvariantCulture); // 32767
251252
break;
252253
case EdmPrimitiveTypeKind.Int32:
253254
schema.Type = JsonSchemaType.Number;
254255
schema.Format = "int32";
255-
schema.Minimum = Int32.MinValue; // -2147483648
256-
schema.Maximum = Int32.MaxValue; // 2147483647
256+
schema.Minimum = int.MinValue.ToString(CultureInfo.InvariantCulture); // -2147483648
257+
schema.Maximum = int.MaxValue.ToString(CultureInfo.InvariantCulture); // 2147483647
257258
break;
258259
case EdmPrimitiveTypeKind.Int64 when emitIEEECompatibleTypes:
259260
schema.OneOf =
@@ -269,8 +270,8 @@ public static IOpenApiSchema CreateSchema(this ODataContext context, IEdmPrimiti
269270
case EdmPrimitiveTypeKind.SByte:
270271
schema.Type = JsonSchemaType.Number;
271272
schema.Format = "int8";
272-
schema.Minimum = SByte.MinValue; // -128
273-
schema.Maximum = SByte.MaxValue; // 127
273+
schema.Minimum = sbyte.MinValue.ToString(CultureInfo.InvariantCulture); // -128
274+
schema.Maximum = sbyte.MaxValue.ToString(CultureInfo.InvariantCulture); // 127
274275
break;
275276
case EdmPrimitiveTypeKind.String: // string
276277
schema.Type = JsonSchemaType.String;

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiLinkGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal static class OpenApiLinkGenerator
3030
/// <param name="parameters">"Optional: The list of parameters of the incoming operation.</param>
3131
/// <param name="navPropOperationId">Optional: The operation id of the source of the NavigationProperty object.</param>
3232
/// <returns>The created dictionary of <see cref="OpenApiLink"/> object.</returns>
33-
public static IDictionary<string, IOpenApiLink> CreateLinks(this ODataContext context,
33+
public static Dictionary<string, IOpenApiLink> CreateLinks(this ODataContext context,
3434
IEdmEntityType entityType, string entityName, string entityKind, ODataPath path,
3535
IList<IOpenApiParameter>? parameters = null, string? navPropOperationId = null)
3636
{

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiParameterGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ public static void AppendParameter(this IList<IOpenApiParameter> parameters, IOp
858858
return null;
859859
}
860860

861-
IList<JsonNode> expandItems = [ "*" ];
861+
List<JsonNode> expandItems = [ "*" ];
862862

863863
foreach (var property in structuredType.NavigationProperties())
864864
{
@@ -902,7 +902,7 @@ private static OpenApiParameter CreateTop(int topExample)
902902
{
903903
Type = JsonSchemaType.Number,
904904
Format = "int64",
905-
Minimum = 0,
905+
Minimum = "0",
906906
},
907907
Example = topExample,
908908
Style = ParameterStyle.Form,
@@ -922,7 +922,7 @@ private static OpenApiParameter CreateSkip()
922922
{
923923
Type = JsonSchemaType.Number,
924924
Format = "int64",
925-
Minimum = 0,
925+
Minimum = "0",
926926
},
927927
Style = ParameterStyle.Form,
928928
Explode = false

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiResponseGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,19 @@ public static OpenApiResponses CreateResponses(this ODataContext context, IEdmOp
187187
}
188188
else if (operation.IsDeltaFunction())
189189
{
190-
baseSchema.Properties.Add(ODataConstants.OdataNextLink);
191-
baseSchema.Properties.Add(ODataConstants.OdataDeltaLink);
190+
baseSchema.Properties.Add(ODataConstants.OdataNextLink.Key, ODataConstants.OdataNextLink.Value);
191+
baseSchema.Properties.Add(ODataConstants.OdataDeltaLink.Key, ODataConstants.OdataDeltaLink.Value);
192192
schema = baseSchema;
193193
}
194194
else
195195
{
196196
if (context.Settings.EnablePagination)
197197
{
198-
baseSchema.Properties.Add(ODataConstants.OdataNextLink);
198+
baseSchema.Properties.Add(ODataConstants.OdataNextLink.Key, ODataConstants.OdataNextLink.Value);
199199
}
200200
if (context.Settings.EnableCount)
201201
{
202-
baseSchema.Properties.Add(ODataConstants.OdataCount);
202+
baseSchema.Properties.Add(ODataConstants.OdataCount.Key, ODataConstants.OdataCount.Value);
203203
}
204204
schema = baseSchema;
205205
}

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ public static void AddSchemasToDocument(this ODataContext context, OpenApiDocume
106106
};
107107
document.AddComponent(Constants.BaseCollectionPaginationCountResponse, responseSchema);
108108

109-
responseSchema.Properties ??= new Dictionary<string, IOpenApiSchema>();
109+
responseSchema.Properties ??= [];
110110
if (context.Settings.EnableCount)
111-
responseSchema.Properties.Add(ODataConstants.OdataCount);
111+
responseSchema.Properties.Add(ODataConstants.OdataCount.Key, ODataConstants.OdataCount.Value);
112112
if (context.Settings.EnablePagination)
113-
responseSchema.Properties.Add(ODataConstants.OdataNextLink);
113+
responseSchema.Properties.Add(ODataConstants.OdataNextLink.Key, ODataConstants.OdataNextLink.Value);
114114
}
115115

116116
// @odata.nextLink + @odata.deltaLink
@@ -265,10 +265,10 @@ private static OpenApiSchema CreateCollectionSchema(ODataContext context, IOpenA
265265
else
266266
{
267267
if (context.Settings.EnablePagination)
268-
baseSchema.Properties.Add(ODataConstants.OdataNextLink);
268+
baseSchema.Properties.Add(ODataConstants.OdataNextLink.Key, ODataConstants.OdataNextLink.Value);
269269

270270
if (context.Settings.EnableCount)
271-
baseSchema.Properties.Add(ODataConstants.OdataCount);
271+
baseSchema.Properties.Add(ODataConstants.OdataCount.Key, ODataConstants.OdataCount.Value);
272272

273273
collectionSchema = baseSchema;
274274
}
@@ -420,7 +420,7 @@ public static IOpenApiSchema CreatePropertySchema(this ODataContext context, IEd
420420
/// <param name="structuredType">The Edm structured type.</param>
421421
/// <param name="document">The Open API document to lookup references.</param>
422422
/// <returns>The created map of <see cref="OpenApiSchema"/>.</returns>
423-
public static IDictionary<string, IOpenApiSchema> CreateStructuredTypePropertiesSchema(this ODataContext context, IEdmStructuredType structuredType, OpenApiDocument document)
423+
public static Dictionary<string, IOpenApiSchema> CreateStructuredTypePropertiesSchema(this ODataContext context, IEdmStructuredType structuredType, OpenApiDocument document)
424424
{
425425
Utils.CheckArgumentNull(context, nameof(context));
426426
Utils.CheckArgumentNull(structuredType, nameof(structuredType));
@@ -545,10 +545,9 @@ private static OpenApiSchema CreateStructuredTypeSchema(this ODataContext contex
545545
OpenApiDiscriminator? discriminator = null;
546546
if (context.Settings.EnableDiscriminatorValue && derivedTypes is not null && derivedTypes.Any())
547547
{
548-
Dictionary<string, string> mapping = derivedTypes
549-
.Select(x => ($"#{x.FullTypeName()}", new OpenApiSchemaReference(x.FullTypeName(), document).Reference.ReferenceV3))
550-
.Where(x => x.Item2 != null)
551-
.ToDictionary(x => x.Item1, x => x.Item2!);
548+
Dictionary<string, OpenApiSchemaReference> mapping = derivedTypes
549+
.Select(x => ($"#{x.FullTypeName()}", new OpenApiSchemaReference(x.FullTypeName(), document)))
550+
.ToDictionary(x => x.Item1, x => x.Item2);
552551

553552
discriminator = new OpenApiDiscriminator
554553
{

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiServerGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal static class OpenApiServerGenerator
2020
/// </summary>
2121
/// <param name="context">The OData context.</param>
2222
/// <returns>The created collection of <see cref="OpenApiServer"/> object.</returns>
23-
public static IList<OpenApiServer> CreateServers(this ODataContext context)
23+
public static List<OpenApiServer> CreateServers(this ODataContext context)
2424
{
2525
Utils.CheckArgumentNull(context, nameof(context));
2626

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiTagGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal static class OpenApiTagGenerator
2222
/// </summary>
2323
/// <param name="context">The OData context.</param>
2424
/// <returns>The created collection of <see cref="OpenApiTag"/> object.</returns>
25-
public static ISet<OpenApiTag> CreateTags(this ODataContext context)
25+
public static HashSet<OpenApiTag> CreateTags(this ODataContext context)
2626
{
2727
Utils.CheckArgumentNull(context, nameof(context));
2828

src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3131
</PackageReference>
3232
<PackageReference Include="Microsoft.OData.Edm" Version="8.2.3" />
33-
<PackageReference Include="Microsoft.OpenApi" Version="2.0.0-preview.15" />
33+
<PackageReference Include="Microsoft.OpenApi" Version="2.0.0-preview.17" />
3434
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
3535
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.13.61">
3636
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/Microsoft.OpenApi.OData.Reader/Operation/EntityGetOperationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected override void SetParameters(OpenApiOperation operation)
106106
protected override void SetResponses(OpenApiOperation operation)
107107
{
108108
IOpenApiSchema? schema = null;
109-
IDictionary<string, IOpenApiLink>? links = null;
109+
Dictionary<string, IOpenApiLink>? links = null;
110110

111111
if (EntitySet is not null)
112112
{

src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetPostOperationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected override void AppendCustomParameters(OpenApiOperation operation)
136136
/// Get the entity content description.
137137
/// </summary>
138138
/// <returns>The entity content description.</returns>
139-
private IDictionary<string, OpenApiMediaType> GetContentDescription()
139+
private Dictionary<string, OpenApiMediaType> GetContentDescription()
140140
{
141141
var schema = GetEntitySchema();
142142
var content = new Dictionary<string, OpenApiMediaType>();

src/Microsoft.OpenApi.OData.Reader/Operation/EntityUpdateOperationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected override void SetRequestBody(OpenApiOperation operation)
8888
base.SetRequestBody(operation);
8989
}
9090

91-
protected IDictionary<string, OpenApiMediaType> GetContent()
91+
protected Dictionary<string, OpenApiMediaType> GetContent()
9292
{
9393
var schema = GetOpenApiSchema();
9494
var content = new Dictionary<string, OpenApiMediaType>();

src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityOperationalHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ protected string GetOperationId(string prefix, string identifier)
166166
/// Gets a media entity content description.
167167
/// </summary>
168168
/// <returns>The entity content description.</returns>
169-
protected IDictionary<string, OpenApiMediaType> GetContentDescription()
169+
protected Dictionary<string, OpenApiMediaType> GetContentDescription()
170170
{
171171
// Fetch the respective AcceptableMediaTypes
172172
(_, var property) = GetStreamElements();

src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyGetOperationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected override void SetExtensions(OpenApiOperation operation)
9292
/// <inheritdoc/>
9393
protected override void SetResponses(OpenApiOperation operation)
9494
{
95-
IDictionary<string, IOpenApiLink>? links = null;
95+
Dictionary<string, IOpenApiLink>? links = null;
9696
if (Context is { Settings.ShowLinks: true } && NavigationProperty is not null && Path is not null)
9797
{
9898
var operationId = GetOperationId();

src/Microsoft.OpenApi.OData.Reader/Operation/RefGetOperationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected override void SetResponses(OpenApiOperation operation)
103103
// $ref returns string for the Uri?
104104
Type = JsonSchemaType.String
105105
};
106-
IDictionary<string, IOpenApiLink>? links = null;
106+
Dictionary<string, IOpenApiLink>? links = null;
107107
if (Context is {Settings.ShowLinks: true} && NavigationProperty is not null && Path is not null)
108108
{
109109
var operationId = GetOperationId();

src/Microsoft.OpenApi.OData.Reader/Operation/SingletonGetOperationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected override void SetResponses(OpenApiOperation operation)
9797
if (Singleton is not null)
9898
{
9999
IOpenApiSchema? schema = null;
100-
IDictionary<string, IOpenApiLink>? links = null;
100+
Dictionary<string, IOpenApiLink>? links = null;
101101

102102
if (Context is {Settings.EnableDerivedTypesReferencesForResponses: true})
103103
{

src/OoasUtil/ComLineProcesser.cs renamed to src/OoasUtil/ComLineProcessor.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ namespace OoasUtil
1515
/// <summary>
1616
/// Command line arguments processer.
1717
/// </summary>
18-
internal class ComLineProcesser
18+
internal class ComLineProcessor
1919
{
2020
private IList<string> _args;
2121
private bool _continue;
2222
public static Version version = new Version(1, 0, 0, 0);
2323

2424
/// <summary>
25-
/// Initializes a new instance of the <see cref="ComLineProcesser"/> class.
25+
/// Initializes a new instance of the <see cref="ComLineProcessor"/> class.
2626
/// </summary>
2727
/// <param name="args">The command line arguments.</param>
28-
public ComLineProcesser(string[] args)
28+
public ComLineProcessor(string[] args)
2929
{
3030
_args = args;
3131
}
@@ -43,7 +43,9 @@ public ComLineProcesser(string[] args)
4343
/// <summary>
4444
/// Output format.
4545
/// </summary>
46-
public OpenApiFormat? Format { get; private set; }
46+
#nullable enable
47+
public string? Format { get; private set; }
48+
#nullable restore
4749

4850
/// <summary>
4951
/// Whether KeyAsSegment is used.
@@ -145,15 +147,15 @@ public bool Process()
145147

146148
case "--yaml":
147149
case "-y":
148-
if (!ProcessTarget(OpenApiFormat.Yaml))
150+
if (!ProcessTarget("yaml"))
149151
{
150152
return false;
151153
}
152154
break;
153155

154156
case "--json":
155157
case "-j":
156-
if (!ProcessTarget(OpenApiFormat.Json))
158+
if (!ProcessTarget("json"))
157159
{
158160
return false;
159161
}
@@ -240,7 +242,7 @@ public bool Process()
240242
// by default.
241243
if (Format == null)
242244
{
243-
Format = OpenApiFormat.Json;
245+
Format = "json";
244246
}
245247

246248
if (Version == null)
@@ -313,7 +315,7 @@ private bool ProcessOutput(string file)
313315
return true;
314316
}
315317

316-
private bool ProcessTarget(OpenApiFormat format)
318+
private bool ProcessTarget(string format)
317319
{
318320
if (Format != null)
319321
{

src/OoasUtil/FileOpenApiGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal class FileOpenApiGenerator : OpenApiGenerator
3535
/// <param name="output">The output.</param>
3636
/// <param name="format">The format.</param>
3737
/// <param name="settings">Conversion settings.</param>
38-
public FileOpenApiGenerator(string input, string output, OpenApiFormat format, OpenApiConvertSettings settings)
38+
public FileOpenApiGenerator(string input, string output, string format, OpenApiConvertSettings settings)
3939
: base(output, format, settings)
4040
{
4141
Input = input;

src/OoasUtil/OpenApiGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal abstract class OpenApiGenerator
2424
/// <summary>
2525
/// Output format.
2626
/// </summary>
27-
public OpenApiFormat Format { get; }
27+
public string Format { get; }
2828

2929
/// <summary>
3030
/// Output file.
@@ -42,7 +42,7 @@ internal abstract class OpenApiGenerator
4242
/// <param name="output">The output.</param>
4343
/// <param name="format">The output format.</param>
4444
/// <param name="settings">Conversion settings.</param>
45-
protected OpenApiGenerator(string output, OpenApiFormat format, OpenApiConvertSettings settings)
45+
protected OpenApiGenerator(string output, string format, OpenApiConvertSettings settings)
4646
{
4747
Output = output;
4848
Format = format;

0 commit comments

Comments
 (0)