Skip to content

Commit b3967d3

Browse files
committed
docs: adds the v3 upgrade guide
Signed-off-by: Vincent Biret <[email protected]>
1 parent 396779e commit b3967d3

File tree

1 file changed

+386
-0
lines changed

1 file changed

+386
-0
lines changed

docs/upgrade-guide-3.md

Lines changed: 386 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,386 @@
1+
# Upgrade guide to OpenAPI.NET 3.0
2+
3+
## Introduction
4+
5+
We are excited to announce OpenAPI.NET v3.0! This major update introduces support for OpenAPI v3.2 specification along with several API enhancements and refinements to the existing model architecture.
6+
7+
> [!WARNING]
8+
> This is a major version update that includes breaking changes. Please review this guide carefully before upgrading.
9+
10+
## OpenAPI v3.2 Support
11+
12+
The primary focus of OpenAPI.NET v3.0 is adding comprehensive support for OpenAPI specification v3.2. This includes new serialization methods, enhanced model properties, and expanded functionality across the entire API surface.
13+
14+
### New Serialization Methods
15+
16+
All serializable components now include a `SerializeAsV32` method alongside the existing serialization methods:
17+
18+
```csharp
19+
// v2.x
20+
document.SerializeAsV31(writer);
21+
22+
// v3.0
23+
document.SerializeAsV31(writer);
24+
document.SerializeAsV32(writer); // New!
25+
```
26+
27+
### OpenApiSpecVersion Enum Update
28+
29+
A new version constant has been added:
30+
31+
```csharp
32+
public enum OpenApiSpecVersion
33+
{
34+
OpenApi2_0 = 0,
35+
OpenApi3_0 = 1,
36+
OpenApi3_1 = 2,
37+
OpenApi3_2 = 3, // New!
38+
}
39+
```
40+
41+
## Enhanced Media Type Support
42+
43+
### IOpenApiMediaType Interface
44+
45+
Media types are now represented by the `IOpenApiMediaType` interface, providing better abstraction and consistency across the API:
46+
47+
```csharp
48+
// v2.x
49+
public IDictionary<string, OpenApiMediaType>? Content { get; set; }
50+
51+
// v3.0
52+
public IDictionary<string, IOpenApiMediaType>? Content { get; set; }
53+
```
54+
55+
### New Media Type Properties
56+
57+
The `IOpenApiMediaType` interface includes additional properties for enhanced functionality:
58+
59+
```csharp
60+
public interface IOpenApiMediaType
61+
{
62+
IDictionary<string, OpenApiEncoding>? Encoding { get; }
63+
JsonNode? Example { get; }
64+
IDictionary<string, IOpenApiExample>? Examples { get; }
65+
OpenApiEncoding? ItemEncoding { get; } // New!
66+
IOpenApiSchema? ItemSchema { get; } // New!
67+
IList<OpenApiEncoding>? PrefixEncoding { get; } // New!
68+
IOpenApiSchema? Schema { get; }
69+
}
70+
```
71+
72+
### MediaTypes in Components
73+
74+
Components now support reusable media types:
75+
76+
```csharp
77+
public class OpenApiComponents
78+
{
79+
public IDictionary<string, IOpenApiMediaType>? MediaTypes { get; set; } // New!
80+
// ... other existing properties
81+
}
82+
```
83+
84+
## Enhanced Example Support
85+
86+
### New Example Properties
87+
88+
Example objects now support additional data representation options:
89+
90+
```csharp
91+
public class OpenApiExample : IOpenApiExample
92+
{
93+
public JsonNode? DataValue { get; set; } // New!
94+
public string? SerializedValue { get; set; } // New!
95+
public string? ExternalValue { get; set; }
96+
public JsonNode? Value { get; set; }
97+
// ... other properties
98+
}
99+
```
100+
101+
## Security Scheme Enhancements
102+
103+
### Deprecated Property
104+
105+
Security schemes now support a deprecated flag:
106+
107+
```csharp
108+
public interface IOpenApiSecurityScheme
109+
{
110+
bool Deprecated { get; } // New!
111+
// ... other existing properties
112+
}
113+
```
114+
115+
### Device Authorization Flow
116+
117+
OAuth flows now support device authorization:
118+
119+
```csharp
120+
public class OpenApiOAuthFlows
121+
{
122+
public OpenApiOAuthFlow? DeviceAuthorization { get; set; } // New!
123+
// ... other existing flows
124+
}
125+
126+
public class OpenApiOAuthFlow
127+
{
128+
public Uri? DeviceAuthorizationUrl { get; set; } // New!
129+
// ... other existing properties
130+
}
131+
```
132+
133+
## Tag System Improvements
134+
135+
### Hierarchical Tags
136+
137+
Tags now support hierarchical organization with enhanced metadata:
138+
139+
```csharp
140+
public interface IOpenApiTag
141+
{
142+
string? Kind { get; } // New!
143+
string? Summary { get; } // New!
144+
OpenApiTagReference? Parent { get; } // New!
145+
string? Name { get; }
146+
// ... other existing properties
147+
}
148+
```
149+
150+
## Response Enhancements
151+
152+
### Summary Support
153+
154+
Responses now implement `IOpenApiSummarizedElement` and support summary text:
155+
156+
```csharp
157+
// v2.x
158+
public interface IOpenApiResponse : IOpenApiDescribedElement, ...
159+
{
160+
// No summary support
161+
}
162+
163+
// v3.0
164+
public interface IOpenApiResponse : IOpenApiDescribedElement,
165+
IOpenApiSummarizedElement, ... // New!
166+
{
167+
// Inherits Summary property from IOpenApiSummarizedElement
168+
}
169+
```
170+
171+
## XML Improvements
172+
173+
### Enhanced Node Type Support
174+
175+
The XML object has been refactored to use a more flexible node type system:
176+
177+
```csharp
178+
// v2.x
179+
public class OpenApiXml
180+
{
181+
public bool Attribute { get; set; } // Removed!
182+
public bool Wrapped { get; set; } // Removed!
183+
}
184+
185+
// v3.0
186+
public class OpenApiXml
187+
{
188+
public OpenApiXmlNodeType? NodeType { get; set; } // New!
189+
}
190+
191+
public enum OpenApiXmlNodeType
192+
{
193+
Element = 0,
194+
Attribute = 1,
195+
Text = 2,
196+
Cdata = 3,
197+
None = 4,
198+
}
199+
```
200+
201+
## Discriminator Enhancements
202+
203+
### Default Mapping Support
204+
205+
Discriminators now support default mapping scenarios:
206+
207+
```csharp
208+
public class OpenApiDiscriminator
209+
{
210+
public OpenApiSchemaReference? DefaultMapping { get; set; } // New!
211+
// ... other existing properties
212+
}
213+
```
214+
215+
## Document Enhancements
216+
217+
### Self-Reference Support
218+
219+
Documents can now specify their own identity URI:
220+
221+
```csharp
222+
public class OpenApiDocument
223+
{
224+
public Uri? Self { get; set; } // New!
225+
// ... other existing properties
226+
}
227+
```
228+
229+
## Parameter Location Enhancements
230+
231+
### New Parameter Locations
232+
233+
Additional parameter locations are now supported:
234+
235+
```csharp
236+
public enum ParameterLocation
237+
{
238+
Query = 0,
239+
Header = 1,
240+
Path = 2,
241+
Cookie = 3,
242+
QueryString = 4, // New!
243+
}
244+
```
245+
246+
### New Parameter Styles
247+
248+
```csharp
249+
public enum ParameterStyle
250+
{
251+
Matrix = 0,
252+
Label = 1,
253+
Form = 2,
254+
Simple = 3,
255+
SpaceDelimited = 4,
256+
PipeDelimited = 5,
257+
DeepObject = 6,
258+
Cookie = 7, // New!
259+
}
260+
```
261+
262+
## Reference Type Enhancements
263+
264+
### New Reference Types
265+
266+
```csharp
267+
public enum ReferenceType
268+
{
269+
Schema = 0,
270+
Response = 1,
271+
Parameter = 2,
272+
Example = 3,
273+
RequestBody = 4,
274+
Header = 5,
275+
SecurityScheme = 6,
276+
Link = 7,
277+
Callback = 8,
278+
Tag = 9,
279+
PathItem = 10,
280+
MediaType = 11, // New!
281+
}
282+
```
283+
284+
## Visitor Pattern Updates
285+
286+
### Interface-Based Visiting
287+
288+
The visitor pattern now works with interface types for better abstraction:
289+
290+
```csharp
291+
// v2.x
292+
public virtual void Visit(OpenApiMediaType mediaType) { }
293+
294+
// v3.0
295+
public virtual void Visit(IOpenApiMediaType mediaType) { }
296+
```
297+
298+
## Version Detection
299+
300+
### New Version Detection Method
301+
302+
```csharp
303+
public static class VersionService
304+
{
305+
public static bool is3_2(this string version) { } // New!
306+
// ... other existing version methods
307+
}
308+
```
309+
310+
## Migration Steps
311+
312+
### 1. Update Media Type References
313+
314+
Replace concrete `OpenApiMediaType` references with `IOpenApiMediaType`:
315+
316+
```csharp
317+
// Before
318+
public IDictionary<string, OpenApiMediaType>? Content { get; set; }
319+
320+
// After
321+
public IDictionary<string, IOpenApiMediaType>? Content { get; set; }
322+
```
323+
324+
### 2. Update XML Object Usage
325+
326+
Replace boolean properties with the new enum-based approach:
327+
328+
```csharp
329+
// Before
330+
var xml = new OpenApiXml
331+
{
332+
Attribute = true,
333+
Wrapped = false
334+
};
335+
336+
// After
337+
var xml = new OpenApiXml
338+
{
339+
NodeType = OpenApiXmlNodeType.Attribute
340+
};
341+
```
342+
343+
### 3. Update Visitor Implementations
344+
345+
Update visitor methods to use interface types:
346+
347+
```csharp
348+
// Before
349+
public override void Visit(OpenApiMediaType mediaType) { /* ... */ }
350+
351+
// After
352+
public override void Visit(IOpenApiMediaType mediaType) { /* ... */ }
353+
```
354+
355+
### 4. Add v3.2 Serialization Support
356+
357+
If you have custom serialization logic, add support for v3.2:
358+
359+
```csharp
360+
public void SerializeAsV32(IOpenApiWriter writer)
361+
{
362+
// Implement v3.2 specific serialization
363+
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_2);
364+
}
365+
```
366+
367+
## Breaking Changes Summary
368+
369+
1. **Media Type Abstraction**: `OpenApiMediaType` replaced with `IOpenApiMediaType` interface in collection properties
370+
2. **XML Object Refactoring**: `Attribute` and `Wrapped` boolean properties replaced with `NodeType` enum
371+
3. **Visitor Pattern**: Methods now accept interface types instead of concrete types
372+
4. **Response Interface**: `IOpenApiResponse` now extends `IOpenApiSummarizedElement`
373+
374+
## New Features Summary
375+
376+
1. **OpenAPI v3.2 Support**: Full serialization and model support
377+
2. **Enhanced Media Types**: New properties for encoding and schema support
378+
3. **Hierarchical Tags**: Support for tag organization with kind, summary, and parent relationships
379+
4. **Security Enhancements**: Deprecated flag and device authorization flow support
380+
5. **Enhanced Examples**: New data value and serialized value properties
381+
6. **Document Self-Reference**: Support for document identity URIs
382+
7. **Extended Parameter Support**: New locations and styles for parameters
383+
384+
## Feedback
385+
386+
If you have any feedback please file [a new GitHub issue](https://github.com/microsoft/OpenAPI.NET/issues). The team looks forward to hearing about your experience with OpenAPI.NET v3.0 and OpenAPI v3.2 support!

0 commit comments

Comments
 (0)