Mapping status codes to return values
Almost all the time, REST APIs carry all significant information back to the client in either the entity headers, or in the payload of the response. Rarely is the status code the most significant piece of information.
The exception to this rule is HEAD requests, which are (by definition) like GET requests, except they don’t return the resource payload even when successful. This may be used to test a service for the existence of a resource, or whether a client has the authority to access it.
Swagger does not allow developers to provide any metadata about the intent of how such return codes should be interpreted by the client. Autorest relies on convention by interpreting a 2xx reply to a HEAD request as ‘true’ and 4xx responses as ‘false’. This convention goes a long way, but it does not allow a client to separate the meaning of status codes from each other, such as 404 (Not Found) from 401 (Unauthorized).
A generalization of the Autorest convention would allow the intent to be explicitly defined in the Swagger specification, and then taken advantage of in generated client code.
The current convention would look something like:
"responses": {
"200": {
"description": "The container exists.",
"x-ms-response-value": { "type": "boolean", "value": true }
},
"404": {
"description": "The container does not exist",
"x-ms-response-value": { "type": "boolean", "value": false }
}
}
or, more generally:
"responses": {
"200": {
"description": "The container exists.",
"x-ms-response-value": { "type": "string", "value": "found" }
},
"401": {
"description": "The container is not accessible",
"x-ms-response-value": { "type": "string", "value": "inaccessible" }
},
"404": {
"description": "The container does not exist",
"x-ms-response-value": { "type": "string", "value": "notfound"}
}
}
I can see the value in defining these response values, and it seems like this would simplify code that teams would have to write by hand for their SDKs. However, since this deals with the shape of the client (like you mention, this isn't part of Swagger), and we're starting to get a large number of custom extensions, we've started talking about the idea of alternate methods of including this metadata. I've marked this as "design" so that we can discuss the strategy for this with the larger team.
Howdy!
In our planning for driving towards a stable '1.0' release, I'm marking this issue as 'deferred' :zzz: and we're going to review it during the post-1.0 planning cycle.
It's not to say that we're not going to work on it, or that this isn't not important, but at the moment, we're picking and choosing the stuff we must do before 1.0. :horse_racing: :horse_racing: :horse_racing:
We'll make sure we pick this back up at that point. :tada: