Skip to content

Commit dcdbe18

Browse files
committed
Merge branch 'main' into fix/security-reports
2 parents 7b1a240 + bb9f706 commit dcdbe18

24 files changed

+363
-100
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "2.0.0-preview.16"
2+
".": "2.0.0-preview.17"
33
}

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# Changelog
22

3+
## [2.0.0-preview.17](https://github.com/microsoft/OpenAPI.NET/compare/v2.0.0-preview.16...v2.0.0-preview.17) (2025-04-16)
4+
5+
6+
### Features
7+
8+
* discriminator mappings now use schema references ([b4877f6](https://github.com/microsoft/OpenAPI.NET/commit/b4877f674ad1a240a367390d40d122eebccc0b20))
9+
* openapiformat enum cleanup ([#2326](https://github.com/microsoft/OpenAPI.NET/issues/2326)) ([19ffd13](https://github.com/microsoft/OpenAPI.NET/commit/19ffd136a7d2137f3de0896148d9a39f469ac711))
10+
* Remove default collection initialization for perf reasons ([#2284](https://github.com/microsoft/OpenAPI.NET/issues/2284)) ([3604382](https://github.com/microsoft/OpenAPI.NET/commit/36043829d29340a47fc93c6477a38ea93e59ef57))
11+
12+
13+
### Bug Fixes
14+
15+
* Empty tag causes error generating Kiota client [#2283](https://github.com/microsoft/OpenAPI.NET/issues/2283) ([#2286](https://github.com/microsoft/OpenAPI.NET/issues/2286)) ([521d636](https://github.com/microsoft/OpenAPI.NET/commit/521d636e2c437c25e1758e9f6a22793d74adf2d7))
16+
* hidi fails to parse yaml files when fixing references ([a5c4d61](https://github.com/microsoft/OpenAPI.NET/commit/a5c4d6109c433b949cdb1665c00ad778b82b28b0))
17+
* hidi fails to parse yaml files when fixing references ([c5b69fe](https://github.com/microsoft/OpenAPI.NET/commit/c5b69fed9c413a6399c36e0f543e1019faac77e6))
18+
* Improve handling of OpenAPI tag references ([#2325](https://github.com/microsoft/OpenAPI.NET/issues/2325)) ([bf9954a](https://github.com/microsoft/OpenAPI.NET/commit/bf9954a257691231fac6f56667bde208a98a5b42))
19+
* read (Exclusive)Maximum and (Exclusive)Minimum values as strings and write their raw values during serialization ([#2309](https://github.com/microsoft/OpenAPI.NET/issues/2309)) ([ac66756](https://github.com/microsoft/OpenAPI.NET/commit/ac667560a951bef2824851c208c55ba070e96163))
20+
* relative references in subdirectory documents are not loading [#1674](https://github.com/microsoft/OpenAPI.NET/issues/1674) ([#2243](https://github.com/microsoft/OpenAPI.NET/issues/2243)) ([4bcbd51](https://github.com/microsoft/OpenAPI.NET/commit/4bcbd51caff689a73e90efbc08f683383741e004))
21+
* renames annotations schema property to metadata to match [#2241](https://github.com/microsoft/OpenAPI.NET/issues/2241) ([28e4a75](https://github.com/microsoft/OpenAPI.NET/commit/28e4a7590fb3525e30970112191d72eaf048ad6b))
22+
* renames annotations schema property to metadata to match [#2241](https://github.com/microsoft/OpenAPI.NET/issues/2241) ([33fc7cb](https://github.com/microsoft/OpenAPI.NET/commit/33fc7cbcda71efea47070ab7a6ebf9db8787a7f8))
23+
* set format to binary for file uploads ([#2305](https://github.com/microsoft/OpenAPI.NET/issues/2305)) ([47f10d3](https://github.com/microsoft/OpenAPI.NET/commit/47f10d323e78b9e6caa757c0d2efa378a19fc28c))
24+
325
## [2.0.0-preview.16](https://github.com/microsoft/OpenAPI.NET/compare/v2.0.0-preview.15...v2.0.0-preview.16) (2025-03-20)
426

527

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<PackageProjectUrl>https://github.com/Microsoft/OpenAPI.NET</PackageProjectUrl>
1313
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1414
<PackageTags>OpenAPI .NET</PackageTags>
15-
<Version>2.0.0-preview.16</Version>
15+
<Version>2.0.0-preview.17</Version>
1616
</PropertyGroup>
1717
<!-- https://github.com/clairernovotny/DeterministicBuilds#deterministic-builds -->
1818
<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ var stream = await httpClient.GetStreamAsync("main/examples/v3.0/petstore.yaml")
8888
var openApiDocument = new OpenApiStreamReader().Read(stream, out var diagnostic);
8989

9090
// Write V2 as JSON
91-
var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json);
91+
var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Json);
9292

9393
```
9494

docs/upgrade-guide-2.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,24 @@ The `SerializeAs()` method simplifies serialization scenarios, making it easier
487487

488488
```csharp
489489
OpenApiDocument document = new OpenApiDocument();
490-
string json = document.SerializeAs(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Json);
490+
string json = document.SerializeAs(OpenApiSpecVersion.OpenApi3_0, OpenApiConstants.Json);
491491

492492
```
493493

494+
### Use OpenApiConstants string Instead of OpenApiFormat Enum
495+
496+
OpenApiConstants are now used instead of OpenApiFormat enums.
497+
498+
**Example:**
499+
500+
```csharp
501+
// Before (1.6)
502+
var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json);
503+
504+
// After (2.0)
505+
var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Json);
506+
```
507+
494508
### Bug Fixes
495509

496510
## Serialization of References

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
5555
if (options.Output == null)
5656
{
5757
#pragma warning disable CA1308 // Normalize strings to uppercase
58-
var extension = options.OpenApiFormat?.GetDisplayName().ToLowerInvariant();
58+
var extension = options.OpenApiFormat?.ToLowerInvariant();
5959
var inputExtension = !string.IsNullOrEmpty(extension) ? string.Concat(".", extension)
6060
: GetInputPathExtension(options.OpenApi, options.Csdl);
6161

@@ -73,7 +73,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
7373
}
7474

7575
// Default to yaml and OpenApiVersion 3_1 during csdl to OpenApi conversion
76-
var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiFormat.Yaml);
76+
var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiConstants.Yaml);
7777
var openApiVersion = options.Version != null ? TryParseOpenApiSpecVersion(options.Version) : OpenApiSpecVersion.OpenApi3_1;
7878

7979
// If ApiManifest is provided, set the referenced OpenAPI document
@@ -92,7 +92,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
9292
}
9393

9494
// Load OpenAPI document
95-
var document = await GetOpenApiAsync(options, openApiFormat.GetDisplayName(), logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false);
95+
var document = await GetOpenApiAsync(options, openApiFormat, logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false);
9696

9797
if (options.FilterOptions != null && document is not null)
9898
{
@@ -189,7 +189,7 @@ private static OpenApiDocument ApplyFilters(HidiOptions options, ILogger logger,
189189
return document;
190190
}
191191

192-
private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument document, ILogger logger, CancellationToken cancellationToken)
192+
private static async Task WriteOpenApiAsync(HidiOptions options, string openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument document, ILogger logger, CancellationToken cancellationToken)
193193
{
194194
using (logger.BeginScope("Output"))
195195
{
@@ -202,11 +202,12 @@ private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat o
202202
InlineLocalReferences = options.InlineLocal,
203203
InlineExternalReferences = options.InlineExternal
204204
};
205-
206-
IOpenApiWriter writer = openApiFormat switch
205+
#pragma warning disable CA1308
206+
IOpenApiWriter writer = openApiFormat.ToLowerInvariant() switch
207+
#pragma warning restore CA1308
207208
{
208-
OpenApiFormat.Json => options.TerseOutput ? new(textWriter, settings, options.TerseOutput) : new OpenApiJsonWriter(textWriter, settings, false),
209-
OpenApiFormat.Yaml => new OpenApiYamlWriter(textWriter, settings),
209+
OpenApiConstants.Json => options.TerseOutput ? new(textWriter, settings, options.TerseOutput) : new OpenApiJsonWriter(textWriter, settings, false),
210+
OpenApiConstants.Yaml => new OpenApiYamlWriter(textWriter, settings),
210211
_ => throw new ArgumentException("Unknown format"),
211212
};
212213

@@ -560,10 +561,10 @@ SecurityException or
560561
/// <param name="input"></param>
561562
/// <param name="logger"></param>
562563
/// <returns></returns>
563-
private static OpenApiFormat GetOpenApiFormat(string input, ILogger logger)
564+
private static string GetOpenApiFormat(string input, ILogger logger)
564565
{
565566
logger.LogTrace("Getting the OpenApi format");
566-
return !input.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Path.GetExtension(input) == ".json" ? OpenApiFormat.Json : OpenApiFormat.Yaml;
567+
return !input.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Path.GetExtension(input) == ".json" ? OpenApiConstants.Json : OpenApiConstants.Yaml;
567568
}
568569

569570
private static string GetInputPathExtension(string? openapi = null, string? csdl = null)
@@ -590,8 +591,8 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
590591
throw new ArgumentException("Please input a file path or URL");
591592
}
592593

593-
var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiFormat.Yaml);
594-
var document = await GetOpenApiAsync(options, openApiFormat.GetDisplayName(), logger, null, cancellationToken).ConfigureAwait(false);
594+
var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiConstants.Yaml);
595+
var document = await GetOpenApiAsync(options, openApiFormat, logger, null, cancellationToken).ConfigureAwait(false);
595596
if (document is not null)
596597
{
597598
using (logger.BeginScope("Creating diagram"))
@@ -754,10 +755,10 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
754755
}
755756

756757
var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi)
757-
? GetOpenApiFormat(options.OpenApi, logger) : OpenApiFormat.Yaml);
758+
? GetOpenApiFormat(options.OpenApi, logger) : OpenApiConstants.Yaml);
758759

759760
// Load OpenAPI document
760-
var document = await GetOpenApiAsync(options, openApiFormat.GetDisplayName(), logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false);
761+
var document = await GetOpenApiAsync(options, openApiFormat, logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false);
761762

762763
cancellationToken.ThrowIfCancellationRequested();
763764

@@ -777,7 +778,7 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
777778
options.TerseOutput = true;
778779
if (document is not null)
779780
{
780-
await WriteOpenApiAsync(options, OpenApiFormat.Json, OpenApiSpecVersion.OpenApi3_1, document, logger, cancellationToken).ConfigureAwait(false);
781+
await WriteOpenApiAsync(options, OpenApiConstants.Json, OpenApiSpecVersion.OpenApi3_1, document, logger, cancellationToken).ConfigureAwait(false);
781782

782783
// Create OpenAIPluginManifest from ApiDependency and OpenAPI document
783784
var manifest = new OpenAIPluginManifest(document.Info.Title ?? "Title",

src/Microsoft.OpenApi.Hidi/Options/CommandOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal class CommandOptions
1616
public readonly Option<bool> CleanOutputOption = new("--clean-output", "Overwrite an existing file");
1717
public readonly Option<string> VersionOption = new("--version", "OpenAPI specification version");
1818
public readonly Option<string> MetadataVersionOption = new("--metadata-version", "Graph metadata version to use.");
19-
public readonly Option<OpenApiFormat?> FormatOption = new("--format", "File format");
19+
public readonly Option<string> FormatOption = new("--format", "File format");
2020
public readonly Option<bool> TerseOutputOption = new("--terse-output", "Produce terse json output");
2121
public readonly Option<string> SettingsFileOption = new("--settings-path", "The configuration file with CSDL conversion settings.");
2222
public readonly Option<LogLevel> LogLevelOption = new("--log-level", () => LogLevel.Information, "The log level to use when logging messages to the main output.");

src/Microsoft.OpenApi.Hidi/Options/HidiOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal class HidiOptions
2020
public bool CleanOutput { get; set; }
2121
public string? Version { get; set; }
2222
public string? MetadataVersion { get; set; }
23-
public OpenApiFormat? OpenApiFormat { get; set; }
23+
public string? OpenApiFormat { get; set; }
2424
public bool TerseOutput { get; set; }
2525
public IConfiguration? SettingsConfig { get; set; }
2626
public LogLevel LogLevel { get; set; }

src/Microsoft.OpenApi.Workbench/MainModel.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System;
@@ -43,7 +43,7 @@ public class MainModel : INotifyPropertyChanged
4343
/// <summary>
4444
/// Default format.
4545
/// </summary>
46-
private OpenApiFormat _format = OpenApiFormat.Yaml;
46+
private string _format = OpenApiConstants.Yaml;
4747

4848
/// <summary>
4949
/// Default version.
@@ -121,7 +121,7 @@ public string RenderTime
121121
}
122122
}
123123

124-
public OpenApiFormat Format
124+
public string Format
125125
{
126126
get => _format;
127127
set
@@ -166,14 +166,14 @@ public OpenApiSpecVersion Version
166166

167167
public bool IsYaml
168168
{
169-
get => Format == OpenApiFormat.Yaml;
170-
set => Format = value ? OpenApiFormat.Yaml : Format;
169+
get => Format == OpenApiConstants.Yaml;
170+
set => Format = value ? OpenApiConstants.Yaml : Format;
171171
}
172172

173173
public bool IsJson
174174
{
175-
get => Format == OpenApiFormat.Json;
176-
set => Format = value ? OpenApiFormat.Json : Format;
175+
get => Format == OpenApiConstants.Json;
176+
set => Format = value ? OpenApiConstants.Json : Format;
177177
}
178178

179179
public bool IsV2_0
@@ -243,7 +243,7 @@ internal async Task ParseDocumentAsync()
243243
: new("file://" + Path.GetDirectoryName(_inputFile) + "/");
244244
}
245245

246-
var readResult = await OpenApiDocument.LoadAsync(stream, Format.GetDisplayName().ToLowerInvariant(), settings);
246+
var readResult = await OpenApiDocument.LoadAsync(stream, Format.ToLowerInvariant(), settings);
247247
var document = readResult.Document;
248248
var context = readResult.Diagnostic;
249249

src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Threading.Tasks;
88
using Microsoft.OpenApi.Exceptions;
99
using Microsoft.OpenApi.Interfaces;
10+
using Microsoft.OpenApi.Models;
1011
using Microsoft.OpenApi.Properties;
1112
using Microsoft.OpenApi.Writers;
1213

@@ -28,7 +29,7 @@ public static class OpenApiSerializableExtensions
2829
public static Task SerializeAsJsonAsync<T>(this T element, Stream stream, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default)
2930
where T : IOpenApiSerializable
3031
{
31-
return element.SerializeAsync(stream, specVersion, OpenApiFormat.Json, cancellationToken);
32+
return element.SerializeAsync(stream, specVersion, OpenApiConstants.Json, cancellationToken);
3233
}
3334

3435
/// <summary>
@@ -42,7 +43,7 @@ public static Task SerializeAsJsonAsync<T>(this T element, Stream stream, OpenAp
4243
public static Task SerializeAsYamlAsync<T>(this T element, Stream stream, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default)
4344
where T : IOpenApiSerializable
4445
{
45-
return element.SerializeAsync(stream, specVersion, OpenApiFormat.Yaml, cancellationToken);
46+
return element.SerializeAsync(stream, specVersion, OpenApiConstants.Yaml, cancellationToken);
4647
}
4748

4849
/// <summary>
@@ -59,7 +60,7 @@ public static Task SerializeAsync<T>(
5960
this T element,
6061
Stream stream,
6162
OpenApiSpecVersion specVersion,
62-
OpenApiFormat format,
63+
string format,
6364
CancellationToken cancellationToken = default)
6465
where T : IOpenApiSerializable
6566
{
@@ -81,7 +82,7 @@ public static Task SerializeAsync<T>(
8182
this T element,
8283
Stream stream,
8384
OpenApiSpecVersion specVersion,
84-
OpenApiFormat format,
85+
string format,
8586
OpenApiWriterSettings? settings = null,
8687
CancellationToken cancellationToken = default)
8788
where T : IOpenApiSerializable
@@ -90,10 +91,10 @@ public static Task SerializeAsync<T>(
9091

9192
var streamWriter = new FormattingStreamWriter(stream, CultureInfo.InvariantCulture);
9293

93-
IOpenApiWriter writer = format switch
94+
IOpenApiWriter writer = format.ToLowerInvariant() switch
9495
{
95-
OpenApiFormat.Json => new OpenApiJsonWriter(streamWriter, settings, false),
96-
OpenApiFormat.Yaml => new OpenApiYamlWriter(streamWriter, settings),
96+
OpenApiConstants.Json => new OpenApiJsonWriter(streamWriter, settings, false),
97+
OpenApiConstants.Yaml => new OpenApiYamlWriter(streamWriter, settings),
9798
_ => throw new OpenApiException(string.Format(SRResource.OpenApiFormatNotSupported, format)),
9899
};
99100
return element.SerializeAsync(writer, specVersion, cancellationToken);
@@ -147,7 +148,7 @@ public static Task<string> SerializeAsJsonAsync<T>(
147148
CancellationToken cancellationToken = default)
148149
where T : IOpenApiSerializable
149150
{
150-
return element.SerializeAsync(specVersion, OpenApiFormat.Json, cancellationToken);
151+
return element.SerializeAsync(specVersion, OpenApiConstants.Json, cancellationToken);
151152
}
152153

153154
/// <summary>
@@ -163,7 +164,7 @@ public static Task<string> SerializeAsYamlAsync<T>(
163164
CancellationToken cancellationToken = default)
164165
where T : IOpenApiSerializable
165166
{
166-
return element.SerializeAsync(specVersion, OpenApiFormat.Yaml, cancellationToken);
167+
return element.SerializeAsync(specVersion, OpenApiConstants.Yaml, cancellationToken);
167168
}
168169

169170
/// <summary>
@@ -177,7 +178,7 @@ public static Task<string> SerializeAsYamlAsync<T>(
177178
public static async Task<string> SerializeAsync<T>(
178179
this T element,
179180
OpenApiSpecVersion specVersion,
180-
OpenApiFormat format,
181+
string format,
181182
CancellationToken cancellationToken = default)
182183
where T : IOpenApiSerializable
183184
{

0 commit comments

Comments
 (0)