Forum Discussion

poopsy's avatar
poopsy
New Contributor
5 years ago

How to create spec for Object with Sub-Objects with variable names? See example request body inside

Hi there,

to clarify, here is the kind of Request Body I would like to spec out:

 

{
  "event" : "eventname",
  "payload" : {
    "Customer" : {
      "Mail" : "user@domain.invalid",
      "Firstname" : "Lorem ipsum",
      "Lastname" : "Lorem ipsum",
    },
    "Shop" : {
      "ShopUrl" : "Lorem ipsum",
    }
  }
}

 

The problem ist, the objects in the "payload" object should be variable - so not just necessarily "Customer" and "Shop", but variable object names and a variable number of objects.

 

I've tried to implement an API spec for this for the last 3 hours or so, but I'm getting nowhere. I'm wondering if this is even possible that way?

 

Any help would be greatly appreciated.

  • "payload" is a string-to-object dictionary. Dictionaries are defined as follows:

    payload:
      type: object
      additionalProperties:
        type: object

     

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    "payload" is a string-to-object dictionary. Dictionaries are defined as follows:

    payload:
      type: object
      additionalProperties:
        type: object

     

    • poopsy's avatar
      poopsy
      New Contributor

      Ah, that seems to do exactly what I was looking for - thanks a lot! HKosova 

      • kishanbora's avatar
        kishanbora
        New Contributor

        Our server has swagger 2.0 specs. Will this work with it also? Meaning any concerns on client side SDK code generation? Thanks in advance.