-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
Add a default "success" response message, the status code is 200 or 204 depending on whether the method returns any data. Append any error messages as specified in the `errors` property of method's remoting metadata. Move the description of operation's return type to the "success" response message. Include error message models in the API models.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,21 +123,40 @@ var routeHelper = module.exports = { | |
|
||
debug('route %j', route); | ||
|
||
var responseDoc = modelHelper.LDLPropToSwaggerDataType(returns); | ||
|
||
// Note: Swagger Spec does not provide a way how to specify | ||
// that the responseModel is "array of X". However, | ||
// Swagger UI converts Arrays to the item types anyways, | ||
// therefore it should be ok to do the same here. | ||
var responseModel = responseDoc.type === 'array' ? | ||
responseDoc.items.type : responseDoc.type; | ||
|
||
var responseMessages = [{ | ||
code: route.returns && route.returns.length ? 200 : 204, | ||
message: 'Request was successful', | ||
responseModel: responseModel | ||
}]; | ||
|
||
if (route.errors) { | ||
responseMessages.push.apply(responseMessages, route.errors); | ||
} | ||
|
||
var apiDoc = { | ||
path: routeHelper.convertPathFragments(route.path), | ||
// Create the operation doc. Use `extendWithType` to add the necessary | ||
// `items` and `format` fields. | ||
operations: [routeHelper.extendWithType({ | ||
// Create the operation doc. | ||
// Note that we are not calling `extendWithType`, as the response type | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
STRML
Member
|
||
// is specified in the first response message. | ||
operations: [{ | ||
method: routeHelper.convertVerb(route.verb), | ||
// [rfeng] Swagger UI doesn't escape '.' for jQuery selector | ||
nickname: route.method.replace(/\./g, '_'), | ||
nickname: route.method.replace(/\./g, '_'), | ||
parameters: accepts, | ||
// TODO(schoon) - We don't have descriptions for this yet. | ||
responseMessages: [], | ||
responseMessages: responseMessages, | ||
summary: typeConverter.convertText(route.description), | ||
notes: typeConverter.convertText(route.notes), | ||
deprecated: route.deprecated | ||
}, returns)] | ||
}] | ||
}; | ||
|
||
return apiDoc; | ||
|
It appears that this is a spec violation.
From the 1.2 spec:
When integrating with other tools (in this case, Restunited), I've seen breakage due to the missing
type
parameter.It seems strange to use responseMessages for 200s. Isn't it just meant for errors?