Skip to content

Hasmaps payloads #593

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

Closed
gedaiu opened this issue Mar 8, 2016 · 12 comments
Closed

Hasmaps payloads #593

gedaiu opened this issue Mar 8, 2016 · 12 comments

Comments

@gedaiu
Copy link

gedaiu commented Mar 8, 2016

parent issue #579

I would be nice to be able to define hashmaps payloads.

I have an use case in an app, where I want to send a list of variables, defined by user. With the 2.0 spec, there is no way of defining a schema object that can contains any key like a Json object...

@ePaul
Copy link
Contributor

ePaul commented Mar 8, 2016

Update: This answer is not helpful, as I misunderstood the question. The values are meant to be anything, not the keys.)


I guess one reason for this is that JSON allows only String keys in key-value pairs in a object.

A possible workaround would be to use an array with "pair" objects, which works already now:

definitions:
  my_hashmap:
    type: array
    items:
      type: object
      properties:
        key:
          # your key type, for example
         type: object
         properties:
            name: string
       value:
          # your value type, for example
         type: object
         properties:
           example: integer

A value of this type could look like this:

[ {"key": { "name": "Paul" }, "value": { "example": 42 } },
  {"key": { "name": "gedaiu" }, "value": { "example": 17 } } ]

@DavidBiesack
Copy link

1+; we have several cases where we want to allow an arbitrary attributes object of name/value pairs. We're happy with just string keys but desire values being scalars, arrays or nested maps.

@webron
Copy link
Member

webron commented Mar 8, 2016

Isn't that supported by additionalProperties?

@gedaiu @DavidBiesack can you provide a sample of such payload? Not a schema of it, just what you want to payload to be.

@gedaiu
Copy link
Author

gedaiu commented Mar 8, 2016

@webron yes, here it is my case:

{
   "id": "0",
   "name": "process1",
   "variables": {
       "seconds": 3600,
       "hours": 30,
       "any other string": 0,
   }
}

where variables is my hash map

@webron
Copy link
Member

webron commented Mar 8, 2016

Are any properties in that payload arbitrary? If not, there's no problem describing that with the current version of the spec.

@gedaiu
Copy link
Author

gedaiu commented Mar 9, 2016

@webron sorry... maybe my comment was not that clear... the variables object can have any property. I don't know how to give a better example...

@webron
Copy link
Member

webron commented Mar 9, 2016

@gedaiu then you just define variables as this:

variables:
  type: object
  additionalProperties: {}

If you want to limit the type of the variables, say to integers:

variables:
  type: object
  additionalProperties:
    type: integer

This is supported by the current version of the spec.

@gedaiu
Copy link
Author

gedaiu commented Mar 9, 2016

uf... I did not saw that... thanks!

@gedaiu gedaiu closed this as completed Mar 9, 2016
@webron
Copy link
Member

webron commented Mar 9, 2016

@gedaiu no problem.

@DavidBiesack - if you feel something isn't covered, can you please elaborate?

@whitlockjc
Copy link
Member

Maybe we could have some examples/recipes/... showcasing how someone might do things like this? I can think of other "oh, I didn't know you could do that" scenarios as well.

@webron
Copy link
Member

webron commented Mar 9, 2016

Sure. Parent: #589

@whitlockjc
Copy link
Member

Thanks Ron. You're a gentleman and a scholar.

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

5 participants