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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for Multiple `type` Options within Response Models

GuyPaddock opened this issue · comments

We are writing a client to wrap a vendor-supplied REST API. One of the values that the API returns can be either null, a scalar string value, or an array of strings. I'm trying to model this as follows:

models:
  AssetMetadataResponse:
    type: 'object'
    location: 'json'
    properties:
      data:
        type: 'array'
        required: true
        items:
          type: 'object'
          properties:
            attribute_id:
              type: 'integer'
              required: true
              minimum: 1
            value:
              type:
                # FIXME: Guzzle does not handle this correctly
                - 'null'
                - 'string'
                - 'array'
              items:
                type: 'string'

This causes problems, because it appears that \GuzzleHttp\Command\Guzzle\ResponseLocation\JsonLocation::recurse does not handle the case where type is an array of types rather than a single type. This causes arrays of values to come through as empty arrays.

I'd love it if Guzzle Services was able to support responses that have fields that can vary in type. Even better would be if Guzzle Services had a construct like JSON Schema's oneOf, where I can model each permutation of the data fields separately.