Conversation
…erties extension for OpenAPI v2/v3.0 serialization
- Add PatternPropertiesExtension constant ("x-jsonschema-patternProperties")
- Emit extension when serializing to OpenAPI v2.0 or v3.0 and PatternProperties is non-empty
- Parse the extension back into PatternProperties when deserializing v2.0 or v3.0 documents
- Add unit tests for both serialization and deserialization round-trip
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Preserve PatternProperties in OpenAPI 3.0 serialization
feat(library): Preserve PatternProperties via x-jsonschema-patternProperties extension for OpenAPI v2/v3.0
Mar 4, 2026
baywet
approved these changes
Mar 4, 2026
|
adrian05-ms
approved these changes
Mar 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



OpenApiSchema.PatternPropertieswas silently dropped during serialization to OpenAPI v2.0 and v3.0. This PR preserves the semantic intent via thex-jsonschema-patternPropertiesvendor extension (consistent with the existingx-jsonschema-unevaluatedPropertiespattern), and restores the property during deserialization when the extension is present.Description
patternPropertiesis not part of the OpenAPI v2.0 or v3.0 schema dialect, but the library's object model supports it. Previously, any schema withPatternPropertiesset would silently lose that data when serialized to those versions. This change round-trips the value via a vendor extension for v2/v3.0, leaving v3.1/v3.2 behavior unchanged.Serialization (v2.0 and v3.0 only):
{ "type": "object", "x-jsonschema-patternProperties": { "^[a-z][a-z0-9_]*$": { "type": "integer", "format": "int32" } } }Deserialization: reading
x-jsonschema-patternPropertiesin a v2/v3.0 document populatesPatternPropertiesdirectly (not stored as a raw extension).Type of Change
Changes Made
OpenApiConstants: AddedPatternPropertiesExtension = "x-jsonschema-patternProperties"OpenApiSchema.SerializeInternal: Emits the extension whenPatternPropertiesis non-empty and version < 3.1OpenApiSchema.SerializeAsV2: Same, for v2.0 serialization pathReader/V2/OpenApiSchemaDeserializer: Addedx-jsonschema-patternPropertiesas a fixed field that directly populatesPatternProperties(takes precedence over the genericx-extension handler)Reader/V3/OpenApiSchemaDeserializer: Same for v3.0PublicAPI.Unshipped.txt: Registered new public constantTesting
Tests added:
SerializePatternPropertiesAsKeywordInV31AndV32— no behavior change in v3.1+SerializePatternPropertiesAsExtensionInEarlierVersions— extension emitted for v2.0/v3.0SerializeEmptyPatternPropertiesNotEmittedInEarlierVersions— no extension emitted for empty mapDeserializePatternPropertiesExtensionInV2AssignsPatternPropertiesProperty— round-trip v2.0DeserializePatternPropertiesExtensionInV3AssignsPatternPropertiesProperty— round-trip v3.0Checklist
Versions applicability
Additional Notes
Follows the same pattern established by
x-jsonschema-unevaluatedProperties. The extension namex-jsonschema-patternPropertiesexplicitly signals JSON Schema keyword preservation and avoids collision with other tooling extensions.Original prompt
This section details on the original issue you should resolve
<issue_title>OpenAPI 3.0: Preserve PatternProperties via Vendor Extension during Serialization</issue_title>
<issue_description>## Summary
When generating OpenAPI 3.0 documents using OpenAPI.NET, schemas that define
PatternPropertieslose their semantic meaning during serialization.Currently, the serializer either:
additionalProperties: false, which is semantically incorrect fordictionary-like schemas with patterned keys.
This issue proposes preserving
PatternPropertiesin a spec-compliant wayfor OpenAPI 3.0 by emitting a vendor extension, while keeping a reasonable
fallback for standard tooling.
Background
patternPropertiesis a core JSON Schema feature that has existed since earlydrafts and is fully supported in:
However, OpenAPI 3.0 uses a restricted schema dialect and does not
support
patternProperties.OpenAPI.NET already exposes:
but this information is effectively lost when serializing to OpenAPI 3.0.
Current Behavior
Given a schema intent like:
{ "type": "object", "patternProperties": { "^[a-z][a-z0-9_]*$": { "type": "integer", "format": "int32" } } }OpenAPI 3.0 serialization may produce:
{ "type": "object", "additionalProperties": false }This output is:
Expected / Proposed Behavior
When serializing OpenAPI 3.0 and
OpenApiSchema.PatternPropertiesis present:1. Preserve semantic intent using a vendor extension
Emit a vendor extension such as:
Vendor extensions are explicitly allowed in OpenAPI 3.0 and are the only
spec-compliant mechanism to preserve this information.
2. Provide a best-effort OpenAPI 3.0 fallback
Additionally emit one of the following (depending on feasibility):
If all pattern properties share the same schema:
Otherwise:
This ensures existing OpenAPI 3.0 tooling continues to function predictably,
while advanced consumers can still read the extension.
Non-Goals
patternPropertiesa first-classOpenAPI 3.0 keyword (that would be non-spec).
Scope of Change
OpenApiSpecVersion.OpenApi3_0Benefits
Suggested Extension Name
Rationale:
References
OpenAPI 3.0 Vendor Extensions
https://swagger.io/docs/specification/v3_0/openapi-extensions/
OpenAPI 3.1 JSON Schema Alignment
https://spec.openapis.org/oas/v3.1.0.html
JSON Schema
patternPropertieshttps://json-schema.org/understanding-json-schema/reference/object.html#pattern-properties
Closing Notes
This change would allow OpenAPI.NET to preserve important schema semantics
without violating the OpenAPI 3.0 specification, and without requiring users
to fork or post-process the library output.
Thank you for considering this enhancement.
</issue_description>
<agent_instructions>implement a fix for this issue.
start by defining unit tests first.
we want the pattern properties property to be serialized as an extension (x-jsonSchema-...) when it's assigned and when we're serializing to v2 or v3. For 3.1 or 3.2 it should remain serialized as it is.
During deserialization, if that extension is present, we should read it and assign the property for those two versions specifically.</agent_instructions>
Comments on the Issue (you are @copilot in this section)
@baywet Hi @mdaneri Thank you for using the SDK and for reaching out.This is something we have precedent for, look for x-oai in the repository. The only "question" I have is the extension name: should we align on x-oai for consistency so users know they are "compatibility" properties at glance, or should we introduce the jsonschema suggestion you've made, so users know where this is sourced from? I do...
💡 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.