guzzle / guzzle-services

Provides an implementation of the Guzzle Command library that uses Guzzle service descriptions to describe web services, serialize requests, and parse responses into easy to use model structures.
MIT License
253 stars 78 forks source link

Anyone interested in patternProperties support ? #103

Closed guillemcanal closed 2 years ago

guillemcanal commented 8 years ago

Hello guys,

So what are patternProperties you may ask ?
Well it's part of the JSON Schema specification, and it allow one developper to describe objects with unpredictable keys.

Unlike additionalProperties, you can add constraints to your object member names (property name) using a regular expression.

Like properties, you can associate each patternProperties keys with a schema.

Consider the following example:

{
    "data": {
        "foo_1": 1,
        "foo_2": 2,
        "foo_3": 3
    }
}

Many of you (myself included) may consider this bad design, but when it come to legacy APIs, or poorly designed services, we still need a way to validate such a payload.

So here, the foo object contains keys that:

Here is the Guzzle service schema that satisfy those requirements:

{
    "operation": {
        "GetFoo": {
            "httpMethod": "GET",
            "responseClass": "FooResponse"
        }
    },
    "models": {
        "FooResponse": {
            "type": "object",
            "properties": {
                "data": {"$ref": "FooList"}
            }
        },
        "FooList": {
            "type": "object",
            "location": "json",
            "additionalProperties": false,
            "patternProperties": {
                "^foo_[0-9]+$": {"type": "integer"}
            }
        }
    }
}

What do you guys think ?

Long story short, I already implemented this feature in guzzle3 (the company I'm working at have some trouble upgrading their PHP 5.3 ^^ ), but since the project is deprecated, I though it might be of some interest to port this feature in guzzle-services.

GrahamCampbell commented 2 years ago

Closing since stale - I'm doing a cleanup across the whole organization, to enable us to focus on the tickets that are still live and have interest. Please feel free to open a new issue if this still is important to you. :)