Skip to content

Commit 82f84e0

Browse files
baywetCopilot
andcommitted
feat(library): add missing json schema properties
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 21488c6 commit 82f84e0

16 files changed

Lines changed: 862 additions & 31 deletions

src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte
260260
/// <summary>
261261
/// Indicates whether unevaluated properties are allowed. When false, no unevaluated properties are permitted.
262262
/// Follow JSON Schema definition: https://json-schema.org/draft/2020-12/json-schema-core#name-unevaluatedproperties
263-
/// Only serialized when false and UnevaluatedPropertiesSchema (from IOpenApiSchemaWithUnevaluatedProperties) is null.
263+
/// Only serialized when false and UnevaluatedPropertiesSchema (from IOpenApiSchemaMissingProperties) is null.
264264
/// </summary>
265265
/// <remarks>
266266
/// NOTE: This property differs from the naming pattern of AdditionalPropertiesAllowed for binary compatibility reasons.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System.Collections.Generic;
2+
3+
namespace Microsoft.OpenApi;
4+
5+
/// <summary>
6+
/// Compatibility interface for schema properties that cannot be added to <see cref="IOpenApiSchema"/>
7+
/// in the current major version without a breaking change.
8+
/// This interface provides access to those properties in contexts where callers need a typed model surface.
9+
/// </summary>
10+
/// <remarks>
11+
/// TODO: Remove this interface in the next major version and merge its content into IOpenApiSchema.
12+
/// </remarks>
13+
public interface IOpenApiSchemaMissingProperties
14+
{
15+
/// <summary>
16+
/// $anchor - identifies a plain-name location-independent fragment within the schema resource.
17+
/// </summary>
18+
public string? Anchor { get; }
19+
20+
/// <summary>
21+
/// Indicates whether unevaluated properties are allowed. When false, no unevaluated properties are permitted.
22+
/// Follow JSON Schema definition: https://json-schema.org/draft/2020-12/json-schema-core#name-unevaluatedproperties
23+
/// Only serialized when false and <see cref="UnevaluatedPropertiesSchema"/> is null.
24+
/// </summary>
25+
/// <remarks>
26+
/// NOTE: This property differs from the naming pattern of AdditionalPropertiesAllowed for binary compatibility reasons.
27+
/// In the next major version, this will be renamed to UnevaluatedPropertiesAllowed.
28+
/// TODO: Rename to UnevaluatedPropertiesAllowed in the next major version.
29+
/// </remarks>
30+
public bool UnevaluatedProperties { get; }
31+
32+
/// <summary>
33+
/// Follow JSON Schema definition: https://json-schema.org/draft/2020-12/json-schema-core#name-unevaluatedproperties
34+
/// This is a schema that unevaluated properties must validate against.
35+
/// When serialized, this takes precedence over the <see cref="UnevaluatedProperties"/> boolean property.
36+
/// </summary>
37+
/// <remarks>
38+
/// NOTE: This property differs from the naming pattern of AdditionalProperties/AdditionalPropertiesAllowed
39+
/// for binary compatibility reasons. In the next major version:
40+
/// - This property will be renamed to UnevaluatedProperties
41+
/// - The current boolean UnevaluatedProperties property will be renamed to UnevaluatedPropertiesAllowed
42+
///
43+
/// TODO: Rename this property to UnevaluatedProperties in the next major version.
44+
/// </remarks>
45+
public IOpenApiSchema? UnevaluatedPropertiesSchema { get; }
46+
47+
/// <summary>
48+
/// contentEncoding - identifies the encoding of string content.
49+
/// </summary>
50+
public string? ContentEncoding { get; }
51+
52+
/// <summary>
53+
/// contentMediaType - identifies the media type of string content.
54+
/// </summary>
55+
public string? ContentMediaType { get; }
56+
57+
/// <summary>
58+
/// contentSchema - provides a schema that describes the decoded string content.
59+
/// </summary>
60+
public IOpenApiSchema? ContentSchema { get; }
61+
62+
/// <summary>
63+
/// propertyNames - provides a schema that validates property names.
64+
/// </summary>
65+
public IOpenApiSchema? PropertyNames { get; }
66+
67+
/// <summary>
68+
/// dependentSchemas - maps property names to schemas that are applied when that property is present.
69+
/// </summary>
70+
public IDictionary<string, IOpenApiSchema>? DependentSchemas { get; }
71+
72+
/// <summary>
73+
/// if - applies a conditional schema that determines whether <see cref="Then"/> or <see cref="Else"/> should be evaluated.
74+
/// </summary>
75+
public IOpenApiSchema? If { get; }
76+
77+
/// <summary>
78+
/// then - applies when <see cref="If"/> evaluates successfully.
79+
/// </summary>
80+
public IOpenApiSchema? Then { get; }
81+
82+
/// <summary>
83+
/// else - applies when <see cref="If"/> does not evaluate successfully.
84+
/// </summary>
85+
public IOpenApiSchema? Else { get; }
86+
}

src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchemaWithUnevaluatedProperties.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
namespace Microsoft.OpenApi;
24

