Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the proper way to define different object structures inside an array schema? #119

Open
TheeGrassHopper opened this issue Oct 2, 2018 · 1 comment

Comments

@TheeGrassHopper
Copy link

TheeGrassHopper commented Oct 2, 2018

I hope this is a legit question, I searched everywhere for an example or any source of information on how to do this. I tried this #17 as well. But the same result.

The end result I would like to get generated is below:

{
  "name": "Awesome Promotion",
  "description": "30% off",
  "qualifiers": [
      {
         "id": 12,
         "type": "Rental"
      },
      {
          "id": 13,
          "type": "Qualifier",
          "user_id": 23
      },
      {
          "id": 14,
          "type": "First",
          "location_id": 32 
      }
  ]

I have the model writen out like this:

swagger_schema :PromotionResponse do
      property :name, type: :string, example: 'Awesome Promotion'
      property :description, type: :string, example: '30% off'
      property :qualifiers do
        key :type, :array
        items do
          property :id, type: :integer, example: 2
          property :type, type:  :string, exmple: 'Location'
        end
      end
    end

What gets generated by swagger right now:

{
  "name": "Awesome Promotion",
  "description": "30% off",
  "qualifiers": [
    {
      "id": 2,
      "type": "Location"
    }
  ]
}

What is the proper way to define different object structures inside an array schema?

@thegreyfellow
Copy link

Hi, I'm not sure if this is helping but if I were in your place, I would have added user_id, location_id or any other key into the items do end block and define id and type as required properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants