Default value used in swagger query parameters

1,658 views
Skip to first unread message

hasa

unread,
Dec 5, 2017, 9:28:15 PM12/5/17
to Swagger
Given that we tend to generate clients from Swagger, we've been looking to have a default value used for these scenarios. For example, we support many api versions, but we want to embed in the swagger which version the clients should be sending to the server. We never want the server to have a default value.
More like a default value that the client should assume if the user doesn't input anything.

In swagger 2.0, the language around this was very clear:

If in is any value other than "body":

default*Declares the value of the parameter that the server will use if none is provided, for example a "count" to control the number of results per page might default to 100 if not supplied by the client in the request. (Note: "default" has no meaning for required parameters.) See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.2. Unlike JSON Schema this value MUST conform to the defined typefor this parameter.

 In swagger v3, it's a bit less clear.:
From the following doc (under Fixed Fields): https://swagger.io/specification/#schemaObject
  • default - The default value represents what would be assumed by the consumer of the input as the value of the schema if one is not provided. Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level. For example, if type is string, then default can be "foo" but cannot be 1.
In this case, who is the consumer of the input? Could it be the client that is generated from the swagger?

Thanks in advance.

Ron Ratovsky

unread,
Dec 5, 2017, 11:03:39 PM12/5/17
to swagger-sw...@googlegroups.com

It could be, but it depends on the scenario.

 

The producer/consumer isn’t necessarily the server/client.

When an API call is executed by the client to the server – the server is the consumer of the request. When the server returns a response, the client is the consumer of the response.

Basically, what it means, is that it’s up to the side that receives the data to assume a default value if one is not being sent in the data.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
swagger-swaggers...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages