Repository navigation
OpenAPI 3.0: Preserve PatternProperties via Vendor Extension during Serialization #2716
Description
Summary
When generating OpenAPI 3.0 documents using OpenAPI.NET, schemas that define
PatternProperties lose their semantic meaning during serialization.
Currently, the serializer either:
- drops the information entirely, or
- emits
additionalProperties: false, which is semantically incorrect for
dictionary-like schemas with patterned keys.
This issue proposes preserving PatternProperties in a spec-compliant way
for OpenAPI 3.0 by emitting a vendor extension, while keeping a reasonable
fallback for standard tooling.
Background
patternProperties is a core JSON Schema feature that has existed since early
drafts and is fully supported in:
- JSON Schema (all modern drafts)
- OpenAPI 3.1+ (which aligns with JSON Schema 2020-12)
However, OpenAPI 3.0 uses a restricted schema dialect and does not
support patternProperties.
OpenAPI.NET already exposes:
OpenApiSchema.PatternPropertiesbut 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:
- syntactically valid OpenAPI 3.0
- semantically incorrect, because it forbids all dynamic keys
Expected / Proposed Behavior
When serializing OpenAPI 3.0 and OpenApiSchema.PatternProperties is present:
1. Preserve semantic intent using a vendor extension
Emit a vendor extension such as:
"x-jsonSchema-patternProperties": {
"^[a-z][a-z0-9_]*$": {
"type": "integer",
"format": "int32"
}
}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:
"additionalProperties": { "type": "integer", "format": "int32" }
-
Otherwise:
"additionalProperties": true
This ensures existing OpenAPI 3.0 tooling continues to function predictably,
while advanced consumers can still read the extension.
Non-Goals
- This proposal does not attempt to make
patternPropertiesa first-class
OpenAPI 3.0 keyword (that would be non-spec). - This proposal does not change OpenAPI 3.1+ behavior.
Scope of Change
- Affects serialization only
- Only for
OpenApiSpecVersion.OpenApi3_0 - No changes to the public object model
- No breaking changes
Benefits
- Prevents silent loss of schema semantics
- Produces valid OpenAPI 3.0 output
- Allows downstream tools to recover JSON Schema intent
- Aligns with OpenAPI’s intended use of vendor extensions
Suggested Extension Name
x-jsonSchema-patternProperties
Rationale:
- Explicitly indicates JSON Schema keyword preservation
- Avoids ambiguity with standard OpenAPI fields
- Minimizes risk of collision with other extensions
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
patternProperties
https://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.
Activity
baywet commentedon Feb 3, 2026
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 don't have a strong opinion either way. Maybe jsonschema would be more beneficial if we're anticipating more instances like those. In which case I'll request this aspect is documented somewhere.
Is this something you'd like to submit a pull request for provided some guidance?
baywet commentedon Feb 17, 2026
As a follow up #2727 is another instance of this, let's use json schema here.
baywet commentedon Feb 17, 2026
baywet commentedon Feb 17, 2026
Actually, nevermind the previous answer, both OpenAPI v2.0, and 3.0 select a subset of supported keywords. So it'll need to be an extension for those two versions
mdaneri commentedon Feb 17, 2026
Vincent Biret (@baywet) Tomorrow I'll try to implement it
baywet commentedon Feb 19, 2026
mdaneri FYI I'm holding release #2733 for this fix. Let me know if you don't think you'll be able to work on that in the next few days in which case I'll ship the release and we'll ship a subsequent one.