Giter VIP home page Giter VIP logo

Comments (11)

zircote avatar zircote commented on August 30, 2024

@pietervogelaar could you elaborate in detail the request? I am familiar with HAL however I am not clear with regards to what you require from Swagger to support it.

from swagger-php.

pietervogelaar avatar pietervogelaar commented on August 30, 2024

At the moment a property in a model can have multiple models. For example a user can have multiple contacts.

The response in JSON for a user will be:

{
    "id": "matthew",
    "name": "Matthew Weier O'Phinney",
    "contacts": [
       {
            "id": "mac_nibblet",
            "name": "Antoine Hedgecock"
      }, 
      {
          "id": "spiffyjr",
          "name": "Kyle Spraggs"
      }
   ]
}

But for HAL the response below is desired:

{
    "_links": {
        "self": {
            "href": "http://example.org/api/user/matthew"
        }
    }
    "id": "matthew",
    "name": "Matthew Weier O'Phinney",
    "_embedded": {
        "contacts": [
            {
                "_links": {
                    "self": {
                        "href": "http://example.org/api/user/mac_nibblet"
                    }
                },
                "id": "mac_nibblet",
                "name": "Antoine Hedgecock"
            },
            {
                "_links": {
                    "self": {
                        "href": "http://example.org/api/user/spiffyjr"
                    }
                },
                "id": "spiffyjr",
                "name": "Kyle Spraggs"
            }
        ],
        "website": {
            "_links": {
                "self": {
                    "href": "http://example.org/api/locations/mwop"
                }
            },
            "id": "mwop",
            "url": "http://www.mwop.net"
        },
    }
}

I think the annotations can stay the same, but the swagger bin should have a flag "hal_enabled" or something. So that child models will be enclosed in a "_embedded" key.

The _links key requires some annotation I think.

from swagger-php.

Bazze avatar Bazze commented on August 30, 2024

I agree, we would really need to get some support for JSON HAL into Swagger in order to be able to show the expected response in a correct way.

from swagger-php.

AndreBaumeier avatar AndreBaumeier commented on August 30, 2024

any progress on this?

from swagger-php.

soejima avatar soejima commented on August 30, 2024

Hi, folks! How are you? We also need this support in a project, does anyone have some new on this issue? Thank you, very much!

from swagger-php.

Jmeyering avatar Jmeyering commented on August 30, 2024

👍

from swagger-php.

nnnnathann avatar nnnnathann commented on August 30, 2024

+1

I am also struggling to figure out how to support JSON-API schema as well, seems support for arbitrarily nested attribute objects is not straight forward unless I'm missing something.

i.e. how would I support this response:

{
  "data": [
    {
      "id": 1,
      "type": "pet",
      "attributes": {
        "id": 1,
        "name": "Dog"
      },
      "links": {
        "count": "/pets/1/count"
      }
    }
  ]
}

from swagger-php.

adambro avatar adambro commented on August 30, 2024

@nnnnathann got similar issue with nested object. I've just created a class for each object in JSON and marked them in phpdoc annotations. Example based on your JSON:

class Pet {
  /** @var PetAttrs */
  var $attributes;
}

class PetAttrs {
  var $id;
  var $name;
}

from swagger-php.

AaronJan avatar AaronJan commented on August 30, 2024

@adambro @nnnnathann for nested definition, you can check this out. 😃

from swagger-php.

babarizbak avatar babarizbak commented on August 30, 2024

+1 for HAL support.

from swagger-php.

bfanger avatar bfanger commented on August 30, 2024

HAL support is outside the scope of the swagger-php project.

Feel free to experiment and create a swagger-php plugin, i'll gladly add that to the related projects page

from swagger-php.

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.