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

Serialization of nested structures in parameters (query, path, headers, cookies) #2594

Closed
bali182 opened this issue May 29, 2021 · 1 comment

Comments

@bali182
Copy link

bali182 commented May 29, 2021

I've posted this on SO, but asking here to as probably more people see it with relevant exeperience.

In the OpenAPI docs about parameter serialization there's a short section about how to serialize query, path, header and cookie parameters with different styles. The schema of these parameters are described as OpenAPI flavoured json schema, which allows infinite nesting of objects and arrays. I haven't found any mention about how to deal with these in the docs:

https://swagger.io/docs/specification/serialization/

Let's assume the JSON schema provided for any of the parameters is like this:

{
  "type": "object",
  "properties": {
    "foo": {
      "type": "object",
      "properties": {
        "bar": "string"
      }
    }
  }
}

Meaning it allows structures in JSON such as:

{
  "foo": {
    "bar": "hello"
  }
}

Or similar concept with arrays that are nested:

{
  "type": "array",
  "items": {
    "type": "array",
    "items": {
      "type": "string"
    }
  }
}

Which allows structures like this (at least in JSON):

[["a"], ["b"]]

My question:

  1. Is this allowed for path, query, etc parameters according to OpenAPI spec?
  2. In case it is, are there any docs on how to serialize these in the different styles the spec allows?
  3. In case it is not, is this mentioned anywhere in official docs?

I'm asking this because I'm working on tooling that needs to be compatible with the OpenAPI spec, and I'd like to know what can I expect here as parameter formats. I'm fully aware that having giant nested objects and trying to serialize them in a url is not the smartest idea. However I'm interested in what the OpenAPI spec allows.

@bali182
Copy link
Author

bali182 commented Jun 8, 2021

Closing this as I got an answer on SO. To summarize:

  • Arrays - 1 level and primitive children allowed, otherwise undefined behaviour, eg.: ["A", false, 12].
  • Objects - 1 level and primitive children allowed, otherwise undefined behaviour, eg.: { foo: "A", bar: false, num: 12 }

https://stackoverflow.com/questions/67745944/openapi-path-query-parameters-nested-structure-serialization

@bali182 bali182 closed this as completed Jun 8, 2021
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

1 participant