This relates to the Swagger 1.2 update at strongloop/loopback-component-explorer#14.
Swagger allows the display of model schemas inside the route definition, both as the return type:

And as a parameter type:

This requires that route definitions are able to mark their returns and accepts values as the model itself. Most built-in methods defined in dao.js (https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/dao.js#L1219) simply specify 'array' or 'object' as their return type, making it impossible to know the specifics of what they are returning.
I propose three new extensions to the accepts and returns syntax:
- The addition of
'this' as a type definition (subclass object). In loopback-explorer, this would be interpreted as equal to the parent model.
- Simple array syntax:
{type: '[this]'}, {type: '[string]'}, etc., instead of the more verbose swagger-compliant {type: 'array', items: {type: 'string'}}. We should support both syntaxes in case of constraints on types, e.g. {type: 'array', items: {type: 'number', min: 0, max: 10}}.
- Anonymous model definition. Sometimes methods don't return a model, but rather selected fields from a model, aggregations, or metadata. Rather than simply define
'object' or 'array' as the return type, it would be great to be able to define the return schema inline. Since constraints don't make sense on return properties, in my opinion it is not necessary to support the more verbose {type: ...} syntax. For example:
returns: {arg: 'data', root: true, type: 'object' /* or array */, schema: {
field1: 'number',
field2: 'string',
field3: '[number]',
field4: '[this]'
}},
This relates to the Swagger 1.2 update at strongloop/loopback-component-explorer#14.
Swagger allows the display of model schemas inside the route definition, both as the return type:
And as a parameter type:
This requires that route definitions are able to mark their
returnsandacceptsvalues as the model itself. Most built-in methods defined indao.js(https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/dao.js#L1219) simply specify'array'or'object'as their return type, making it impossible to know the specifics of what they are returning.I propose three new extensions to the
acceptsandreturnssyntax:'this'as a type definition (subclass object). Inloopback-explorer, this would be interpreted as equal to the parent model.{type: '[this]'},{type: '[string]'}, etc., instead of the more verbose swagger-compliant{type: 'array', items: {type: 'string'}}. We should support both syntaxes in case of constraints on types, e.g.{type: 'array', items: {type: 'number', min: 0, max: 10}}.'object'or'array'as the return type, it would be great to be able to define the return schema inline. Since constraints don't make sense on return properties, in my opinion it is not necessary to support the more verbose{type: ...}syntax. For example: