Skip to content

Commit 23c5580

Browse files
committed
chore: merge main into current branch
2 parents aa5292f + 7ea0e9d commit 23c5580

File tree

126 files changed

+2727
-662
lines changed

Some content is hidden

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

126 files changed

+2727
-662
lines changed

.github/workflows/auto-merge-dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
steps:
2020
- name: Dependabot metadata
2121
id: metadata
22-
uses: dependabot/fetch-metadata@v2.3.0
22+
uses: dependabot/fetch-metadata@v2.4.0
2323
with:
2424
github-token: "${{ secrets.GITHUB_TOKEN }}"
2525

.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.17"
2+
".": "2.0.0-preview.20"
33
}

CHANGELOG.md

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

3+
## [2.0.0-preview.20](https://github.com/microsoft/OpenAPI.NET/compare/v2.0.0-preview.19...v2.0.0-preview.20) (2025-05-20)
4+
5+
6+
### Bug Fixes
7+
8+
* nullable and type ordering should be maintain to ease up migration work ([6c82aa6](https://github.com/microsoft/OpenAPI.NET/commit/6c82aa6b2d6e4f39af3c594edd8590a0cf749530))
9+
* nullable should not be inserted as an attempt to normalize the document ([6c82aa6](https://github.com/microsoft/OpenAPI.NET/commit/6c82aa6b2d6e4f39af3c594edd8590a0cf749530))
10+
* refactor to avoid adding duplicate entries ([41fd508](https://github.com/microsoft/OpenAPI.NET/commit/41fd508074f1b70415026df3aa878cd5f5e7b1ee))
11+
* refactor to avoid adding duplicate entries ([#2359](https://github.com/microsoft/OpenAPI.NET/issues/2359)) ([9791eb6](https://github.com/microsoft/OpenAPI.NET/commit/9791eb684a0f040feeb8c58701fd4f3577e73e2c))
12+
* tree node has the wrong structure because of trailing slashes ([2ffb273](https://github.com/microsoft/OpenAPI.NET/commit/2ffb2735aa3718370d6094186142f9cf50b194fa))
13+
* tree node has the wrong structure because of trailing slashes ([4439340](https://github.com/microsoft/OpenAPI.NET/commit/443934060e1e446de726addde69a2de955b95a7b))
14+
* wrong link to json schema spec in schema doc comments ([d9b0c90](https://github.com/microsoft/OpenAPI.NET/commit/d9b0c906f7173b81fea15001d588edcbc3eed8f1))
15+
* wrong link to json schema spec in schema doc comments ([9a73ec6](https://github.com/microsoft/OpenAPI.NET/commit/9a73ec6e5486d84b6a30a5fa0ac5961b381fc3d3))
16+
17+
## [2.0.0-preview.19](https://github.com/microsoft/OpenAPI.NET/compare/v2.0.0-preview.18...v2.0.0-preview.19) (2025-05-16)
18+
19+
20+
### Bug Fixes
21+
22+
* base url should be read from the settings when available ([f5d6e81](https://github.com/microsoft/OpenAPI.NET/commit/f5d6e81c21fd18b6de0fb19b535ad6dbc187790d))
23+
* base url should be read from the settings when available ([b17b7d8](https://github.com/microsoft/OpenAPI.NET/commit/b17b7d8d25fdf9a767411481287aacee31434aaa))
24+
* discriminator mapping references don't get a document when created from DOM ([767d3fb](https://github.com/microsoft/OpenAPI.NET/commit/767d3fb163b273b275cd67d710c573c59e4e642b))
25+
* discriminator mapping references don't get a document when created from DOM ([fdfe002](https://github.com/microsoft/OpenAPI.NET/commit/fdfe002d551fc3feaaeb5af24042826f13bdf412))
26+
27+
## [2.0.0-preview.18](https://github.com/microsoft/OpenAPI.NET/compare/v2.0.0-preview.17...v2.0.0-preview.18) (2025-05-13)
28+
29+
30+
### Features
31+
32+
* upgrades openapi.net.odata and apimanifest to the latest version ([80844a6](https://github.com/microsoft/OpenAPI.NET/commit/80844a60ae50ba0a4d54d7dd2e45ce8360206bf5))
33+
* upgrades openapi.net.odata and apimanifest to the latest version ([938a2e0](https://github.com/microsoft/OpenAPI.NET/commit/938a2e07b40b082e01ed1cdf3244767cbdca4061))
34+
35+
36+
### Bug Fixes
37+
38+
* avoid calling virtual members in constructor ([5835057](https://github.com/microsoft/OpenAPI.NET/commit/5835057a7e905e371f859e727ddaf65ec08c6db0))
39+
* Fix typo in error message ([#2345](https://github.com/microsoft/OpenAPI.NET/issues/2345)) ([3f8b2b9](https://github.com/microsoft/OpenAPI.NET/commit/3f8b2b99c07bd3c58825728c2dd2ffed91d88fbe))
40+
* handle deserializing and writing empty security requirements [#1426](https://github.com/microsoft/OpenAPI.NET/issues/1426) ([#2323](https://github.com/microsoft/OpenAPI.NET/issues/2323)) ([962e0e4](https://github.com/microsoft/OpenAPI.NET/commit/962e0e436f96b1b68613013d75307dc1f92ce15c))
41+
* normalized override implementation for parameter types serialization in v2 ([5930916](https://github.com/microsoft/OpenAPI.NET/commit/593091621926defcbc2727a922613e34557d882a))
42+
343
## [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)
444

545

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.17</Version>
15+
<Version>2.0.0-preview.20</Version>
1616
</PropertyGroup>
1717
<!-- https://github.com/clairernovotny/DeterministicBuilds#deterministic-builds -->
1818
<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">

docs/upgrade-guide-2.md

Lines changed: 154 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ var openApiObject = new OpenApiObject
203203
}
204204
};
205205
var parameter = new OpenApiParameter();
206-
parameter.Extensions.Add("x-foo", new OpenApiAny(openApiObject));
206+
parameter.Extensions.Add("x-foo", openApiObject);
207207

208208
```
209209

@@ -223,7 +223,7 @@ var openApiObject = new JsonObject
223223
}
224224
};
225225
var parameter = new OpenApiParameter();
226-
parameter.Extensions.Add("x-foo", new OpenApiAny(openApiObject));
226+
parameter.Extensions.Add("x-foo", new JsonNodeExtension(openApiObject));
227227

228228
```
229229

@@ -361,6 +361,29 @@ public class OpenApiSchema : IMetadataContainer, IOpenApiExtensible, IOpenApiRef
361361

362362
There are a number of new features in OpenAPI v3.1 that are now supported in OpenAPI.NET.
363363

364+
### JsonSchema Dialect and BaseUri in OpenApiDocument
365+
To enable full compatibility with JSON Schema, the `OpenApiDocument` class now supports a `JsonSchemaDialect` property. This property specifies the JSON Schema dialect used throughout the document, using a URI. By explicitly declaring the dialect, tooling can be directed to use a JSON Schema version other than the default [2020-12 draft](https://json-schema.org/draft/2020-12/json-schema-core.html). However, OpenAPI.NET does not guarantee compatibility with versions other than 2020-12.
366+
367+
In addition, a `BaseUri` property has been added to represent the identity of the OpenAPI document. If the document’s identity is not provided or cannot be determined at based on its location, this property will be set to a generated placeholder URI.
368+
369+
```csharp
370+
/// <summary>
371+
/// Describes an OpenAPI object (OpenAPI document). See: https://spec.openapis.org
372+
/// </summary>
373+
public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible, IMetadataContainer
374+
{
375+
/// <summary>
376+
/// The default value for the $schema keyword within Schema Objects contained within this OAS document. This MUST be in the form of a URI.
377+
/// </summary>
378+
public Uri? JsonSchemaDialect { get; set; }
379+
380+
/// <summary>
381+
/// Absolute location of the document or a generated placeholder if location is not given
382+
/// </summary>
383+
public Uri BaseUri { get; internal set; }
384+
}
385+
```
386+
364387
### Webhooks
365388

366389
```csharp
@@ -483,6 +506,7 @@ OpenApiComponents components = new OpenApiComponents
483506
### OpenApiDocument.SerializeAs()
484507

485508
The `SerializeAs()` method simplifies serialization scenarios, making it easier to convert OpenAPI documents to different formats.
509+
486510
**Example:**
487511

488512
```csharp
@@ -493,7 +517,7 @@ string json = document.SerializeAs(OpenApiSpecVersion.OpenApi3_0, OpenApiConstan
493517

494518
### Use OpenApiConstants string Instead of OpenApiFormat Enum
495519

496-
OpenApiConstants are now used instead of OpenApiFormat enums.
520+
`OpenApiConstants` are now used instead the `OpenApiFormat` enumeration.
497521

498522
**Example:**
499523

@@ -505,6 +529,133 @@ var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, Open
505529
var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Json);
506530
```
507531

532+
### OpenApiSchema's Type property is now a flaggable enum
533+
534+
In v2.0, the Type property in `OpenApiSchema` is now defined as a flaggable enum, allowing consumers to swap nullable for type arrays.
535+
536+
**Example:**
537+
```csharp
538+
// v1.6.x
539+
var schema = new OpenApiSchema
540+
{
541+
Type = "string",
542+
Nullable = true
543+
}
544+
545+
// v2.0
546+
// bitwise OR(|) - combines flags to allow multiple types
547+
var schema = new OpenApiSchema
548+
{
549+
Type = JsonSchemaType.String | JsonSchemaType.Null
550+
}
551+
552+
// bitwise NOT(~) - inverts bits; filters out null flag
553+
var schema = new OpenApiSchema
554+
{
555+
Type = JsonSchemaType.String & ~JsonSchemaType.Null
556+
}
557+
558+
// bitwise AND(&) - intersects flags to check for a specific type
559+
var schema = new OpenApiSchema
560+
{
561+
Type = (JsonSchemaType.String & JsonSchemaType.Null) == JsonSchemaType.Null
562+
}
563+
564+
```
565+
566+
### Component registration in a document's workspace
567+
568+
When loading up a file into an in-memory document, all the components contained in the document are registered within the document's workspace by default to aid with reference resolution.
569+
However if you're working directly with a DOM and you need the references resolved, you can register the components as below:
570+
571+
```csharp
572+
// register all components
573+
document.Workspace.RegisterComponents(OpenApiDocument document);
574+
575+
// register single component
576+
document.AddComponent<T>(string id, T componentToRegister);
577+
```
578+
579+
### Refactored model architecture
580+
581+
The following structural improvements have been made to the OpenAPI model layer to enhance type safety, extensibility, and maintainability:
582+
583+
1. Model Interfaces Introduced:
584+
Each model now has a corresponding interface (e.g., `IOpenApiSchema` for `OpenApiSchema`). This allows for better abstraction and testing support, while also simplifying cross-cutting concerns like serialization.
585+
586+
2. Models as Reference Types:
587+
All models are now implemented as reference types to ensure consistent identity semantics, especially when managing circular references or shared definitions.
588+
589+
3. Type Assertion Pattern Adopted:
590+
A standardized pattern has been introduced for casting model instances to specific types safely and predictably, reducing the risk of invalid casts or reflection-based logic.
591+
592+
4. Removed Reference Fields from Base Models:
593+
Properties like `Reference` that were previously defined on base model types have been removed. Models that support referencing now handle this behavior explicitly via composition rather than inheritance.
594+
595+
5. New Target and RecursiveTarget Properties:
596+
A `Target` property that points to the actual resolved model instance as well as a `RecursiveTarget` property that handles recursive references and supports advanced dereferencing logic have been introduced.
597+
598+
6. Removed OpenApiReferenceResolver:
599+
This resolver class has been removed in favor of a more streamlined resolution model using the `Target` and `RecursiveTarget` properties along with updated reader/serializer pipelines.
600+
601+
### Visitor and Validator now pass an interface model
602+
603+
**Example:**
604+
```csharp
605+
//v1.6.x
606+
public override void Visit(OpenApiParameter parameter){}
607+
608+
//v2.0
609+
public override void Visit(IOpenApiParameter parameter){}
610+
```
611+
612+
### Cleaned up the IEffective/GetEffective infrastructure
613+
614+
All the `IEffective` and `GetEffective` infrastructure in the models have been removed as we've implemented lazy reference resolution using the proxy design.
615+
616+
### Shallow Copy in place of copy constructors
617+
618+
Copy constructors for referenceable components have been made internal, a new `CreateShallowCopy()` method has been exposed on these models to facilitate cloning.
619+
620+
**Example:**
621+
```csharp
622+
var schema = new OpenApiSchema();
623+
var schemaCopy = schema.CreateShallowCopy();
624+
```
625+
626+
### Duplicated _style Property on Parameter Removed
627+
628+
The redundant _style property on the Parameter model has been removed to simplify the model's structure.
629+
630+
### Discriminator now use References
631+
632+
Discriminator mappings have been updated from using a `Dictionary<string, string>` to a `Dictionary<string, OpenApiSchemaReference>`. This change improves the handling of discriminator mappings by referencing OpenAPI schema components more explicitly, which enhances schema resolution.
633+
634+
**Example:**
635+
```csharp
636+
// v1.6.x
637+
Discriminator = new()
638+
{
639+
PropertyName = "@odata.type",
640+
Mapping = new Dictionary<string, string> {
641+
{
642+
"#microsoft.graph.directoryObject", "#/components/schemas/microsoft.graph.directoryObject"
643+
}
644+
}
645+
}
646+
647+
//v2.0
648+
Discriminator = new()
649+
{
650+
PropertyName = "@odata.type",
651+
Mapping = new Dictionary<string, OpenApiSchemaReference> {
652+
{
653+
"#microsoft.graph.directoryObject", new OpenApiSchemaReference("microsoft.graph.directoryObject")
654+
}
655+
}
656+
}
657+
```
658+
508659
### Bug Fixes
509660

510661
## Serialization of References
@@ -524,17 +675,3 @@ OpenApiSchemaReference schemaRef = new OpenApiSchemaReference("MySchema")
524675

525676
If you have any feedback please file a GitHub issue [here](https://github.com/microsoft/OpenAPI.NET/issues)
526677
The team is looking forward to hear your experience trying the new version and we hope you have fun busting out your OpenAPI 3.1 descriptions.
527-
528-
## Todos
529-
530-
- Models now have matching interfaces + reference type + type assertion pattern + reference fields removed from the base model + Target + RecursiveTarget + removed OpenApiReferenceResolver.
531-
- Workspace + component resolution.
532-
- Visitor and Validator method now pass the interface model.
533-
- Removed all the IEffective/GetEffective infrastructure.
534-
- OpenApiSchema.Type is now a flag enum + bitwise operations.
535-
- JsonSchemaDialect + BaseUri in document.
536-
- Copy constructors are gone, use shallow copy method.
537-
- Multiple methods that should have been internal have been changed from public to private link OpenApiLink.SerializeAsV3WithoutReference.
538-
- duplicated _style property on parameter was removed.
539-
- discriminator now uses references.
540-
- ValidationRuleSet now accepts a key?
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
```
22
3-
BenchmarkDotNet v0.14.0, Windows 11 (10.0.26100.3476)
3+
BenchmarkDotNet v0.14.0, Windows 11 (10.0.26100.3981)
44
11th Gen Intel Core i7-1185G7 3.00GHz, 1 CPU, 8 logical and 4 physical cores
5-
.NET SDK 8.0.408
6-
[Host] : .NET 8.0.15 (8.0.1525.16413), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
7-
ShortRun : .NET 8.0.15 (8.0.1525.16413), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
5+
.NET SDK 8.0.409
6+
[Host] : .NET 8.0.16 (8.0.1625.21506), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
7+
ShortRun : .NET 8.0.16 (8.0.1625.21506), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
88
99
Job=ShortRun IterationCount=3 LaunchCount=1
1010
WarmupCount=3
1111
1212
```
1313
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated |
1414
|------------- |-------------:|--------------:|-------------:|-----------:|-----------:|----------:|-------------:|
15-
| PetStoreYaml | 450.5 μs | 59.26 μs | 3.25 μs | 58.5938 | 11.7188 | - | 377.15 KB |
16-
| PetStoreJson | 172.8 μs | 123.46 μs | 6.77 μs | 39.0625 | 7.8125 | - | 239.29 KB |
17-
| GHESYaml | 943,452.7 μs | 137,685.49 μs | 7,547.01 μs | 66000.0000 | 21000.0000 | 3000.0000 | 389463.91 KB |
18-
| GHESJson | 468,401.8 μs | 300,711.80 μs | 16,483.03 μs | 41000.0000 | 15000.0000 | 3000.0000 | 250934.62 KB |
15+
| PetStoreYaml | 470.3 μs | 138.05 μs | 7.57 μs | 58.5938 | 11.7188 | - | 380.53 KB |
16+
| PetStoreJson | 166.0 μs | 43.84 μs | 2.40 μs | 39.0625 | 8.7891 | - | 242.67 KB |
17+
| GHESYaml | 915,406.4 μs | 714,492.62 μs | 39,163.75 μs | 68000.0000 | 22000.0000 | 4000.0000 | 395800.98 KB |
18+
| GHESJson | 470,609.4 μs | 264,698.88 μs | 14,509.04 μs | 42000.0000 | 15000.0000 | 3000.0000 | 257270.45 KB |
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Method,Job,AnalyzeLaunchVariance,EvaluateOverhead,MaxAbsoluteError,MaxRelativeError,MinInvokeCount,MinIterationTime,OutlierMode,Affinity,EnvironmentVariables,Jit,LargeAddressAware,Platform,PowerPlanMode,Runtime,AllowVeryLargeObjects,Concurrent,CpuGroups,Force,HeapAffinitizeMask,HeapCount,NoAffinitize,RetainVm,Server,Arguments,BuildConfiguration,Clock,EngineFactory,NuGetReferences,Toolchain,IsMutator,InvocationCount,IterationCount,IterationTime,LaunchCount,MaxIterationCount,MaxWarmupIterationCount,MemoryRandomization,MinIterationCount,MinWarmupIterationCount,RunStrategy,UnrollFactor,WarmupCount,Mean,Error,StdDev,Gen0,Gen1,Gen2,Allocated
2-
PetStoreYaml,ShortRun,False,Default,Default,Default,Default,Default,Default,11111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,450.5 μs,59.26 μs,3.25 μs,58.5938,11.7188,0.0000,377.15 KB
3-
PetStoreJson,ShortRun,False,Default,Default,Default,Default,Default,Default,11111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,172.8 μs,123.46 μs,6.77 μs,39.0625,7.8125,0.0000,239.29 KB
4-
GHESYaml,ShortRun,False,Default,Default,Default,Default,Default,Default,11111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,"943,452.7 μs","137,685.49 μs","7,547.01 μs",66000.0000,21000.0000,3000.0000,389463.91 KB
5-
GHESJson,ShortRun,False,Default,Default,Default,Default,Default,Default,11111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,"468,401.8 μs","300,711.80 μs","16,483.03 μs",41000.0000,15000.0000,3000.0000,250934.62 KB
2+
PetStoreYaml,ShortRun,False,Default,Default,Default,Default,Default,Default,11111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,470.3 μs,138.05 μs,7.57 μs,58.5938,11.7188,0.0000,380.53 KB
3+
PetStoreJson,ShortRun,False,Default,Default,Default,Default,Default,Default,11111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,166.0 μs,43.84 μs,2.40 μs,39.0625,8.7891,0.0000,242.67 KB
4+
GHESYaml,ShortRun,False,Default,Default,Default,Default,Default,Default,11111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,"915,406.4 μs","714,492.62 μs","39,163.75 μs",68000.0000,22000.0000,4000.0000,395800.98 KB
5+
GHESJson,ShortRun,False,Default,Default,Default,Default,Default,Default,11111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,"470,609.4 μs","264,698.88 μs","14,509.04 μs",42000.0000,15000.0000,3000.0000,257270.45 KB

0 commit comments

Comments
 (0)