Skip to content

Commit 74f0e2d

Browse files
committed
Adds logic for serializing the Pattern Properties object in a JSON schema
1 parent 92bf348 commit 74f0e2d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System;
55
using System.Collections.Generic;
66
using System.IO;
7+
using System.Linq;
78
using System.Text.Json;
9+
using System.Text.RegularExpressions;
810
using Json.Schema;
911
using Json.Schema.OpenApi;
1012
using Microsoft.OpenApi.Any;
@@ -536,6 +538,16 @@ public void WriteJsonSchemaWithoutReference(IOpenApiWriter writer, JsonSchema sc
536538
writer.WriteOptionalMap(OpenApiConstants.Properties, (IDictionary<string, JsonSchema>)schema.GetProperties(),
537539
(w, key, s) => w.WriteJsonSchema(s, version));
538540

541+
// pattern properties
542+
var patternProperties = schema?.GetPatternProperties();
543+
var stringPatternProperties = patternProperties?.ToDictionary(
544+
kvp => kvp.Key.ToString(), // Convert Regex key to string
545+
kvp => kvp.Value
546+
);
547+
548+
writer.WriteOptionalMap(OpenApiConstants.PatternProperties, stringPatternProperties,
549+
(w, key, s) => w.WriteJsonSchema(s, version));
550+
539551
// additionalProperties
540552
if (schema.GetAdditionalPropertiesAllowed() ?? false)
541553
{

0 commit comments

Comments
 (0)