Rswag nested objects, rswag syntax
Asked Answered
D

1

11

I have a project where I have nested objects. I have tried to figure out the correct syntax for nested array. This is something that I have tired (among of the many other things):

parameter name: :measurement, in: :body, schema: {
  type: :object,
  properties: {
    measurement_code: { type: :string },
  },
  type: :array_of_objects,
  measure: { type: :array },
  items: {
    value: { type: :integer }
    name: { type: :string }
    id: { type: :integer }
  },
  required: []
}

The example data that I am sending:

{"measurement_code"=>"918031199-7",
 :measure=>
  [
    {
    "id": 1,
    "value": 8049,
    "name": "Temporibus quam et ipsum blanditiis hic."
    },
    {
    "id": 2,
    "value": 76060,
    "name": "Sint omnis."
    }]
  }
}
Daumier answered 15/6, 2018 at 7:12 Comment(5)
Can you give the exact issue you're encountering with this syntax - error message, warning, etc?Chutzpah
I think I am too far away form the correct syntax. There is very little documentation in rswag and actual swagger syntax seems to be a bt different.Daumier
Thanks @Chutzpah sending me to debug and google one more round :D. This solved my problem: #26207185. Correct solution added to original question.Daumier
Excellent, good job! You can post an answer with your findings yourself and accept it as correct if you like, or vote to close this question as a duplicate if it's too close to the one you found your solution in.Chutzpah
Yes, thanks for the proposal @waldrumpus. Stack overflow newbie here. First question..Daumier
D
11

This works as the rswag syntax for array of objects:

  properties: {
    measurement_code: { type: :string },
    measure: {
      type: :array,
      items: {
        properties: {
          value: { type: :integer },
          name: { type: :string },
          id: { type: :integer }
        }
      },
    },
  }
Daumier answered 15/6, 2018 at 8:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.