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

What is the expected behavior of default in the Swagger specification? #1607

Closed
matthchr opened this issue Nov 14, 2016 · 4 comments
Closed

Comments

@matthchr
Copy link
Member

matthchr commented Nov 14, 2016

When I read default in the Swagger spec, what I see is "optional, and if omitted the server will use the following value."

It seems like what actually happens at least in some languages is that AutoRest uses the default in the signature (for languages which support that such as Python and C#) and we end up with a signature which looks like this:
DoFoo(string required, string optional = null, string default = "Test")

This actually ends up always serializing the string "Test" to the server. Which means as far as the server is concerned, this value is now never omitted.

So I have a few questions about the expected behavior of default in the clients:

  1. Are we consistently treating default the same across default in operations and default in the body? I know that the body supports default but I can't seem to find any tests for it except Complex-Model which only seems to be generated for Node.JS -- although from some investigation into the Python generator by @annatisch on my team it seems at least python treats the two consistently.
  2. Is it desirable to actually serialize the default value across the wire? Taking this to it's extreme (which my service probably does...) if we have an object with 2 required properties and 15 optional properties. The defaults of these optional properties may be documentable in the Swagger specification, and if they were documented we would serialize 17 values instead of 2.
  3. What happens if I have a property which is both required and default -- and is the behavior the same in the body and the operation parameters?

Overall I think the win of including default probably outweighs the awkwardness of always serializing that value to the server (better method signatures, etc), but curious what others think or if anybody has an alternative option that is the best of both worlds.

@matthchr
Copy link
Member Author

Note that this is in some way philosophically related to my other question: #1583

@matthchr matthchr added the design-discussion An area of design currently under discussion and open to team and community feedback. label Nov 14, 2016
@brjohnstmsft
Copy link
Member

My take on default is similar to my take on client-side validation of Swagger constraints like minimum, maximum, etc.: The client should not be "smart". Assume the service knows what it's doing, and avoid the extra coupling and wasted bandwidth of redundant default values being sent over the wire.

@fearthecowboy fearthecowboy added AutoRest-2.0-Ideas and removed design-discussion An area of design currently under discussion and open to team and community feedback. labels Jan 31, 2017
@fearthecowboy
Copy link
Member

It's ok for the client to be smart, just not "smart" :D

IMHO, default values should not be sent across the wire.

I don't particularly like the current assumption/behavior, but we can't change that right now.

AutoRest 1.0 has a number of implicit, not-well-documented assumptions that are not overridable; this will change drastically in AutoRest 2.0, where we will document every single assumption and provide the ability to change the assumption via configuration.

@olydis
Copy link
Contributor

olydis commented Sep 27, 2017

added to #2448

@olydis olydis closed this as completed Sep 27, 2017
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

4 participants