Skip to content

Commit b0a0e8e

Browse files
committed
Add const keyword and serialization logic
1 parent 0bf5a42 commit b0a0e8e

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/Microsoft.OpenApi/Models/OpenApiConstants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public static class OpenApiConstants
5050
/// </summary>
5151
public const string Title = "title";
5252

53+
/// <summary>
54+
/// Field: Const
55+
/// </summary>
56+
public const string Const = "const";
57+
5358
/// <summary>
5459
/// Field: Type
5560
/// </summary>

src/Microsoft.OpenApi/Models/OpenApiSchema.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ public class OpenApiSchema : IOpenApiAnnotatable, IOpenApiExtensible, IOpenApiRe
8383
/// </summary>
8484
public virtual JsonSchemaType? Type { get; set; }
8585

86+
/// <summary>
87+
/// Follow JSON Schema definition: https://json-schema.org/draft/2020-12/json-schema-validation
88+
/// </summary>
89+
public virtual string Const { get; set; }
90+
8691
/// <summary>
8792
/// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00
8893
/// While relying on JSON Schema's defined formats,
@@ -347,6 +352,7 @@ public OpenApiSchema(OpenApiSchema schema)
347352
{
348353
Title = schema?.Title ?? Title;
349354
Id = schema?.Id ?? Id;
355+
Const = schema?.Const ?? Const;
350356
Schema = schema?.Schema ?? Schema;
351357
Comment = schema?.Comment ?? Comment;
352358
Vocabulary = schema?.Vocabulary != null ? new Dictionary<string, bool>(schema.Vocabulary) : null;
@@ -563,6 +569,7 @@ internal void WriteV31Properties(IOpenApiWriter writer)
563569
writer.WriteProperty(OpenApiConstants.Id, Id);
564570
writer.WriteProperty(OpenApiConstants.DollarSchema, Schema);
565571
writer.WriteProperty(OpenApiConstants.Comment, Comment);
572+
writer.WriteProperty(OpenApiConstants.Const, Const);
566573
writer.WriteOptionalMap(OpenApiConstants.Vocabulary, Vocabulary, (w, s) => w.WriteValue(s));
567574
writer.WriteOptionalMap(OpenApiConstants.Defs, Definitions, (w, s) => s.SerializeAsV31(w));
568575
writer.WriteProperty(OpenApiConstants.DynamicRef, DynamicRef);

src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ internal OpenApiSchemaReference(OpenApiSchema target, string referenceId)
9090
/// <inheritdoc/>
9191
public override JsonSchemaType? Type { get => Target.Type; set => Target.Type = value; }
9292
/// <inheritdoc/>
93+
public override string Const { get => Target.Const; set => Target.Const = value; }
94+
/// <inheritdoc/>
9395
public override string Format { get => Target.Format; set => Target.Format = value; }
9496
/// <inheritdoc/>
9597
public override string Description

0 commit comments

Comments
 (0)