Git Product home page Git Product logo

Comments (5)

vanderlee avatar vanderlee commented on June 19, 2024

That's a good idea!

From the top of my head, I don't know if the Swagger/Open-API spec permits this type of referencing. If it does, than implementing it should be easy. If it does not, it could still be implemented but will take a bit more effort.

The current "support" for array references is probably a bug; this was not intentional and has to do with the way SG handles types. Could you describe what you think the result should be and what SG currently generates?

I'll try to find some time this weekend to look into this.

from phpswaggergen.

tecnom1k3 avatar tecnom1k3 commented on June 19, 2024

I think Swagger does permit, at least at swagger editor. Consider the following yaml:

swagger: '2.0'
info:
  title: API
  description: Description
  version: "1.0"
host: myhost.com
schemes:
  - https
basePath: /
consumes:
  - application/json
produces:
  - application/json
paths:
  /stations:
    get:
      description: |
        Returns list of station for a given supplier id.
      responses:
        200:
          description: An Object defining response from Station
          schema:
              $ref: '#/definitions/Stations'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'
definitions:
  Error:
    type: object
    properties:
      code:
        type: integer
        format: int32
      message:
        type: string
      fields:
        type: string
  Address:
    description: Object defining Address.
    properties:
      address_line1:
        type: string
      address_line2:
        type: string
      city:
        type: string
      state:
        type: string
      postal_code:
        type: string
      country_code:
        type: string
      phone:
        type: string
      fax:
        type: string
  Stations:
    type: array
    items:
      $ref: '#/definitions/Station'
  Station:
    description: Detailsof station.
    properties:
      id:
        type: integer
      name:
        type: string
      address:
        $ref: '#/definitions/Address'

As you can see, the Stations schema contains and array of Station objects (that is why I was expecting that @rest\property array(address) to work fine). At the same time, Station contains a reference to the address object. This way, editor.swagger.io does not complaints and produces the following output:

image

I can get SG to generate an array of referenced objects, but fail to generate a referenced object within another referenced object.

Hope this helps, please let me know if you need additional information. I would like to contribute, but at this time I find myself with very limited time :( I'm also attaching YAML above converted to JSON

Thanks!
swagger (1).json.zip

from phpswaggergen.

vanderlee avatar vanderlee commented on June 19, 2024

This was a pretty simple fix, adding some useful functionality.
Thanks for the issue and all the example code, which greatly helped finding and fixing this issue.
Fix and unittest coverage included in 2.3.7
Please let me know if this works for you.

from phpswaggergen.

tecnom1k3 avatar tecnom1k3 commented on June 19, 2024

Awesome!

Will update and test, and will let you know.

from phpswaggergen.

tecnom1k3 avatar tecnom1k3 commented on June 19, 2024

Confirming the generated docs work as expected in the swagger editor using version 2.3.7. Thanks

from phpswaggergen.

Related Issues (19)

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.