You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/upgrade-guide-2.md
+139-15
Original file line number
Diff line number
Diff line change
@@ -361,6 +361,29 @@ public class OpenApiSchema : IMetadataContainer, IOpenApiExtensible, IOpenApiRef
361
361
362
362
There are a number of new features in OpenAPI v3.1 that are now supported in OpenAPI.NET.
363
363
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 no longer needs to infer which draft is being used based on schema structure or references.
366
+
367
+
In addition, a BaseUri property has been added to represent the absolute location of the OpenAPI document. If the document’s location is not provided, 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
### 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
+
varschema=newOpenApiSchema
540
+
{
541
+
Type="string",
542
+
Nullable=true
543
+
}
544
+
545
+
// v2.0
546
+
varschema=newOpenApiSchema
547
+
{
548
+
Type=JsonSchemaType.String|JsonSchemaType.Null
549
+
}
550
+
551
+
```
552
+
553
+
### Component registration in a document's workspace
554
+
555
+
Whenloadingupafileintoanin-memorydocument, allthecomponentscontainedinthedocumentareregisteredwithinthedocument's workspace by default to aid with reference resolution.
556
+
Howeverifyou're working directly with a DOM and you need the references resolved, you can register the components as below:
The following structural improvements have been made to the OpenAPI model layer to enhance type safety, extensibility, and maintainability:
569
+
570
+
1. Model Interfaces Introduced:
571
+
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.
572
+
573
+
2. Models as Reference Types:
574
+
All models are now implemented as reference types to ensure consistent identity semantics, especially when managing circular references or shared definitions.
575
+
576
+
3. Type Assertion Pattern Adopted:
577
+
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.
578
+
579
+
4. Removed Reference Fields from Base Models:
580
+
Fields 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.
581
+
582
+
5. New Target and RecursiveTarget Properties:
583
+
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.
584
+
585
+
6. Removed OpenApiReferenceResolver:
586
+
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.
587
+
588
+
### Visitor and Validator now pass an interface model
### Cleaned up the IEffective/GetEffective infrastructure
600
+
601
+
All the IEffective and GetEffective methods in the models have been removed as we've implemented lazy reference resolution using the proxy design.
602
+
603
+
### Shallow Copy in place of copy constructors
604
+
605
+
Copy constructors have been eliminated from the models in favor of a more straightforward approach using a shallow copy method. This simplifies the codebase and reduces potential issues with deep copying and unintended side effects.
606
+
607
+
**Example:**
608
+
```csharp
609
+
varschema=newOpenApiSchema();
610
+
varschemaCopy=schema.CreateShallowCopy();
611
+
```
612
+
613
+
### Duplicated _style Property on Parameter Removed
614
+
615
+
The redundant _style property on the Parameter model has been removed to simplify the model's structure.
616
+
617
+
### Discriminator now use References
618
+
619
+
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.
@@ -523,18 +661,4 @@ OpenApiSchemaReference schemaRef = new OpenApiSchemaReference("MySchema")
523
661
## Feedback
524
662
525
663
If you have any feedback please file a GitHub issue [here](https://github.com/microsoft/OpenAPI.NET/issues)
526
-
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?
664
+
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.
0 commit comments