Giter Club home page Giter Club logo

Comments (6)

hassankhan avatar hassankhan commented on May 7, 2024

I was pointed to this: https://github.com/Rarst/wporg-client/blob/33fb0dcce9f170b92824d09f5717ca814d7ecd29/php/WporgService.php and it worked for me :)

from guzzle-services.

wirtsi avatar wirtsi commented on May 7, 2024

Still, I don't see why the first approach should not work. I mean clearly the outer structure should be marked as an array, but then this array consists of the given models.

This maybeToArray seems like a very odd solution to me...

from guzzle-services.

hassankhan avatar hassankhan commented on May 7, 2024

I know, but in the absence of any decent documentation this was the only solution I could find. If you could find a better solution, I would love to see it 😄

from guzzle-services.

wirtsi avatar wirtsi commented on May 7, 2024

Hey ... just figured it out. You need to use "location" => "json" on the array definition. So for my use case this works

$description = new Description([
    'baseUrl' => 'http://localhost',
    'operations' => [
        'facets' => [
            'httpMethod' => 'GET',
            'uri' => 'fakeapi/facets.json',
            'responseModel' => 'Facets',
        ],
        'facet' => [
            'httpMethod' => 'GET',
            'uri' => 'fakeapi/facet.json',
            'responseModel' => 'Facet'
        ]
    ],
    'models' => [
        "Facet" => [
            "type" => "object",
            "properties" => [
                "id" => [
                    "location" => "json",
                    "type" => "int"
                ],
                "group_name" => [
                    "location" => "json",
                    "type" => "string"
                ],
                "name" => [
                    "location" => "json",
                    "type" => "string"
                ],
                "facet_id" => [
                    "location" => "json",
                    "type" => "int"
                ],
            ]
        ],
        'Facets' => [
            "type" => "array",
            "location" => "json",
            "items" => [
                "type" => "object",
                '$ref' => "Facet"
            ]
        ]
    ]
]);
$guzzle = new GuzzleClient($client, $description);

$command = $guzzle->getCommand('facets');

$result = $guzzle->execute($command);

Data in facet.json is

{
  "id": 257,
  "group_name": "material",
  "name": "Foo",
  "value": "Bar",
  "facet_id": 3606
}

and facets.json is an array of these

from guzzle-services.

matks avatar matks commented on May 7, 2024

I did not succeed to use the maybeToArray function suggested by @hassankhan but @wirtsi answer did work for my case. Thanks !

from guzzle-services.

Konafets avatar Konafets commented on May 7, 2024

I close the issue because it seems to be solved. Please reopen the issue if you have any further questions or the the issue is not solved in your opinion.

from guzzle-services.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.