-
Notifications
You must be signed in to change notification settings - Fork 263
Add JSON Schema 2020-12 metadata annotations to OpenApiSchemaReference #2376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: baywet <[email protected]>
- Add Default, Title, Deprecated, ReadOnly, WriteOnly, Examples to OpenApiReference - Update OpenApiSchemaReference properties to use override pattern like Description - Add Summary property to OpenApiSchemaReference - Update serialization for v3.1 to include new annotation fields - Update deserialization to handle new annotation fields - Add comprehensive unit tests for new functionality - Update public API approvals Co-authored-by: baywet <[email protected]>
- Add comprehensive integration test for parsing schema references with annotations - Verify full round-trip functionality works correctly - All existing tests pass (854/858 tests successful) - New serialization tests show correct behavior for v3.0 and v3.1 Co-authored-by: baywet <[email protected]>
…dback Co-authored-by: baywet <[email protected]>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs
Outdated
Show resolved
Hide resolved
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
{ | ||
Utils.CheckArgumentNull(source); | ||
Reference = new(source.Reference); | ||
Reference = CopyReference(source.Reference); |
Check warning
Code scanning / CodeQL
Virtual call in constructor or destructor Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 months ago
To fix the issue, we need to eliminate the virtual call to CopyReference
in the constructor. Instead, we can introduce a protected method in the base class that performs the necessary initialization without relying on virtual calls. The derived classes can then override this method if needed, ensuring that the virtual behavior is invoked only after the derived class's constructor has completed.
Specifically:
- Replace the call to
CopyReference(source.Reference)
in the constructor with a call to a new non-virtual method, e.g.,InitializeReference
. - Move the logic of
CopyReference
into the derived classes, ensuring it is invoked explicitly after the base class constructor has completed.
-
Copy modified lines R41-R49 -
Copy modified line R56
@@ -40,2 +40,11 @@ | ||
/// <summary> | ||
/// Initialize the reference object. | ||
/// </summary> | ||
/// <param name="sourceReference">The source reference to copy</param> | ||
protected void InitializeReference(V sourceReference) | ||
{ | ||
Reference = CopyReference(sourceReference); | ||
} | ||
|
||
/// <summary> | ||
/// Copy constructor | ||
@@ -46,3 +55,3 @@ | ||
Utils.CheckArgumentNull(source); | ||
Reference = CopyReference(source.Reference); | ||
InitializeReference(source.Reference); | ||
//no need to copy summary and description as if they are not overridden, they will be fetched from the target |
… use Where Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs
Outdated
Show resolved
Hide resolved
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
|
This PR implements support for all JSON Schema 2020-12 metadata annotations on
OpenApiSchemaReference
, enabling developers to override schema properties at the reference level as specified in OpenAPI 3.1.Changes Made
Core Implementation
OpenApiReference
:default
,title
,deprecated
,readOnly
,writeOnly
,examples
OpenApiSchemaReference
properties to use the same override pattern asDescription
:Summary
property toOpenApiSchemaReference
for completenessSerialization & Deserialization
$ref
(correct behavior, annotations not supported)Example Usage
JSON Schema 2020-12 Compliance
Supports the metadata vocabulary as defined in the JSON Schema specification:
title
- Short description of the datadescription
- Longer description with CommonMark supportdefault
- Default value for the schemadeprecated
- Indicates if the schema is deprecatedreadOnly
- Indicates if the property is read-onlywriteOnly
- Indicates if the property is write-onlyexamples
- Example values for the schemaTesting
OpenAPI Output Examples
OpenAPI 3.1 (with annotations):
OpenAPI 3.0 (reference only):
This enables the ASP.NET Core scenario mentioned in the issue where XML comments can be used to apply rich metadata annotations to schema references, providing better API documentation and tooling support.
Fixes #2369.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.