Support for patternProperties in Signatures solves dynamic Transport Keys #224
sebastiandemel
started this conversation in
Ideas
Replies: 1 comment
-
|
I have a few comments and questions from my brief skim:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Examples and discussion on how
patternProperties(see example use here) support in Moonwalk signature objects solves the long-lasting problem of dynamic Headers, Query, Cookies and Path parameters.Problem
The OpenAPI 3.x specification restricts transport blocks (headers, queries, cookies) to strict maps of explicitly named parameters. This limitation prevents the accurate description and validation of APIs utilizing dynamic, pattern-based keys.
Currently, API producers rely on out-of-band documentation,
x-extensions, or serialization workarounds (likedeepObjectfor queries) to describe these patterns.Some real-world patterns:
X-Amz-Meta-<Key>), gRPC transcoding metadata (Grpc-Metadata-<Key>), or multi-tenant routing (X-Tenant-<ID>).filter[<field>]=<value>), sorting (sort[<field>]=asc), or sparse fieldsets (fields[<resource>]=<field>).session_<tenant_id>) or partitioned analytics trackers (_tracker_<domain_hash>)./map/lat=<val>;lon=<val>) or dynamic wildcard path segment mapping.How
patternPropertiesfixes thisMoonwalk's architecture separates pure data schemas from HTTP interactions. Because of this, we can treat incoming HTTP transport blocks (like
headers,queries, andcookies) simply as JSON objects that are evaluated by JSON Schema.By adopting standard JSON Schemas
patternPropertieswe gain a native, canonical mechanism for validating dynamic transport keys.Sample: Metadata with GET requests
In this sample, a client is fetching metadata via a GET request. Because GET requests should not have a body (RFC 9110), dynamic data such as custom metadata headers and dynamic query filters must be passed via the transport layer.
Sample: Stream upload
Sample shows a client is uploading a raw binary stream. Because the HTTP body is entirely occupied by the binary file, user-defined metadata must be passed dynamically via headers.
This approach requires no new custom x- extensions and naturally converges with ongoing Moonwalk efforts to model standard HTTP fields (Discussion #108) and adopt full RFC 6570 URI Templates for path routing (Discussion #127).
Full example: Storage Object Api
Here is a YAML schema that defines a Storage Object API as an example that combines URI Templating and other discussions with
patternPropertiesCombines the following discussions
Endpoint
Valid Deep-Path Retrieval
In this scenario, a client is fetching metadata for a deeply nested file. The request includes dynamic metadata headers and a dynamic filter.
Request:
How the Validator processes this:
Path:
The RFC 6570 router extracts
bucketIdasmedia-assetsand{+objectPath}asproduction/2026/marketing/banners/hero-v2.png. The regex in$defs/ObjectPathParametersconfirms this is a valid nested string.Headers:
if-matchproperty (case-insensitive mapping), then iterates through the remaining lowercase headers.x-object-meta-ownerandx-object-meta-project-idboth match thepatternPropertiesregex^x-object-meta-[a-z0-9\-]+$.hostpass through safely due toadditionalProperties: true.Query: The validator confirms the URL-decoded key
filter[department]matches the query regex.Cookies: The validator confirms
cdn_edge_token_...matches the regex. The unmodeled_gatracking cookie is ignored safely due toadditionalProperties: true.Response:
Invalid Key Validation (Header & Cookie Fail)
This example demonstrates a request that fails because it uses keys that do not match the required patterns, even though the transport location is correct.
Request:
The Resulting Error (Validation Rejection):
The API gateway or validator rejects this before it hits the application logic because the explicitly provided keys do not satisfy the patternProperties constraints.
Response
Assumptions
URL-Decoding of Transport Keys
We assume that schema validation applies to the parsed and URL-decoded key-value pairs of the query string and cookies, not the raw HTTP string. This avoids the validation failures that percent-encoding would otherwise cause.
For example, while a dynamic query is transmitted as
filter%5Bdepartment%5D, the schema validator evaluates the decodedfilter[department].Edge cases
1. The Case-Sensitivity Clash (Headers)
Problem: HTTP headers are strictly case-insensitive according to RFC 9110 (e.g.,
X-Object-Meta-Owneris identical tox-object-meta-owner). However, JSON Schema'spatternPropertiesuses ECMA-262 regular expressions, which are case-sensitive by default, and standard JSON Schema does not natively support inline regex flags like(?i).Solution: Tooling MUST normalize header keys to lowercase before applying the JSON Schema evaluation.
2. Support for
additionalProperties: falseProblem: While not specifically a problem with
patternProperties, it's worth mentioning that the use ofadditionalProperties: falsein headers can cause unintended rejections as clients tend to send implicit headers (such asHost,User-Agent,Accept, etc.). Similarly, clients (especially browsers) automatically append all domain-scoped cookies (like analytics trackers or CSRF tokens), even if the specific API endpoint does not require them.Solution: Tooling SHOULD warn of its use in headers and cookies, and the default value for
additionalPropertiesshould betrueto allow unmodeled transport data to safely pass through.Beta Was this translation helpful? Give feedback.
All reactions