35
/// <summary>
@@ -13,6 +15,7 @@ namespace Microsoft.OpenApi;
1315
/// <remarks>
1416
/// TODO: Remove this interface in the next major version and merge its content into IOpenApiSchema.
1517
/// </remarks>
18+
[Obsolete("Use IOpenApiSchemaMissingProperties instead.")]
1619
public interface IOpenApiSchemaWithUnevaluatedProperties
1720
{
1821
/// <summary>

src/Microsoft.OpenApi/Models/OpenApiConstants.cs

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ public static class OpenApiConstants
9090
/// </summary>
9191
public const string Vocabulary = "$vocabulary";
9292

93+
/// <summary>
94+
/// Field: Anchor
95+
/// </summary>
96+
public const string Anchor = "$anchor";
97+
9398
/// <summary>
9499
/// Field: DynamicRef
95100
/// </summary>
@@ -131,9 +136,14 @@ public static class OpenApiConstants
131136
public const string UnevaluatedProperties = "unevaluatedProperties";
132137

133138
/// <summary>
134-
/// Extension: x-jsonschema-unevaluatedProperties
139+
/// Extension: x-oai-unevaluatedProperties
140+
/// </summary>
141+
public const string UnevaluatedPropertiesExtension = "x-oai-unevaluatedProperties";
142+
143+
/// <summary>
144+
/// Legacy extension: x-jsonschema-unevaluatedProperties
135145
/// </summary>
136-
public const string UnevaluatedPropertiesExtension = "x-jsonschema-unevaluatedProperties";
146+
public const string LegacyUnevaluatedPropertiesExtension = "x-jsonschema-unevaluatedProperties";
137147

138148
/// <summary>
139149
/// Field: Version
@@ -535,11 +545,51 @@ public static class OpenApiConstants
535545
/// </summary>
536546
public const string PatternProperties = "patternProperties";
537547

548+
/// <summary>
549+
/// Field: PropertyNames
550+
/// </summary>
551+
public const string PropertyNames = "propertyNames";
552+
538553
/// <summary>
539554
/// Extension: x-jsonschema-patternProperties
540555
/// </summary>
541556
public const string PatternPropertiesExtension = "x-jsonschema-patternProperties";
542557

558+
/// <summary>
559+
/// Field: DependentSchemas
560+
/// </summary>
561+
public const string DependentSchemas = "dependentSchemas";
562+
563+
/// <summary>
564+
/// Field: If
565+
/// </summary>
566+
public const string If = "if";
567+
568+
/// <summary>
569+
/// Field: Then
570+
/// </summary>
571+
public const string Then = "then";
572+
573+
/// <summary>
574+
/// Field: Else
575+
/// </summary>
576+
public const string Else = "else";
577+
578+
/// <summary>
579+
/// Field: ContentEncoding
580+
/// </summary>
581+
public const string ContentEncoding = "contentEncoding";
582+
583+
/// <summary>
584+
/// Field: ContentMediaType
585+
/// </summary>
586+
public const string ContentMediaType = "contentMediaType";
587+
588+
/// <summary>
589+
/// Field: ContentSchema
590+
/// </summary>
591+
public const string ContentSchema = "contentSchema";
592+
543593
/// <summary>
544594
/// Field: AdditionalProperties
545595
/// </summary>
@@ -790,6 +840,51 @@ public static class OpenApiConstants
790840
/// </summary>
791841
public const string DependentRequired = "dependentRequired";
792842

843+
/// <summary>
844+
/// Extension: x-oai-$anchor
845+
/// </summary>
846+
public const string AnchorExtension = "x-oai-$anchor";
847+
848+
/// <summary>
849+
/// Extension: x-oai-propertyNames
850+
/// </summary>
851+
public const string PropertyNamesExtension = "x-oai-propertyNames";
852+
853+
/// <summary>
854+
/// Extension: x-oai-dependentSchemas
855+
/// </summary>
856+
public const string DependentSchemasExtension = "x-oai-dependentSchemas";
857+
858+
/// <summary>
859+
/// Extension: x-oai-if
860+
/// </summary>
861+
public const string IfExtension = "x-oai-if";
862+
863+
/// <summary>
864+
/// Extension: x-oai-then
865+
/// </summary>
866+
public const string ThenExtension = "x-oai-then";
867+
868+
/// <summary>
869+
/// Extension: x-oai-else
870+
/// </summary>
871+
public const string ElseExtension = "x-oai-else";
872+
873+
/// <summary>
874+
/// Extension: x-oai-contentEncoding
875+
/// </summary>
876+
public const string ContentEncodingExtension = "x-oai-contentEncoding";
877+
878+
/// <summary>
879+
/// Extension: x-oai-contentMediaType
880+
/// </summary>
881+
public const string ContentMediaTypeExtension = "x-oai-contentMediaType";
882+
883+
/// <summary>
884+
/// Extension: x-oai-contentSchema
885+
/// </summary>
886+
public const string ContentSchemaExtension = "x-oai-contentSchema";
887+
793888
#region V2.0
794889

795890
/// <summary>

0 commit comments

Comments
 (0)