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

Add support for JSON objects as query parameters #785

Open
gorbster opened this issue Feb 15, 2024 · 2 comments
Open

Add support for JSON objects as query parameters #785

gorbster opened this issue Feb 15, 2024 · 2 comments
Labels
parameter-object schema-object Concerning schema object of OpenAPI spec.

Comments

@gorbster
Copy link

The OpenAPI 3 spec allows for query parameters that are of type object. However when this is converted to a Postman collection, the parameters are converted to key / value string pairs. The below example is from an OpenAPI spec that defines a request with a GET query param of type object (location) that must include oneOf the listed properties (zip or address). When converted to a Postman collection, zip is created as a top-level parameter instead of a nested parameter within the location object.

{
     "schema":
     {
         "type": "object",
         "properties":
         {
             "zip":
             {
                 "type": "string",
                 "description": "Your zip code",
                 "maxLength": 5,
                 "minLength": 5
             },
             "address":
             {
                 "type": "string",
                 "description": "Your address"
             }
         },
         "oneOf":
         [
             {
                 "required":
                 [
                     "zip"
                 ]
             },
             {
                 "required":
                 [
                     "address"
                 ]
             }
         ],
         "maxProperties": 1,
         "minProperties": 1
     },
     "in": "query",
     "name": "location",
     "required": true
 }
@gorbster
Copy link
Author

This was originally raised in the Postman community forum here.

@VShingala
Copy link
Member

VShingala commented Apr 4, 2024

Hey @gorbster, OpenAPI specification suggests that when the object is used for query parameters, by default the value of it's properties should be at top level.

Ref: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#style-examples

For detailed explanation, for query, parameters called style and explode which determines how value of query will be handled are defaulted to form and true. And for these values, you can see from table that top level param name is not maintained and individual params will be formed for each key value pairs.

To keep top level param intact, you can mention explode as false in you definition. i.e. below will provide you result with location intact.

{
     "schema":
     {
         "type": "object",
         "properties":
         {
             "zip":
             {
                 "type": "string",
                 "description": "Your zip code",
                 "maxLength": 5,
                 "minLength": 5
             },
             "address":
             {
                 "type": "string",
                 "description": "Your address"
             }
         }
     },
     "in": "query",
     "name": "location",
     "required": true,
     "explode": false
 }

@VShingala VShingala added parameter-object schema-object Concerning schema object of OpenAPI spec. labels Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parameter-object schema-object Concerning schema object of OpenAPI spec.
Projects
None yet
Development

No branches or pull requests

2 participants